Task: | Maximums |
Sender: | Pohjantahti |
Submission time: | 2018-10-20 14:26:19 +0300 |
Language: | C++ |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.02 s | details |
#2 | ACCEPTED | 0.06 s | details |
#3 | ACCEPTED | 0.07 s | details |
#4 | ACCEPTED | 0.06 s | details |
#5 | ACCEPTED | 0.05 s | details |
#6 | ACCEPTED | 0.05 s | details |
#7 | ACCEPTED | 0.06 s | details |
#8 | ACCEPTED | 0.04 s | details |
#9 | ACCEPTED | 0.05 s | details |
#10 | ACCEPTED | 0.05 s | details |
#11 | ACCEPTED | 0.06 s | details |
#12 | ACCEPTED | 0.05 s | details |
#13 | ACCEPTED | 0.05 s | details |
#14 | ACCEPTED | 0.05 s | details |
#15 | ACCEPTED | 0.04 s | details |
#16 | ACCEPTED | 0.02 s | details |
Code
#include <iostream> using namespace std; typedef long long ll; const ll INF = 1000000000000000005; const ll N = 1LL<<60; // max element index struct node { ll s; node *l, *r; node (ll cs) : s(cs) { l = nullptr; r = nullptr; } }; node *st = new node(0LL); // segtree root node void update(ll k, ll val, ll x, ll y, node *nd = st) { if (x == y) { nd->s = val; } else { ll mid = (x+y)/2; if (x <= k && k <= mid) { if (nd->l == nullptr) nd->l = new node(0LL); update(k, val, x, mid, nd->l); } else if (mid < k && k <= y) { if (nd->r == nullptr) nd->r = new node(0LL); update(k, val, mid+1, y, nd->r); } ll ns = -INF; if (nd->l != nullptr) ns = max(ns, (nd->l)->s); if (nd->r != nullptr) ns = max(ns, (nd->r)->s); nd->s = ns; } } ll query(ll ql, ll qr, ll x, ll y, node *nd = st) { if (ql <= x && y <= qr) return nd->s; if (y < ql || x > qr) return -INF; ll mid = (x+y)/2; ll res = -INF; if (nd->l != nullptr) res = max(res, query(ql, qr, x, mid, nd->l)); if (nd->r != nullptr) res = max(res, query(ql, qr, mid+1, y, nd->r)); return res; } int qcnt; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> qcnt; for (int cq = 0; cq < qcnt; ++cq) { int tp; cin >> tp; if (tp == 0) { ll k, x; cin >> k >> x; update(k, x, 0, N-1, st); } else { ll a, b; cin >> a >> b; if (a > b) swap(a, b); ll cres = query(a, b, 0, N-1, st); cres = max(0LL, cres); cout << cres << "\n"; } } return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
14 0 1 10 0 2 20 0 3 10 0 5 30 ... |
correct output |
---|
30 900 10 10 30 ... |
user output |
---|
30 900 10 10 30 ... |
Test 2
Verdict: ACCEPTED
input |
---|
10000 1 32165844002674501 9935522969... |
correct output |
---|
0 0 0 0 11234759 ... |
user output |
---|
0 0 0 0 11234759 ... |
Test 3
Verdict: ACCEPTED
input |
---|
10000 0 506000858779722442 955856127 0 365677212339294554 191262305 0 80298683202610332 731026780 1 251018061710642286 402321118... |
correct output |
---|
191262305 955856127 0 0 974767945 ... |
user output |
---|
191262305 955856127 0 0 974767945 ... |
Test 4
Verdict: ACCEPTED
input |
---|
10000 1 638126273190686812 950389431... |
correct output |
---|
0 0 0 0 282004160 ... |
user output |
---|
0 0 0 0 282004160 ... |
Test 5
Verdict: ACCEPTED
input |
---|
10000 1 111025053997747742 442310357... |
correct output |
---|
0 0 0 0 904661686 ... |
user output |
---|
0 0 0 0 904661686 ... |
Test 6
Verdict: ACCEPTED
input |
---|
10000 1 496705609862664992 581730224... |
correct output |
---|
0 0 0 0 405817260 ... |
user output |
---|
0 0 0 0 405817260 ... |
Test 7
Verdict: ACCEPTED
input |
---|
10000 0 72593517785362728 681384442 0 362460280234102656 165260530 1 151141022927318138 187584320... |
correct output |
---|
0 111311568 685553350 681384442 956755171 ... |
user output |
---|
0 111311568 685553350 681384442 956755171 ... |
Test 8
Verdict: ACCEPTED
input |
---|
10000 1 622606698099284018 987544827... |
correct output |
---|
0 0 807751104 849715958 0 ... |
user output |
---|
0 0 807751104 849715958 0 ... |
Test 9
Verdict: ACCEPTED
input |
---|
10000 1 69238043798947793 4706690300... |
correct output |
---|
0 0 795546841 0 795546841 ... |
user output |
---|
0 0 795546841 0 795546841 ... |
Test 10
Verdict: ACCEPTED
input |
---|
10000 1 119685018556413794 615398329... |
correct output |
---|
0 0 0 870853046 0 ... |
user output |
---|
0 0 0 870853046 0 ... |
Test 11
Verdict: ACCEPTED
input |
---|
10000 1 348122926527894017 731130196... |
correct output |
---|
0 0 0 0 0 ... |
user output |
---|
0 0 0 0 0 ... |
Test 12
Verdict: ACCEPTED
input |
---|
10000 1 355395486708916153 967691841... |
correct output |
---|
0 0 0 0 680197744307649083 ... |
user output |
---|
0 0 0 0 680197744307649083 ... |
Test 13
Verdict: ACCEPTED
input |
---|
10000 1 55431229101938445 9696845731... |
correct output |
---|
0 0 971464128922141096 233235584702314016 971464128922141096 ... |
user output |
---|
0 0 971464128922141096 233235584702314016 971464128922141096 ... |
Test 14
Verdict: ACCEPTED
input |
---|
10000 0 207801709118991370 174237375... |
correct output |
---|
0 689368052041962301 174237375167386391 630879973186342989 0 ... |
user output |
---|
0 689368052041962301 174237375167386391 630879973186342989 0 ... |
Test 15
Verdict: ACCEPTED
input |
---|
10000 1 281035836234805473 310949475... |
correct output |
---|
0 0 539398684288713903 0 539398684288713903 ... |
user output |
---|
0 0 539398684288713903 0 539398684288713903 ... |
Test 16
Verdict: ACCEPTED
input |
---|
10 0 100 1000 0 200 1001 1 100 200 1 101 199 ... |
correct output |
---|
1001 0 200 250 200 |
user output |
---|
1001 0 200 250 200 |