Task: | Ispiti |
Sender: | henrikaalto |
Submission time: | 2019-07-25 15:23:31 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 100 |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.01 s | details |
#2 | ACCEPTED | 0.01 s | details |
#3 | ACCEPTED | 0.04 s | details |
#4 | ACCEPTED | 0.05 s | details |
#5 | ACCEPTED | 0.07 s | details |
#6 | ACCEPTED | 0.08 s | details |
#7 | ACCEPTED | 0.11 s | details |
#8 | ACCEPTED | 0.15 s | details |
#9 | ACCEPTED | 0.23 s | details |
#10 | ACCEPTED | 0.26 s | details |
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 |