CSES - COCI 2006/2007 #4 - Results
Submission details
Task:Ispiti
Sender:henrikaalto
Submission time:2019-07-25 15:20:57 +0300
Language:C++ (C++17)
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#10.01 sdetails
#20.01 sdetails
#30.04 sdetails
#4ACCEPTED0.05 sdetails
#50.07 sdetails
#60.08 sdetails
#70.11 sdetails
#80.14 sdetails
#90.23 sdetails
#100.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));
    }

    // l, r = target
    // ll, rr = current

    void muuta(int l, int r, int ll, int rr, int s, pi x)
    {
        if (rr < l || r < ll) return;
        //cout << "muuta: " << l << ", " << r << ", " << ll << ", " << rr << ", " << s << ", " << x.F << ", " << x.S << "\n";
        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;
        // //cout<<"hae "<<l<<" " << ll<< " "<<rr<< " " <<x <<"\n";
        if (puu[s].F < x) return inf;
        if (s >= N) {
            //cout<<"löytyi: kohta: " << ll << " x: " << x << " index: " << puu[s].S << " arvo: " << puu[s].F << " itse: " << itse << "\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)
    {
        //cout << "MUUTA("<<l<<","<<"{"<<x.F<<","<<x.S<<"});\n";
        muuta(l, l, 0, N - 1, 1, x);
    }

    int hae(int l, int x, int itse)
    {
        //cout<<"HAE("<<l<<","<<x<<");\n";
        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];
            // //cout << z.F << " " << z.S << "\n";
            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 << "NA\n";
            else cout << y << "\n";
        }
    }
}
/*
               find first point where A >= A_i
         (B_i) |----------------------
--------------------------------------> B
*/

Test details

Test 1

Verdict:

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

correct output
3
NE
4
5

user output
3
NA
5
5

Test 2

Verdict:

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

correct output
NE
NE
3
3
6
...

user output
NA
NA
3
3
6
...

Test 3

Verdict:

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

correct output
NE
2
NE
NE
4
...

user output
NA
2
NA
NA
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:

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:

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:

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:

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:

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:

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