#pragma GCC optimize("O2")
#include <bits/stdc++.h>
#ifdef DEBUG
#include "debug.hpp"
#endif
using namespace std;
#define all(c) (c).begin(), (c).end()
#define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); it++)
#define rep(i, N) for(int i = 0; i < (N); i++)
#define rep1(i, N) for(int i = 1; i <= (N); i++)
#define rep2(i, s, e) for(int i = (s); i <= (e); i++)
#define rep3(i, s, e, d) for(int i = (s); (d) >= 0 ? i <= (e) : i >= (e); i += (d))
#define pb push_back
#ifdef DEBUG
#define debug(x...) {dbg::depth++; string dbg_vals = dbg::to_string(x); dbg::depth--; dbg::fprint(__func__, __LINE__, #x, dbg_vals);}
#define light_debug(x) {dbg::light = 1; dbg::dout << __func__ << ":" << __LINE__ << " " << #x << " = " << x << endl; dbg::light = 0;}
#else
#define debug(x...)
#define light_debug(x)
#endif
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<int> uid(0, 1 << 30);
class Treap{
private:
struct node{
int v, i, prior, size, diff, dp;
node* l; node* r;
node(int _v, int _i){
prior = uid(rng);
v = _v;
i = _i;
dp = i;
l = r = 0;
size = 1;
}
};
using pnode = node*;
pnode root = 0;
inline int size(pnode t){
return t ? t->size : 0;
}
inline int dp(pnode t){
return t ? t->dp : 0;
}
inline void pull(pnode t){
if(t) {
t->size = size(t->l) + 1 + size(t->r);
t->dp = max(max(dp(t->l), dp(t->r) - size(t->l) - 1), t->i - size(t->l));
}
}
void split(pnode t, pnode& l, pnode& r, int v, int i){
if(!t)
l = r = 0;
else if(make_pair(t->v, t->i) <= make_pair(v, i))
split(t->r, t->r, r, v, i), l = t;
else
split(t->l, l, t->l, v, i), r = t;
pull(t);
}
void merge(pnode& t, pnode l, pnode r){
if(!l || !r)
t = l ? l : r;
else if(l->prior >= r->prior)
merge(l->r, l->r, r), t = l;
else
merge(r->l, l, r->l), t = r;
pull(t);
}
public:
void insert(int i, int v){
pnode l, m, r;
split(root, m, r, v, i);
split(m, l, m, v, i - 1);
m = new node(v, i);
merge(root, l, m);
merge(root, root, r);
}
void erase(int i, int v){
pnode l, m, r;
split(root, m, r, v, i);
split(m, l, m, v, i - 1);
m = 0;
merge(root, l, m);
merge(root, root, r);
}
int query(){
return root->dp;
}
};
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
int N = A.size(), Q = X.size();
Treap trp;
vector<int> answer(Q);
rep(i, N)
trp.insert(i, A[i]);
rep(i, Q){
int x = X[i], v = V[i];
trp.erase(x, A[x]);
trp.insert(x, v);
A[x] = v;
answer[i] = trp.query();
}
return answer;
}
signed main1(){
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
#ifdef DEBUG
freopen("debug", "w", stderr);
#endif
int N, Q;
Treap trp;
vi A;
cin >> N >> Q;
A.resize(N);
rep(i, N) {
cin >> A[i];
trp.insert(i, A[i]);
}
debug(trp.query());
while(Q--){
int x, v;
cin >> x >> v;
trp.erase(x, A[x]);
trp.insert(x, v);
A[x] = v;
cout << trp.query() << '\n';
}
#ifdef DEBUG
dbg::dout << "\nExecution time: " << clock() << "ms\n";
#endif
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
640 KB |
Output is correct |
5 |
Correct |
5 ms |
640 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
5 ms |
640 KB |
Output is correct |
11 |
Correct |
5 ms |
640 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
5 ms |
640 KB |
Output is correct |
14 |
Correct |
5 ms |
640 KB |
Output is correct |
15 |
Correct |
5 ms |
640 KB |
Output is correct |
16 |
Correct |
5 ms |
596 KB |
Output is correct |
17 |
Correct |
5 ms |
640 KB |
Output is correct |
18 |
Correct |
5 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
640 KB |
Output is correct |
5 |
Correct |
5 ms |
640 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
5 ms |
640 KB |
Output is correct |
11 |
Correct |
5 ms |
640 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
5 ms |
640 KB |
Output is correct |
14 |
Correct |
5 ms |
640 KB |
Output is correct |
15 |
Correct |
5 ms |
640 KB |
Output is correct |
16 |
Correct |
5 ms |
596 KB |
Output is correct |
17 |
Correct |
5 ms |
640 KB |
Output is correct |
18 |
Correct |
5 ms |
640 KB |
Output is correct |
19 |
Correct |
19 ms |
1408 KB |
Output is correct |
20 |
Correct |
21 ms |
1536 KB |
Output is correct |
21 |
Correct |
20 ms |
1536 KB |
Output is correct |
22 |
Correct |
20 ms |
1536 KB |
Output is correct |
23 |
Correct |
19 ms |
1536 KB |
Output is correct |
24 |
Correct |
19 ms |
1536 KB |
Output is correct |
25 |
Correct |
19 ms |
1536 KB |
Output is correct |
26 |
Correct |
19 ms |
1536 KB |
Output is correct |
27 |
Correct |
19 ms |
1516 KB |
Output is correct |
28 |
Correct |
18 ms |
1528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
1920 KB |
Output is correct |
2 |
Correct |
86 ms |
4472 KB |
Output is correct |
3 |
Correct |
162 ms |
6904 KB |
Output is correct |
4 |
Correct |
166 ms |
6904 KB |
Output is correct |
5 |
Correct |
159 ms |
6904 KB |
Output is correct |
6 |
Correct |
155 ms |
7036 KB |
Output is correct |
7 |
Correct |
146 ms |
6904 KB |
Output is correct |
8 |
Correct |
143 ms |
6904 KB |
Output is correct |
9 |
Correct |
146 ms |
6996 KB |
Output is correct |
10 |
Correct |
100 ms |
7032 KB |
Output is correct |
11 |
Correct |
104 ms |
7032 KB |
Output is correct |
12 |
Correct |
103 ms |
7032 KB |
Output is correct |
13 |
Correct |
95 ms |
7032 KB |
Output is correct |
14 |
Correct |
97 ms |
7032 KB |
Output is correct |
15 |
Correct |
116 ms |
7160 KB |
Output is correct |
16 |
Correct |
85 ms |
7000 KB |
Output is correct |
17 |
Correct |
86 ms |
6992 KB |
Output is correct |
18 |
Correct |
86 ms |
7032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
640 KB |
Output is correct |
5 |
Correct |
5 ms |
640 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
5 ms |
640 KB |
Output is correct |
11 |
Correct |
5 ms |
640 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
5 ms |
640 KB |
Output is correct |
14 |
Correct |
5 ms |
640 KB |
Output is correct |
15 |
Correct |
5 ms |
640 KB |
Output is correct |
16 |
Correct |
5 ms |
596 KB |
Output is correct |
17 |
Correct |
5 ms |
640 KB |
Output is correct |
18 |
Correct |
5 ms |
640 KB |
Output is correct |
19 |
Correct |
19 ms |
1408 KB |
Output is correct |
20 |
Correct |
21 ms |
1536 KB |
Output is correct |
21 |
Correct |
20 ms |
1536 KB |
Output is correct |
22 |
Correct |
20 ms |
1536 KB |
Output is correct |
23 |
Correct |
19 ms |
1536 KB |
Output is correct |
24 |
Correct |
19 ms |
1536 KB |
Output is correct |
25 |
Correct |
19 ms |
1536 KB |
Output is correct |
26 |
Correct |
19 ms |
1536 KB |
Output is correct |
27 |
Correct |
19 ms |
1516 KB |
Output is correct |
28 |
Correct |
18 ms |
1528 KB |
Output is correct |
29 |
Correct |
26 ms |
1920 KB |
Output is correct |
30 |
Correct |
86 ms |
4472 KB |
Output is correct |
31 |
Correct |
162 ms |
6904 KB |
Output is correct |
32 |
Correct |
166 ms |
6904 KB |
Output is correct |
33 |
Correct |
159 ms |
6904 KB |
Output is correct |
34 |
Correct |
155 ms |
7036 KB |
Output is correct |
35 |
Correct |
146 ms |
6904 KB |
Output is correct |
36 |
Correct |
143 ms |
6904 KB |
Output is correct |
37 |
Correct |
146 ms |
6996 KB |
Output is correct |
38 |
Correct |
100 ms |
7032 KB |
Output is correct |
39 |
Correct |
104 ms |
7032 KB |
Output is correct |
40 |
Correct |
103 ms |
7032 KB |
Output is correct |
41 |
Correct |
95 ms |
7032 KB |
Output is correct |
42 |
Correct |
97 ms |
7032 KB |
Output is correct |
43 |
Correct |
116 ms |
7160 KB |
Output is correct |
44 |
Correct |
85 ms |
7000 KB |
Output is correct |
45 |
Correct |
86 ms |
6992 KB |
Output is correct |
46 |
Correct |
86 ms |
7032 KB |
Output is correct |
47 |
Correct |
863 ms |
21752 KB |
Output is correct |
48 |
Correct |
3391 ms |
58936 KB |
Output is correct |
49 |
Correct |
3741 ms |
63756 KB |
Output is correct |
50 |
Correct |
4099 ms |
63784 KB |
Output is correct |
51 |
Correct |
3971 ms |
63796 KB |
Output is correct |
52 |
Correct |
3676 ms |
63796 KB |
Output is correct |
53 |
Correct |
3882 ms |
63660 KB |
Output is correct |
54 |
Correct |
3155 ms |
63564 KB |
Output is correct |
55 |
Correct |
3845 ms |
63528 KB |
Output is correct |
56 |
Correct |
3123 ms |
63424 KB |
Output is correct |
57 |
Correct |
3604 ms |
63604 KB |
Output is correct |
58 |
Correct |
2984 ms |
63428 KB |
Output is correct |
59 |
Correct |
2650 ms |
63400 KB |
Output is correct |
60 |
Correct |
2940 ms |
63460 KB |
Output is correct |
61 |
Correct |
2753 ms |
63420 KB |
Output is correct |
62 |
Correct |
2763 ms |
63416 KB |
Output is correct |
63 |
Correct |
2443 ms |
63224 KB |
Output is correct |
64 |
Correct |
2526 ms |
63252 KB |
Output is correct |
65 |
Correct |
2356 ms |
63244 KB |
Output is correct |
66 |
Correct |
2267 ms |
63228 KB |
Output is correct |
67 |
Correct |
2247 ms |
63168 KB |
Output is correct |