#include <bits/stdc++.h>
using namespace std;
#define pb push_back
using vi=vector<int>;
#define mp make_pair
#define lb lower_bound
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
const int N=2e6+5;
vi a;
int seg[N], lzy[N];
vector<pair<int,int>> v;
void upd(int i, int j, int vv, int p=0, int l=1, int r=sz(v)){
if(i>r or j<l) return;
if(i<=l and r<=j){ seg[p]+=vv,lzy[p]+=vv; return; }
int mid = (l+r)/2; int rp = p+2*(mid-l+1);
if(i<=mid) upd(i,j,vv,p+1,l,mid);
if(j>mid) upd(i,j,vv,rp,mid+1,r);
seg[p] = max(seg[p+1],seg[rp])+lzy[p];
}
void add(int i, int x){
int j = lb(all(v),mp(a[i],i))-begin(v);
int j2 = lb(all(v),mp(a[i],-1))-begin(v);
upd(j,j,i*x), upd(j2,sz(v),-x);
}
vi countScans(vi A, vi x, vi y){
int n = sz(A), q = sz(x); vi ans; a.resize(n+1);
for(int i = 1; i <= n; i++) a[i]=A[i-1],v.pb({a[i],i});
for(int i = 0; i < q; i++) v.pb({y[i],++x[i]});
sort(all(v)); v.erase(unique(all(v)),end(v));
for(int i = 1; i <= n; i++) add(i,1);
for(int i = 0; i < q; i++)
add(x[i],-1),a[x[i]]=y[i],add(x[i],1),ans.pb(seg[0]);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
468 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
3 ms |
492 KB |
Output is correct |
7 |
Correct |
3 ms |
468 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
468 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
4 ms |
436 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
468 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
3 ms |
492 KB |
Output is correct |
7 |
Correct |
3 ms |
468 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
468 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
4 ms |
436 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
19 |
Correct |
17 ms |
968 KB |
Output is correct |
20 |
Correct |
17 ms |
1044 KB |
Output is correct |
21 |
Correct |
16 ms |
1048 KB |
Output is correct |
22 |
Correct |
14 ms |
1048 KB |
Output is correct |
23 |
Correct |
13 ms |
980 KB |
Output is correct |
24 |
Correct |
13 ms |
1024 KB |
Output is correct |
25 |
Correct |
13 ms |
996 KB |
Output is correct |
26 |
Correct |
13 ms |
980 KB |
Output is correct |
27 |
Correct |
18 ms |
976 KB |
Output is correct |
28 |
Correct |
14 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
1500 KB |
Output is correct |
2 |
Correct |
54 ms |
2796 KB |
Output is correct |
3 |
Correct |
121 ms |
4476 KB |
Output is correct |
4 |
Correct |
95 ms |
4388 KB |
Output is correct |
5 |
Correct |
102 ms |
4416 KB |
Output is correct |
6 |
Correct |
105 ms |
4408 KB |
Output is correct |
7 |
Correct |
94 ms |
4384 KB |
Output is correct |
8 |
Correct |
91 ms |
4416 KB |
Output is correct |
9 |
Correct |
132 ms |
4392 KB |
Output is correct |
10 |
Correct |
76 ms |
3720 KB |
Output is correct |
11 |
Correct |
71 ms |
3696 KB |
Output is correct |
12 |
Correct |
76 ms |
3700 KB |
Output is correct |
13 |
Correct |
96 ms |
3744 KB |
Output is correct |
14 |
Correct |
75 ms |
3704 KB |
Output is correct |
15 |
Correct |
79 ms |
3708 KB |
Output is correct |
16 |
Correct |
72 ms |
3724 KB |
Output is correct |
17 |
Correct |
69 ms |
3652 KB |
Output is correct |
18 |
Correct |
71 ms |
3780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
468 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
3 ms |
492 KB |
Output is correct |
7 |
Correct |
3 ms |
468 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
468 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
4 ms |
436 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
19 |
Correct |
17 ms |
968 KB |
Output is correct |
20 |
Correct |
17 ms |
1044 KB |
Output is correct |
21 |
Correct |
16 ms |
1048 KB |
Output is correct |
22 |
Correct |
14 ms |
1048 KB |
Output is correct |
23 |
Correct |
13 ms |
980 KB |
Output is correct |
24 |
Correct |
13 ms |
1024 KB |
Output is correct |
25 |
Correct |
13 ms |
996 KB |
Output is correct |
26 |
Correct |
13 ms |
980 KB |
Output is correct |
27 |
Correct |
18 ms |
976 KB |
Output is correct |
28 |
Correct |
14 ms |
980 KB |
Output is correct |
29 |
Correct |
19 ms |
1500 KB |
Output is correct |
30 |
Correct |
54 ms |
2796 KB |
Output is correct |
31 |
Correct |
121 ms |
4476 KB |
Output is correct |
32 |
Correct |
95 ms |
4388 KB |
Output is correct |
33 |
Correct |
102 ms |
4416 KB |
Output is correct |
34 |
Correct |
105 ms |
4408 KB |
Output is correct |
35 |
Correct |
94 ms |
4384 KB |
Output is correct |
36 |
Correct |
91 ms |
4416 KB |
Output is correct |
37 |
Correct |
132 ms |
4392 KB |
Output is correct |
38 |
Correct |
76 ms |
3720 KB |
Output is correct |
39 |
Correct |
71 ms |
3696 KB |
Output is correct |
40 |
Correct |
76 ms |
3700 KB |
Output is correct |
41 |
Correct |
96 ms |
3744 KB |
Output is correct |
42 |
Correct |
75 ms |
3704 KB |
Output is correct |
43 |
Correct |
79 ms |
3708 KB |
Output is correct |
44 |
Correct |
72 ms |
3724 KB |
Output is correct |
45 |
Correct |
69 ms |
3652 KB |
Output is correct |
46 |
Correct |
71 ms |
3780 KB |
Output is correct |
47 |
Correct |
406 ms |
12868 KB |
Output is correct |
48 |
Correct |
1629 ms |
38192 KB |
Output is correct |
49 |
Correct |
1828 ms |
41460 KB |
Output is correct |
50 |
Correct |
1845 ms |
41468 KB |
Output is correct |
51 |
Correct |
1761 ms |
41408 KB |
Output is correct |
52 |
Correct |
1919 ms |
41504 KB |
Output is correct |
53 |
Correct |
1803 ms |
41428 KB |
Output is correct |
54 |
Correct |
1790 ms |
41512 KB |
Output is correct |
55 |
Correct |
1704 ms |
41448 KB |
Output is correct |
56 |
Correct |
1690 ms |
41420 KB |
Output is correct |
57 |
Correct |
1722 ms |
41480 KB |
Output is correct |
58 |
Correct |
1638 ms |
41480 KB |
Output is correct |
59 |
Correct |
1396 ms |
39512 KB |
Output is correct |
60 |
Correct |
1380 ms |
39464 KB |
Output is correct |
61 |
Correct |
1389 ms |
39476 KB |
Output is correct |
62 |
Correct |
1342 ms |
38576 KB |
Output is correct |
63 |
Correct |
1381 ms |
38576 KB |
Output is correct |
64 |
Correct |
1313 ms |
38732 KB |
Output is correct |
65 |
Correct |
1254 ms |
37504 KB |
Output is correct |
66 |
Correct |
1168 ms |
37664 KB |
Output is correct |
67 |
Correct |
1253 ms |
37608 KB |
Output is correct |