#include <bits/stdc++.h>
using namespace std;
#define lc ind<<1
#define rc ind<<1|1
const int MN = 1e6 + 5;
vector<pair<int,int>> xs; int sz;
int getx (const pair<int,int> &x) {return lower_bound(xs.begin(),xs.end(),x) - xs.begin() + 1;}
struct Node {
int mx,lz;
} tree[MN<<2];
void push_down (int ind, int l, int r) {
if (!tree[ind].lz) return;
tree[ind].mx += tree[ind].lz;
if (l!=r) {
tree[lc].lz += tree[ind].lz;
tree[rc].lz += tree[ind].lz;
}
tree[ind].lz = 0;
}
void update (int ind, int tl, int tr, int l, int r, int v) {
push_down(ind,tl,tr);
if (l > tr || r < tl) return;
if (l <= tl && tr <= r) {
tree[ind].lz += v;
push_down(ind,tl,tr);
return;
}
int mid = (tl + tr) / 2;
update(lc,tl,mid,l,r,v); update(rc,mid+1,tr,l,r,v);
tree[ind].mx = max(tree[lc].mx,tree[rc].mx);
}
int query (int ind, int tl, int tr, int l, int r) {
push_down(ind,tl,tr);
if (l > tr || r < tl) return INT_MIN;
if (l <= tl && tr <= r) return tree[ind].mx;
int mid = (tl + tr) / 2;
return max(query(lc,tl,mid,l,r),query(rc,mid+1,tr,l,r));
}
int bit[MN];
void u (int x, int v) {
for (;x<MN;x+=x&-x)
bit[x] += v;
}
int qu (int x) {
int ret = 0;
for (;x;x^=x&-x)
ret += bit[x];
return ret;
}
void s (int x, int v) {
int cur = query(1,1,sz,x,x);
update(1,1,sz,x,x,v - cur);
}
vector<int> countScans (vector<int> a, vector<int> x, vector<int> v) {
int n = a.size(), q = x.size(); vector<int> ret(q);
for (int i = 0; i < n; i++) xs.emplace_back(a[i],i);
for (int i = 0; i < q; i++) xs.emplace_back(v[i],x[i]);
sort(xs.begin(),xs.end()); xs.erase(unique(xs.begin(),xs.end()),xs.end());
for (Node &nd : tree) nd = {-MN*1000,0};
sz = xs.size();
for (int i = 0; i < n; i++) u(getx({a[i],i}),1);
for (int i = 0; i < n; i++) {
int pos = getx({a[i],i});
s(pos,i - qu(pos-1));
}
for (int i = 0; i < q; i++) {
int oldpos = getx({a[x[i]],x[i]});
s(oldpos,-1e9);
if (oldpos + 1 <= sz) update(1,1,sz,oldpos+1,sz,1);
a[x[i]] = v[i];
int pos = getx({v[i],x[i]});
u(oldpos,-1); u(pos,1);
s(pos,x[i] - qu(pos-1));
if (pos + 1 <= sz) update(1,1,sz,pos+1,sz,-1);
ret[i] = query(1,1,sz,1,sz);
}
return ret;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
31744 KB |
Output is correct |
2 |
Correct |
30 ms |
31768 KB |
Output is correct |
3 |
Correct |
28 ms |
31872 KB |
Output is correct |
4 |
Correct |
26 ms |
31900 KB |
Output is correct |
5 |
Correct |
26 ms |
31872 KB |
Output is correct |
6 |
Correct |
27 ms |
31872 KB |
Output is correct |
7 |
Correct |
31 ms |
31864 KB |
Output is correct |
8 |
Correct |
28 ms |
31872 KB |
Output is correct |
9 |
Correct |
32 ms |
31864 KB |
Output is correct |
10 |
Correct |
31 ms |
31864 KB |
Output is correct |
11 |
Correct |
29 ms |
31864 KB |
Output is correct |
12 |
Correct |
26 ms |
31872 KB |
Output is correct |
13 |
Correct |
26 ms |
31864 KB |
Output is correct |
14 |
Correct |
26 ms |
31872 KB |
Output is correct |
15 |
Correct |
28 ms |
31844 KB |
Output is correct |
16 |
Correct |
26 ms |
31876 KB |
Output is correct |
17 |
Correct |
26 ms |
31872 KB |
Output is correct |
18 |
Correct |
26 ms |
31872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
31744 KB |
Output is correct |
2 |
Correct |
30 ms |
31768 KB |
Output is correct |
3 |
Correct |
28 ms |
31872 KB |
Output is correct |
4 |
Correct |
26 ms |
31900 KB |
Output is correct |
5 |
Correct |
26 ms |
31872 KB |
Output is correct |
6 |
Correct |
27 ms |
31872 KB |
Output is correct |
7 |
Correct |
31 ms |
31864 KB |
Output is correct |
8 |
Correct |
28 ms |
31872 KB |
Output is correct |
9 |
Correct |
32 ms |
31864 KB |
Output is correct |
10 |
Correct |
31 ms |
31864 KB |
Output is correct |
11 |
Correct |
29 ms |
31864 KB |
Output is correct |
12 |
Correct |
26 ms |
31872 KB |
Output is correct |
13 |
Correct |
26 ms |
31864 KB |
Output is correct |
14 |
Correct |
26 ms |
31872 KB |
Output is correct |
15 |
Correct |
28 ms |
31844 KB |
Output is correct |
16 |
Correct |
26 ms |
31876 KB |
Output is correct |
17 |
Correct |
26 ms |
31872 KB |
Output is correct |
18 |
Correct |
26 ms |
31872 KB |
Output is correct |
19 |
Correct |
56 ms |
32376 KB |
Output is correct |
20 |
Correct |
48 ms |
32504 KB |
Output is correct |
21 |
Correct |
51 ms |
32452 KB |
Output is correct |
22 |
Correct |
47 ms |
32504 KB |
Output is correct |
23 |
Correct |
46 ms |
32512 KB |
Output is correct |
24 |
Correct |
45 ms |
32384 KB |
Output is correct |
25 |
Correct |
52 ms |
32384 KB |
Output is correct |
26 |
Correct |
50 ms |
32504 KB |
Output is correct |
27 |
Correct |
49 ms |
32384 KB |
Output is correct |
28 |
Correct |
48 ms |
32384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
32632 KB |
Output is correct |
2 |
Correct |
129 ms |
33824 KB |
Output is correct |
3 |
Correct |
220 ms |
34924 KB |
Output is correct |
4 |
Correct |
228 ms |
34972 KB |
Output is correct |
5 |
Correct |
222 ms |
34924 KB |
Output is correct |
6 |
Correct |
219 ms |
34924 KB |
Output is correct |
7 |
Correct |
219 ms |
35052 KB |
Output is correct |
8 |
Correct |
218 ms |
34928 KB |
Output is correct |
9 |
Correct |
225 ms |
34956 KB |
Output is correct |
10 |
Correct |
177 ms |
34796 KB |
Output is correct |
11 |
Correct |
181 ms |
34796 KB |
Output is correct |
12 |
Correct |
180 ms |
34796 KB |
Output is correct |
13 |
Correct |
186 ms |
34796 KB |
Output is correct |
14 |
Correct |
180 ms |
34796 KB |
Output is correct |
15 |
Correct |
186 ms |
34796 KB |
Output is correct |
16 |
Correct |
184 ms |
34856 KB |
Output is correct |
17 |
Correct |
177 ms |
34796 KB |
Output is correct |
18 |
Correct |
174 ms |
34924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
31744 KB |
Output is correct |
2 |
Correct |
30 ms |
31768 KB |
Output is correct |
3 |
Correct |
28 ms |
31872 KB |
Output is correct |
4 |
Correct |
26 ms |
31900 KB |
Output is correct |
5 |
Correct |
26 ms |
31872 KB |
Output is correct |
6 |
Correct |
27 ms |
31872 KB |
Output is correct |
7 |
Correct |
31 ms |
31864 KB |
Output is correct |
8 |
Correct |
28 ms |
31872 KB |
Output is correct |
9 |
Correct |
32 ms |
31864 KB |
Output is correct |
10 |
Correct |
31 ms |
31864 KB |
Output is correct |
11 |
Correct |
29 ms |
31864 KB |
Output is correct |
12 |
Correct |
26 ms |
31872 KB |
Output is correct |
13 |
Correct |
26 ms |
31864 KB |
Output is correct |
14 |
Correct |
26 ms |
31872 KB |
Output is correct |
15 |
Correct |
28 ms |
31844 KB |
Output is correct |
16 |
Correct |
26 ms |
31876 KB |
Output is correct |
17 |
Correct |
26 ms |
31872 KB |
Output is correct |
18 |
Correct |
26 ms |
31872 KB |
Output is correct |
19 |
Correct |
56 ms |
32376 KB |
Output is correct |
20 |
Correct |
48 ms |
32504 KB |
Output is correct |
21 |
Correct |
51 ms |
32452 KB |
Output is correct |
22 |
Correct |
47 ms |
32504 KB |
Output is correct |
23 |
Correct |
46 ms |
32512 KB |
Output is correct |
24 |
Correct |
45 ms |
32384 KB |
Output is correct |
25 |
Correct |
52 ms |
32384 KB |
Output is correct |
26 |
Correct |
50 ms |
32504 KB |
Output is correct |
27 |
Correct |
49 ms |
32384 KB |
Output is correct |
28 |
Correct |
48 ms |
32384 KB |
Output is correct |
29 |
Correct |
56 ms |
32632 KB |
Output is correct |
30 |
Correct |
129 ms |
33824 KB |
Output is correct |
31 |
Correct |
220 ms |
34924 KB |
Output is correct |
32 |
Correct |
228 ms |
34972 KB |
Output is correct |
33 |
Correct |
222 ms |
34924 KB |
Output is correct |
34 |
Correct |
219 ms |
34924 KB |
Output is correct |
35 |
Correct |
219 ms |
35052 KB |
Output is correct |
36 |
Correct |
218 ms |
34928 KB |
Output is correct |
37 |
Correct |
225 ms |
34956 KB |
Output is correct |
38 |
Correct |
177 ms |
34796 KB |
Output is correct |
39 |
Correct |
181 ms |
34796 KB |
Output is correct |
40 |
Correct |
180 ms |
34796 KB |
Output is correct |
41 |
Correct |
186 ms |
34796 KB |
Output is correct |
42 |
Correct |
180 ms |
34796 KB |
Output is correct |
43 |
Correct |
186 ms |
34796 KB |
Output is correct |
44 |
Correct |
184 ms |
34856 KB |
Output is correct |
45 |
Correct |
177 ms |
34796 KB |
Output is correct |
46 |
Correct |
174 ms |
34924 KB |
Output is correct |
47 |
Correct |
840 ms |
43104 KB |
Output is correct |
48 |
Correct |
3363 ms |
67284 KB |
Output is correct |
49 |
Correct |
3762 ms |
70248 KB |
Output is correct |
50 |
Correct |
3981 ms |
70252 KB |
Output is correct |
51 |
Correct |
3614 ms |
70100 KB |
Output is correct |
52 |
Correct |
3766 ms |
70128 KB |
Output is correct |
53 |
Correct |
3723 ms |
70228 KB |
Output is correct |
54 |
Correct |
3348 ms |
70296 KB |
Output is correct |
55 |
Correct |
3789 ms |
70336 KB |
Output is correct |
56 |
Correct |
3648 ms |
70384 KB |
Output is correct |
57 |
Correct |
4086 ms |
70228 KB |
Output is correct |
58 |
Correct |
3319 ms |
70280 KB |
Output is correct |
59 |
Correct |
3398 ms |
68540 KB |
Output is correct |
60 |
Correct |
2973 ms |
68436 KB |
Output is correct |
61 |
Correct |
3108 ms |
68692 KB |
Output is correct |
62 |
Correct |
2890 ms |
68204 KB |
Output is correct |
63 |
Correct |
2850 ms |
68132 KB |
Output is correct |
64 |
Correct |
2819 ms |
68052 KB |
Output is correct |
65 |
Correct |
2631 ms |
67676 KB |
Output is correct |
66 |
Correct |
2493 ms |
67748 KB |
Output is correct |
67 |
Correct |
2515 ms |
67720 KB |
Output is correct |