CSES - COCI 2006/2007 #4 - Results
Submission details
Task:Ispiti
Sender:henrikaalto
Submission time:2019-07-25 15:23:31 +0300
Language:C++ (C++17)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.01 sdetails
#2ACCEPTED0.01 sdetails
#3ACCEPTED0.04 sdetails
#4ACCEPTED0.05 sdetails
#5ACCEPTED0.07 sdetails
#6ACCEPTED0.08 sdetails
#7ACCEPTED0.11 sdetails
#8ACCEPTED0.15 sdetails
#9ACCEPTED0.23 sdetails
#10ACCEPTED0.26 sdetails

Code

#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define F first
#define S second
using pi=pair<int,int>;
const int inf = 1e9;
struct segtree {
    vector<pi> puu;
    int N;
    segtree()
    {
        N = 1 << 19;
        puu.resize(N * 2, make_pair(0, 0));
    }

    void muuta(int l, int r, int ll, int rr, int s, pi x)
    {
        if (rr < l || r < ll) return;
        if (l <= ll && rr <= r) {
            puu[s] = x;
            return;
        }
        int w = (rr - ll) / 2;
        muuta(l, r, ll, ll + w, s * 2, x);
        muuta(l, r, ll + w + 1, rr, s * 2 + 1, x);
        puu[s] = max(puu[s*2],puu[s*2+1]);
    }

    int hae(int l, int ll ,int rr, int s, int x, int itse)
    {
        if (rr < l) return inf;
        if (puu[s].F < x) return inf;
        if (s >= N) {
            if (puu[s].S == itse) return inf;
            return puu[s].S;
        }
        int w = (rr - ll) / 2;
        int r = hae(l, ll, ll + w, s * 2, x, itse);
        if (r == inf) return hae(l, ll + w + 1, rr, s * 2 + 1, x, itse);
        return r;
    }

    void muuta(int l, pi x)
    {
        muuta(l, l, 0, N - 1, 1, x);
    }

    int hae(int l, int x, int itse)
    {
        return hae(l, 0, N - 1, 1, x, itse);
    }
};

int main()
{
    int n;
    cin >> n;
    vector<pi> o;
    vector<pair<int, pi>>q;
    vector<pi> orig(n * 2);
    int idx = 1;
    for (int i = 0; i < n; ++i) {
        char c;
        cin >> c;
        int a, b;
        if (c == 'D') {
            cin >> a >> b;
            q.emplace_back(0, make_pair(a, b));
            o.emplace_back(b, a);
        }
        else {
            cin >> a;
            q.emplace_back(1, make_pair(a, a));
        }
    }
    sort(all(o));
    vector<int> start(o.size());
    segtree lol;
    for (int i = 0; i < n; ++i) {
        if (q[i].F == 0) {
            int it = lower_bound(all(o), make_pair(q[i].S.S, q[i].S.F)) - o.begin();
            lol.muuta(it + 1, make_pair(q[i].S.F, idx));
            orig[idx++] = q[i].S;
        }
        else {
            auto z = orig[q[i].S.F];
            int it = lower_bound(all(o), make_pair(z.S, -inf)) - o.begin();
            int y = lol.hae(it + 1, z.F, q[i].S.F);
            if (y == inf) cout << "NE\n";
            else cout << y << "\n";
        }
    }
}

Test details

Test 1

Verdict: ACCEPTED

input
9
D 2 1000000000
D 5 1000000000
D 9 1000000000
P 2
...

correct output
3
NE
4
5

user output
3
NE
4
5

Test 2

Verdict: ACCEPTED

input
16
D 4 10
D 3 50
P 1
P 2
...

correct output
NE
NE
3
3
6
...

user output
NE
NE
3
3
6
...

Test 3

Verdict: ACCEPTED

input
30000
D 15194 31331
D 1646 19709
P 1
D 646 12738
...

correct output
NE
2
NE
NE
4
...

user output
NE
2
NE
NE
4
...
Truncated

Test 4

Verdict: ACCEPTED

input
39999
D 1999999999 1999999999
D 1999999999 1000000001
D 1999999998 1000000002
D 1999999997 1000000003
...

correct output
1
1
1
1
1
...

user output
1
1
1
1
1
...
Truncated

Test 5

Verdict: ACCEPTED

input
60000
D 1999999999 1999999999
D 1999999999 1000000001
D 1999999998 1000000002
D 1999999997 1000000003
...

correct output
1
1
1
1
1
...

user output
1
1
1
1
1
...
Truncated

Test 6

Verdict: ACCEPTED

input
70000
D 1999999999 1999999999
D 1999999999 1000000001
D 1999999998 1000000002
D 1999999997 1000000003
...

correct output
1
1
1
1
1
...

user output
1
1
1
1
1
...
Truncated

Test 7

Verdict: ACCEPTED

input
90000
D 1999999999 1999999999
D 1999999999 1000000001
D 1999999998 1000000002
D 1999999997 1000000003
...

correct output
1
1
1
1
1
...

user output
1
1
1
1
1
...
Truncated

Test 8

Verdict: ACCEPTED

input
120000
D 1999999999 1999999999
D 1999999999 1000000001
D 1999999998 1000000002
D 1999999997 1000000003
...

correct output
1
1
1
1
1
...

user output
1
1
1
1
1
...
Truncated

Test 9

Verdict: ACCEPTED

input
180000
D 1999999999 1999999999
D 1999999999 1000000001
D 1999999998 1000000002
D 1999999997 1000000003
...

correct output
1
1
1
1
1
...

user output
1
1
1
1
1
...
Truncated

Test 10

Verdict: ACCEPTED

input
200000
D 1999999999 1999999999
D 1999999999 1000000001
D 1999999998 1000000002
D 1999999997 1000000003
...

correct output
1
1
1
1
1
...

user output
1
1
1
1
1
...
Truncated