CSES - E4590 2018 6 - Results
Submission details
Task:Maximums
Sender:Pohjantahti
Submission time:2018-10-20 14:26:19 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.02 sdetails
#2ACCEPTED0.06 sdetails
#3ACCEPTED0.07 sdetails
#4ACCEPTED0.06 sdetails
#5ACCEPTED0.05 sdetails
#6ACCEPTED0.05 sdetails
#7ACCEPTED0.06 sdetails
#8ACCEPTED0.04 sdetails
#9ACCEPTED0.05 sdetails
#10ACCEPTED0.05 sdetails
#11ACCEPTED0.06 sdetails
#12ACCEPTED0.05 sdetails
#13ACCEPTED0.05 sdetails
#14ACCEPTED0.05 sdetails
#15ACCEPTED0.04 sdetails
#16ACCEPTED0.02 sdetails

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