#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;
const int N=500007,pot=1<<20;
map<int,int>id[N];
int lzy[2*pot+7];
int seg[2*pot+7];
void push(int v)
{
lzy[2*v]+=lzy[v];
seg[2*v]+=lzy[v];
lzy[2*v+1]+=lzy[v];
seg[2*v+1]+=lzy[v];
lzy[v]=0;
}
void ins(int v,int a,int b,int l,int r,int x)
{
if(a<=l&&b>=r)
{
seg[v]+=x;
lzy[v]+=x;
return ;
}
if(r<a||l>b) return ;
push(v);
ins(2*v,a,b,l,(l+r)/2,x);
ins(2*v+1,a,b,(l+r)/2+1,r,x);
seg[v]=max(seg[2*v],seg[2*v+1]);
}
vector<int>countScans(vector<int>a,vector<int>X,vector<int>V)
{
set<pair<int,int>>S;
int n=sz(a),q=sz(X);
for(int i=0;i<n;i++) S.insert({a[i],i});
for(int i=0;i<q;i++) S.insert({V[i],X[i]});
int it=0;
for(int i=1;i<=pot;i++) seg[i+pot-1]=-inf;
for(auto x:S)
{
id[x.nd][x.st]=++it;
seg[it+pot-1]+=x.nd;
}
for(int i=0;i<n;i++) seg[id[i][a[i]]+pot-1]+=inf;
for(int i=pot-1;i>0;i--) seg[i]=max(seg[2*i],seg[2*i+1]);
for(int i=0;i<n;i++) ins(1,id[i][a[i]]+1,pot,1,pot,-1);
vector<int>ans(q);
for(int i=0;i<q;i++)
{
ins(1,id[X[i]][a[X[i]]]+1,pot,1,pot,1);
ins(1,id[X[i]][a[X[i]]],id[X[i]][a[X[i]]],1,pot,-inf);
a[X[i]]=V[i];
ins(1,id[X[i]][a[X[i]]],id[X[i]][a[X[i]]],1,pot,inf);
ins(1,id[X[i]][a[X[i]]]+1,pot,1,pot,-1);
ans[i]=seg[1];
}
return ans;
}
/*int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
vector<int>X=countScans({1,2, 3, 4},{0, 2},{3, 1});
for(auto x:X) cout<<x<<" ";
return 0;
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
32108 KB |
Output is correct |
2 |
Correct |
18 ms |
32256 KB |
Output is correct |
3 |
Correct |
20 ms |
32448 KB |
Output is correct |
4 |
Correct |
20 ms |
32468 KB |
Output is correct |
5 |
Correct |
21 ms |
32448 KB |
Output is correct |
6 |
Correct |
20 ms |
32540 KB |
Output is correct |
7 |
Correct |
20 ms |
32560 KB |
Output is correct |
8 |
Correct |
20 ms |
32508 KB |
Output is correct |
9 |
Correct |
20 ms |
32552 KB |
Output is correct |
10 |
Correct |
21 ms |
32412 KB |
Output is correct |
11 |
Correct |
20 ms |
32468 KB |
Output is correct |
12 |
Correct |
20 ms |
32468 KB |
Output is correct |
13 |
Correct |
23 ms |
32420 KB |
Output is correct |
14 |
Correct |
23 ms |
32464 KB |
Output is correct |
15 |
Correct |
20 ms |
32468 KB |
Output is correct |
16 |
Correct |
19 ms |
32380 KB |
Output is correct |
17 |
Correct |
19 ms |
32388 KB |
Output is correct |
18 |
Correct |
20 ms |
32340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
32108 KB |
Output is correct |
2 |
Correct |
18 ms |
32256 KB |
Output is correct |
3 |
Correct |
20 ms |
32448 KB |
Output is correct |
4 |
Correct |
20 ms |
32468 KB |
Output is correct |
5 |
Correct |
21 ms |
32448 KB |
Output is correct |
6 |
Correct |
20 ms |
32540 KB |
Output is correct |
7 |
Correct |
20 ms |
32560 KB |
Output is correct |
8 |
Correct |
20 ms |
32508 KB |
Output is correct |
9 |
Correct |
20 ms |
32552 KB |
Output is correct |
10 |
Correct |
21 ms |
32412 KB |
Output is correct |
11 |
Correct |
20 ms |
32468 KB |
Output is correct |
12 |
Correct |
20 ms |
32468 KB |
Output is correct |
13 |
Correct |
23 ms |
32420 KB |
Output is correct |
14 |
Correct |
23 ms |
32464 KB |
Output is correct |
15 |
Correct |
20 ms |
32468 KB |
Output is correct |
16 |
Correct |
19 ms |
32380 KB |
Output is correct |
17 |
Correct |
19 ms |
32388 KB |
Output is correct |
18 |
Correct |
20 ms |
32340 KB |
Output is correct |
19 |
Correct |
31 ms |
33764 KB |
Output is correct |
20 |
Correct |
34 ms |
34068 KB |
Output is correct |
21 |
Correct |
33 ms |
34088 KB |
Output is correct |
22 |
Correct |
34 ms |
33988 KB |
Output is correct |
23 |
Correct |
32 ms |
33868 KB |
Output is correct |
24 |
Correct |
38 ms |
33928 KB |
Output is correct |
25 |
Correct |
32 ms |
33656 KB |
Output is correct |
26 |
Correct |
31 ms |
33684 KB |
Output is correct |
27 |
Correct |
31 ms |
33620 KB |
Output is correct |
28 |
Correct |
31 ms |
33580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
35360 KB |
Output is correct |
2 |
Correct |
88 ms |
39612 KB |
Output is correct |
3 |
Correct |
148 ms |
44084 KB |
Output is correct |
4 |
Correct |
141 ms |
44044 KB |
Output is correct |
5 |
Correct |
140 ms |
44008 KB |
Output is correct |
6 |
Correct |
146 ms |
43836 KB |
Output is correct |
7 |
Correct |
143 ms |
43884 KB |
Output is correct |
8 |
Correct |
135 ms |
43900 KB |
Output is correct |
9 |
Correct |
135 ms |
43852 KB |
Output is correct |
10 |
Correct |
107 ms |
39500 KB |
Output is correct |
11 |
Correct |
107 ms |
39464 KB |
Output is correct |
12 |
Correct |
107 ms |
39672 KB |
Output is correct |
13 |
Correct |
105 ms |
39616 KB |
Output is correct |
14 |
Correct |
125 ms |
39496 KB |
Output is correct |
15 |
Correct |
106 ms |
39500 KB |
Output is correct |
16 |
Correct |
106 ms |
39516 KB |
Output is correct |
17 |
Correct |
103 ms |
39624 KB |
Output is correct |
18 |
Correct |
116 ms |
39600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
32108 KB |
Output is correct |
2 |
Correct |
18 ms |
32256 KB |
Output is correct |
3 |
Correct |
20 ms |
32448 KB |
Output is correct |
4 |
Correct |
20 ms |
32468 KB |
Output is correct |
5 |
Correct |
21 ms |
32448 KB |
Output is correct |
6 |
Correct |
20 ms |
32540 KB |
Output is correct |
7 |
Correct |
20 ms |
32560 KB |
Output is correct |
8 |
Correct |
20 ms |
32508 KB |
Output is correct |
9 |
Correct |
20 ms |
32552 KB |
Output is correct |
10 |
Correct |
21 ms |
32412 KB |
Output is correct |
11 |
Correct |
20 ms |
32468 KB |
Output is correct |
12 |
Correct |
20 ms |
32468 KB |
Output is correct |
13 |
Correct |
23 ms |
32420 KB |
Output is correct |
14 |
Correct |
23 ms |
32464 KB |
Output is correct |
15 |
Correct |
20 ms |
32468 KB |
Output is correct |
16 |
Correct |
19 ms |
32380 KB |
Output is correct |
17 |
Correct |
19 ms |
32388 KB |
Output is correct |
18 |
Correct |
20 ms |
32340 KB |
Output is correct |
19 |
Correct |
31 ms |
33764 KB |
Output is correct |
20 |
Correct |
34 ms |
34068 KB |
Output is correct |
21 |
Correct |
33 ms |
34088 KB |
Output is correct |
22 |
Correct |
34 ms |
33988 KB |
Output is correct |
23 |
Correct |
32 ms |
33868 KB |
Output is correct |
24 |
Correct |
38 ms |
33928 KB |
Output is correct |
25 |
Correct |
32 ms |
33656 KB |
Output is correct |
26 |
Correct |
31 ms |
33684 KB |
Output is correct |
27 |
Correct |
31 ms |
33620 KB |
Output is correct |
28 |
Correct |
31 ms |
33580 KB |
Output is correct |
29 |
Correct |
36 ms |
35360 KB |
Output is correct |
30 |
Correct |
88 ms |
39612 KB |
Output is correct |
31 |
Correct |
148 ms |
44084 KB |
Output is correct |
32 |
Correct |
141 ms |
44044 KB |
Output is correct |
33 |
Correct |
140 ms |
44008 KB |
Output is correct |
34 |
Correct |
146 ms |
43836 KB |
Output is correct |
35 |
Correct |
143 ms |
43884 KB |
Output is correct |
36 |
Correct |
135 ms |
43900 KB |
Output is correct |
37 |
Correct |
135 ms |
43852 KB |
Output is correct |
38 |
Correct |
107 ms |
39500 KB |
Output is correct |
39 |
Correct |
107 ms |
39464 KB |
Output is correct |
40 |
Correct |
107 ms |
39672 KB |
Output is correct |
41 |
Correct |
105 ms |
39616 KB |
Output is correct |
42 |
Correct |
125 ms |
39496 KB |
Output is correct |
43 |
Correct |
106 ms |
39500 KB |
Output is correct |
44 |
Correct |
106 ms |
39516 KB |
Output is correct |
45 |
Correct |
103 ms |
39624 KB |
Output is correct |
46 |
Correct |
116 ms |
39600 KB |
Output is correct |
47 |
Correct |
582 ms |
69972 KB |
Output is correct |
48 |
Correct |
2460 ms |
149508 KB |
Output is correct |
49 |
Correct |
2743 ms |
160376 KB |
Output is correct |
50 |
Correct |
2758 ms |
160380 KB |
Output is correct |
51 |
Correct |
2748 ms |
160384 KB |
Output is correct |
52 |
Correct |
2769 ms |
160472 KB |
Output is correct |
53 |
Correct |
2765 ms |
160448 KB |
Output is correct |
54 |
Correct |
2477 ms |
160528 KB |
Output is correct |
55 |
Correct |
2712 ms |
160568 KB |
Output is correct |
56 |
Correct |
2659 ms |
160588 KB |
Output is correct |
57 |
Correct |
2795 ms |
160604 KB |
Output is correct |
58 |
Correct |
2749 ms |
160424 KB |
Output is correct |
59 |
Correct |
2225 ms |
146508 KB |
Output is correct |
60 |
Correct |
2226 ms |
146516 KB |
Output is correct |
61 |
Correct |
2204 ms |
146400 KB |
Output is correct |
62 |
Correct |
1932 ms |
139972 KB |
Output is correct |
63 |
Correct |
2007 ms |
140108 KB |
Output is correct |
64 |
Correct |
2375 ms |
139996 KB |
Output is correct |
65 |
Correct |
1901 ms |
133488 KB |
Output is correct |
66 |
Correct |
1859 ms |
133484 KB |
Output is correct |
67 |
Correct |
1811 ms |
133496 KB |
Output is correct |