//fast
#include<bits/stdc++.h>
#include "bubblesort2.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(x) x.begin(),x.end()
#define rep(n) for (int i = 0 ; i<n ; i++)
#define pb push_back
const int base = (1<<20);
int maks[base*2];
int sum[base*2];
set<int> pos[base];
int stala[base];
void printout(){
cout << " " << maks[1] << '\n';
cout << " " << maks[2] << " " << maks[3] << '\n';
cout << maks[4] << ' ' << maks[5] << ' ' << maks[6] << ' ' << maks[7] << '\n';
cout << " " << sum[1] << '\n';
cout << " " << sum[2] << " " << sum[3] << '\n';
cout << sum[4] << ' ' << sum[5] << ' ' << sum[6] << ' ' << sum[7] << '\n';
cout << stala[0] << ' ' << stala[1] << ' ' << stala[2] << ' ' << stala[3] << '\n';
}
void dodaj(int l, int r, int p, int k, int w, int c){
if (k<l || r<p) return;
if (p<=l && r<=k){
sum[w]+=c;
maks[w]+=c;
return;
}
dodaj(l,(l+r)/2,p,k,w*2,c);
dodaj((l+r)/2+1,r,p,k,w*2+1,c);
maks[w] = max(maks[w*2],maks[w*2+1])+sum[w];
}
void ustaw(int a, int b){
sum[a+base]-=stala[a];
stala[a] = b;
sum[a+base]+=stala[a];
a+=base;
maks[a] = sum[a];
a/=2;
while (a>=1){
maks[a] = max(maks[a*2],maks[a*2+1])+sum[a];
a/=2;
}
}
map<int,int> tosmall;
int tobig[base];
vector<int> countScans(vector<int> a, vector<int> x, vector<int> v){
int n = a.size(), q = x.size();
vector<int> odp(q);
vector<int> move;
rep(n){
move.pb(a[i]);
}
rep(q){
move.pb(v[i]);
}
int c = -1;
int last = -2137;
sort(all(move));
for (int i : move){
if (i!=last){
last = i;
c++;
tobig[c] = i;
tosmall[i] = c;
}
}
rep(base){
pos[i].insert(-1e8);
}
rep(n){
a[i] = tosmall[a[i]];
pos[a[i]].insert(i);
dodaj(0,base-1,a[i],base-1,1,-1);
}
rep(base){
auto it = pos[i].end();
it--;
ustaw(i,*it);
}
rep(q){
int old = a[x[i]];
int nowy = tosmall[v[i]];
a[x[i]] = nowy;
pos[old].erase(x[i]);
pos[nowy].insert(x[i]);
dodaj(0,base-1,old,base-1,1,1);
dodaj(0,base-1,nowy,base-1,1,-1);
auto it = pos[old].end();
it--;
ustaw(old,*it);
auto it1 = pos[nowy].end();
it1--;
ustaw(nowy,*it1);
odp[i] = maks[1]+1;
//printout();
}
return odp;
}
/*int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,q;
cin >> n >> q;
vector<int> a(n);
vector<int> x(q);
vector<int> v(q);
rep(n) cin >> a[i];
rep(q) cin >> x[i] >> v[i];
vector<int> odp = countScans(a,x,v);
for (int i : odp) cout << i << '\n';
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
149 ms |
115300 KB |
Output is correct |
2 |
Correct |
149 ms |
115328 KB |
Output is correct |
3 |
Correct |
151 ms |
115708 KB |
Output is correct |
4 |
Correct |
158 ms |
115588 KB |
Output is correct |
5 |
Correct |
158 ms |
116044 KB |
Output is correct |
6 |
Correct |
153 ms |
115784 KB |
Output is correct |
7 |
Correct |
159 ms |
115704 KB |
Output is correct |
8 |
Correct |
153 ms |
115788 KB |
Output is correct |
9 |
Correct |
171 ms |
115668 KB |
Output is correct |
10 |
Correct |
167 ms |
115784 KB |
Output is correct |
11 |
Correct |
154 ms |
115756 KB |
Output is correct |
12 |
Correct |
178 ms |
115608 KB |
Output is correct |
13 |
Correct |
175 ms |
115784 KB |
Output is correct |
14 |
Correct |
168 ms |
115784 KB |
Output is correct |
15 |
Correct |
162 ms |
115784 KB |
Output is correct |
16 |
Correct |
168 ms |
115532 KB |
Output is correct |
17 |
Correct |
177 ms |
115556 KB |
Output is correct |
18 |
Correct |
174 ms |
115632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
149 ms |
115300 KB |
Output is correct |
2 |
Correct |
149 ms |
115328 KB |
Output is correct |
3 |
Correct |
151 ms |
115708 KB |
Output is correct |
4 |
Correct |
158 ms |
115588 KB |
Output is correct |
5 |
Correct |
158 ms |
116044 KB |
Output is correct |
6 |
Correct |
153 ms |
115784 KB |
Output is correct |
7 |
Correct |
159 ms |
115704 KB |
Output is correct |
8 |
Correct |
153 ms |
115788 KB |
Output is correct |
9 |
Correct |
171 ms |
115668 KB |
Output is correct |
10 |
Correct |
167 ms |
115784 KB |
Output is correct |
11 |
Correct |
154 ms |
115756 KB |
Output is correct |
12 |
Correct |
178 ms |
115608 KB |
Output is correct |
13 |
Correct |
175 ms |
115784 KB |
Output is correct |
14 |
Correct |
168 ms |
115784 KB |
Output is correct |
15 |
Correct |
162 ms |
115784 KB |
Output is correct |
16 |
Correct |
168 ms |
115532 KB |
Output is correct |
17 |
Correct |
177 ms |
115556 KB |
Output is correct |
18 |
Correct |
174 ms |
115632 KB |
Output is correct |
19 |
Correct |
182 ms |
116808 KB |
Output is correct |
20 |
Correct |
193 ms |
117064 KB |
Output is correct |
21 |
Correct |
185 ms |
117028 KB |
Output is correct |
22 |
Correct |
191 ms |
117088 KB |
Output is correct |
23 |
Correct |
180 ms |
116808 KB |
Output is correct |
24 |
Correct |
180 ms |
116808 KB |
Output is correct |
25 |
Correct |
182 ms |
116808 KB |
Output is correct |
26 |
Correct |
184 ms |
116816 KB |
Output is correct |
27 |
Correct |
182 ms |
116824 KB |
Output is correct |
28 |
Correct |
178 ms |
116808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
183 ms |
117064 KB |
Output is correct |
2 |
Correct |
212 ms |
118416 KB |
Output is correct |
3 |
Correct |
251 ms |
120000 KB |
Output is correct |
4 |
Correct |
255 ms |
120008 KB |
Output is correct |
5 |
Correct |
262 ms |
119880 KB |
Output is correct |
6 |
Correct |
251 ms |
119988 KB |
Output is correct |
7 |
Correct |
249 ms |
121792 KB |
Output is correct |
8 |
Correct |
243 ms |
120004 KB |
Output is correct |
9 |
Correct |
237 ms |
120000 KB |
Output is correct |
10 |
Correct |
229 ms |
120156 KB |
Output is correct |
11 |
Correct |
252 ms |
119940 KB |
Output is correct |
12 |
Correct |
237 ms |
120100 KB |
Output is correct |
13 |
Correct |
233 ms |
119920 KB |
Output is correct |
14 |
Correct |
233 ms |
120256 KB |
Output is correct |
15 |
Correct |
236 ms |
120000 KB |
Output is correct |
16 |
Correct |
230 ms |
121808 KB |
Output is correct |
17 |
Correct |
235 ms |
119912 KB |
Output is correct |
18 |
Correct |
243 ms |
120168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
149 ms |
115300 KB |
Output is correct |
2 |
Correct |
149 ms |
115328 KB |
Output is correct |
3 |
Correct |
151 ms |
115708 KB |
Output is correct |
4 |
Correct |
158 ms |
115588 KB |
Output is correct |
5 |
Correct |
158 ms |
116044 KB |
Output is correct |
6 |
Correct |
153 ms |
115784 KB |
Output is correct |
7 |
Correct |
159 ms |
115704 KB |
Output is correct |
8 |
Correct |
153 ms |
115788 KB |
Output is correct |
9 |
Correct |
171 ms |
115668 KB |
Output is correct |
10 |
Correct |
167 ms |
115784 KB |
Output is correct |
11 |
Correct |
154 ms |
115756 KB |
Output is correct |
12 |
Correct |
178 ms |
115608 KB |
Output is correct |
13 |
Correct |
175 ms |
115784 KB |
Output is correct |
14 |
Correct |
168 ms |
115784 KB |
Output is correct |
15 |
Correct |
162 ms |
115784 KB |
Output is correct |
16 |
Correct |
168 ms |
115532 KB |
Output is correct |
17 |
Correct |
177 ms |
115556 KB |
Output is correct |
18 |
Correct |
174 ms |
115632 KB |
Output is correct |
19 |
Correct |
182 ms |
116808 KB |
Output is correct |
20 |
Correct |
193 ms |
117064 KB |
Output is correct |
21 |
Correct |
185 ms |
117028 KB |
Output is correct |
22 |
Correct |
191 ms |
117088 KB |
Output is correct |
23 |
Correct |
180 ms |
116808 KB |
Output is correct |
24 |
Correct |
180 ms |
116808 KB |
Output is correct |
25 |
Correct |
182 ms |
116808 KB |
Output is correct |
26 |
Correct |
184 ms |
116816 KB |
Output is correct |
27 |
Correct |
182 ms |
116824 KB |
Output is correct |
28 |
Correct |
178 ms |
116808 KB |
Output is correct |
29 |
Correct |
183 ms |
117064 KB |
Output is correct |
30 |
Correct |
212 ms |
118416 KB |
Output is correct |
31 |
Correct |
251 ms |
120000 KB |
Output is correct |
32 |
Correct |
255 ms |
120008 KB |
Output is correct |
33 |
Correct |
262 ms |
119880 KB |
Output is correct |
34 |
Correct |
251 ms |
119988 KB |
Output is correct |
35 |
Correct |
249 ms |
121792 KB |
Output is correct |
36 |
Correct |
243 ms |
120004 KB |
Output is correct |
37 |
Correct |
237 ms |
120000 KB |
Output is correct |
38 |
Correct |
229 ms |
120156 KB |
Output is correct |
39 |
Correct |
252 ms |
119940 KB |
Output is correct |
40 |
Correct |
237 ms |
120100 KB |
Output is correct |
41 |
Correct |
233 ms |
119920 KB |
Output is correct |
42 |
Correct |
233 ms |
120256 KB |
Output is correct |
43 |
Correct |
236 ms |
120000 KB |
Output is correct |
44 |
Correct |
230 ms |
121808 KB |
Output is correct |
45 |
Correct |
235 ms |
119912 KB |
Output is correct |
46 |
Correct |
243 ms |
120168 KB |
Output is correct |
47 |
Correct |
828 ms |
147824 KB |
Output is correct |
48 |
Correct |
2456 ms |
213728 KB |
Output is correct |
49 |
Correct |
2805 ms |
224064 KB |
Output is correct |
50 |
Correct |
2913 ms |
223960 KB |
Output is correct |
51 |
Correct |
2745 ms |
223872 KB |
Output is correct |
52 |
Correct |
2837 ms |
223916 KB |
Output is correct |
53 |
Correct |
3021 ms |
223920 KB |
Output is correct |
54 |
Correct |
2563 ms |
224196 KB |
Output is correct |
55 |
Correct |
2581 ms |
224240 KB |
Output is correct |
56 |
Correct |
2532 ms |
224172 KB |
Output is correct |
57 |
Correct |
2712 ms |
224208 KB |
Output is correct |
58 |
Correct |
2317 ms |
224172 KB |
Output is correct |
59 |
Correct |
2437 ms |
215976 KB |
Output is correct |
60 |
Correct |
2321 ms |
216496 KB |
Output is correct |
61 |
Correct |
2196 ms |
215980 KB |
Output is correct |
62 |
Correct |
1993 ms |
212400 KB |
Output is correct |
63 |
Correct |
2039 ms |
212788 KB |
Output is correct |
64 |
Correct |
2121 ms |
212492 KB |
Output is correct |
65 |
Correct |
2090 ms |
208816 KB |
Output is correct |
66 |
Correct |
1824 ms |
208856 KB |
Output is correct |
67 |
Correct |
1865 ms |
208800 KB |
Output is correct |