#include<bits/stdc++.h>
//~ #include "bubblesort2.h"
using namespace std;
#define endl "\n"
typedef long long int ll;
const int MOD = 1e9 + 7;
struct segTree{
vector<int> v;
vector<int> upd;
int siz;
void init(int n){
siz = 1;
while(siz < n) siz *= 2;
v.assign(2 * siz, 0);
upd.assign(2 * siz, 0);
}
void set(int l, int r, int u, int x, int lx, int rx){
if(lx >= l && rx <= r){
upd[x] += u;
v[x] += u;
return;
}
if(lx >= r || rx <= l) return;
int m = (lx + rx) / 2;
set(l, r, u, 2 * x + 1, lx, m);
set(l, r, u, 2 * x + 2, m, rx);
v[x] = max(v[2 * x + 1], v[2 * x + 2]) + upd[x];
}
void set(int l, int r, int u){
set(l, r, u, 0, 0, siz);
}
int get_ans(){
return v[0];
}
};
vector<int> countScans(vector<int> A,vector<int> V1,vector<int> V2){
int n = (int)A.size();
int q = (int)V1.size();
vector<int> all(n + q);
for(int i = 0; i < n; i++) all[i] = A[i];
for(int i = 0; i < q; i++) all[i + n] = V2[i];
sort(all.begin(), all.end());
unordered_map<int, int> m;
int curr = 0;
for(int i = 0; i < n + q; i++){
if(i == 0) {m[all[i]] = curr; curr++;}
else{
if(all[i] == all[i-1]) continue;
m[all[i]] = curr;
curr++;
}
}
segTree st; st.init(curr);
vector<set<int>> pos(curr);
for(int i = 0; i < n; i++){
pos[m[A[i]]].insert(i);
st.set(m[A[i]], curr, -1);
}
for(int i = 0; i < curr; i++){
if((int)pos[i].size() > 0){
st.set(i, i + 1, *pos[i].rbegin()+1);
}
}
vector<int> ans(q);
for(int qq = 0; qq < q; qq++){
int i = V1[qq];
int lst = A[i];
int nw = V2[qq];
A[i] = nw;
lst = m[lst];
nw = m[nw];
int lst_pos = *pos[lst].rbegin();
pos[lst].erase(i);
if((int)pos[lst].size() > 0) st.set(lst, lst + 1, (*pos[lst].rbegin() - lst_pos));
else st.set(lst, lst + 1, -lst_pos - 1);
st.set(lst, curr, 1);
if((int)pos[nw].size() == 0){
pos[nw].insert(i);
st.set(nw, nw + 1, i+1);
}else{
lst_pos = *pos[nw].rbegin();
pos[nw].insert(i);
st.set(nw, nw + 1, (*pos[nw].rbegin() - lst_pos));
}
st.set(nw, curr, -1);
ans[qq] = st.get_ans();
}
return ans;
}
//~ int readInt(){
//~ int i;
//~ if(scanf("%d",&i)!=1){
//~ fprintf(stderr,"Error while reading input\n");
//~ exit(1);
//~ }
//~ return i;
//~ }
//~ int main(){
//~ int N,Q;
//~ N=readInt();
//~ Q=readInt();
//~ std::vector<int> A(N);
//~ for(int i=0;i<N;i++)
//~ A[i]=readInt();
//~ std::vector<int> X(Q),V(Q);
//~ for(int j=0;j<Q;j++){
//~ X[j]=readInt();
//~ V[j]=readInt();
//~ }
//~ std::vector<int> res=countScans(A,X,V);
//~ for(int j=0;j<int(res.size());j++)
//~ printf("%d\n",res[j]);
//~ }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
852 KB |
Output is correct |
4 |
Correct |
6 ms |
852 KB |
Output is correct |
5 |
Correct |
5 ms |
852 KB |
Output is correct |
6 |
Correct |
5 ms |
860 KB |
Output is correct |
7 |
Correct |
5 ms |
852 KB |
Output is correct |
8 |
Correct |
4 ms |
852 KB |
Output is correct |
9 |
Correct |
5 ms |
852 KB |
Output is correct |
10 |
Correct |
4 ms |
852 KB |
Output is correct |
11 |
Correct |
5 ms |
852 KB |
Output is correct |
12 |
Correct |
5 ms |
852 KB |
Output is correct |
13 |
Correct |
5 ms |
852 KB |
Output is correct |
14 |
Correct |
4 ms |
852 KB |
Output is correct |
15 |
Correct |
5 ms |
824 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
4 ms |
828 KB |
Output is correct |
18 |
Correct |
5 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
852 KB |
Output is correct |
4 |
Correct |
6 ms |
852 KB |
Output is correct |
5 |
Correct |
5 ms |
852 KB |
Output is correct |
6 |
Correct |
5 ms |
860 KB |
Output is correct |
7 |
Correct |
5 ms |
852 KB |
Output is correct |
8 |
Correct |
4 ms |
852 KB |
Output is correct |
9 |
Correct |
5 ms |
852 KB |
Output is correct |
10 |
Correct |
4 ms |
852 KB |
Output is correct |
11 |
Correct |
5 ms |
852 KB |
Output is correct |
12 |
Correct |
5 ms |
852 KB |
Output is correct |
13 |
Correct |
5 ms |
852 KB |
Output is correct |
14 |
Correct |
4 ms |
852 KB |
Output is correct |
15 |
Correct |
5 ms |
824 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
4 ms |
828 KB |
Output is correct |
18 |
Correct |
5 ms |
724 KB |
Output is correct |
19 |
Correct |
18 ms |
2456 KB |
Output is correct |
20 |
Correct |
20 ms |
2772 KB |
Output is correct |
21 |
Correct |
20 ms |
2740 KB |
Output is correct |
22 |
Correct |
18 ms |
2772 KB |
Output is correct |
23 |
Correct |
19 ms |
2604 KB |
Output is correct |
24 |
Correct |
21 ms |
2600 KB |
Output is correct |
25 |
Correct |
17 ms |
2516 KB |
Output is correct |
26 |
Correct |
17 ms |
2516 KB |
Output is correct |
27 |
Correct |
17 ms |
2364 KB |
Output is correct |
28 |
Correct |
17 ms |
2492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
2004 KB |
Output is correct |
2 |
Correct |
44 ms |
3532 KB |
Output is correct |
3 |
Correct |
78 ms |
4868 KB |
Output is correct |
4 |
Correct |
87 ms |
4984 KB |
Output is correct |
5 |
Correct |
90 ms |
4872 KB |
Output is correct |
6 |
Correct |
67 ms |
4996 KB |
Output is correct |
7 |
Correct |
69 ms |
5064 KB |
Output is correct |
8 |
Correct |
67 ms |
4960 KB |
Output is correct |
9 |
Correct |
72 ms |
4940 KB |
Output is correct |
10 |
Correct |
55 ms |
5072 KB |
Output is correct |
11 |
Correct |
55 ms |
5056 KB |
Output is correct |
12 |
Correct |
58 ms |
5072 KB |
Output is correct |
13 |
Correct |
59 ms |
5068 KB |
Output is correct |
14 |
Correct |
70 ms |
5064 KB |
Output is correct |
15 |
Correct |
56 ms |
5092 KB |
Output is correct |
16 |
Correct |
50 ms |
4944 KB |
Output is correct |
17 |
Correct |
48 ms |
4980 KB |
Output is correct |
18 |
Correct |
48 ms |
5052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
852 KB |
Output is correct |
4 |
Correct |
6 ms |
852 KB |
Output is correct |
5 |
Correct |
5 ms |
852 KB |
Output is correct |
6 |
Correct |
5 ms |
860 KB |
Output is correct |
7 |
Correct |
5 ms |
852 KB |
Output is correct |
8 |
Correct |
4 ms |
852 KB |
Output is correct |
9 |
Correct |
5 ms |
852 KB |
Output is correct |
10 |
Correct |
4 ms |
852 KB |
Output is correct |
11 |
Correct |
5 ms |
852 KB |
Output is correct |
12 |
Correct |
5 ms |
852 KB |
Output is correct |
13 |
Correct |
5 ms |
852 KB |
Output is correct |
14 |
Correct |
4 ms |
852 KB |
Output is correct |
15 |
Correct |
5 ms |
824 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
4 ms |
828 KB |
Output is correct |
18 |
Correct |
5 ms |
724 KB |
Output is correct |
19 |
Correct |
18 ms |
2456 KB |
Output is correct |
20 |
Correct |
20 ms |
2772 KB |
Output is correct |
21 |
Correct |
20 ms |
2740 KB |
Output is correct |
22 |
Correct |
18 ms |
2772 KB |
Output is correct |
23 |
Correct |
19 ms |
2604 KB |
Output is correct |
24 |
Correct |
21 ms |
2600 KB |
Output is correct |
25 |
Correct |
17 ms |
2516 KB |
Output is correct |
26 |
Correct |
17 ms |
2516 KB |
Output is correct |
27 |
Correct |
17 ms |
2364 KB |
Output is correct |
28 |
Correct |
17 ms |
2492 KB |
Output is correct |
29 |
Correct |
14 ms |
2004 KB |
Output is correct |
30 |
Correct |
44 ms |
3532 KB |
Output is correct |
31 |
Correct |
78 ms |
4868 KB |
Output is correct |
32 |
Correct |
87 ms |
4984 KB |
Output is correct |
33 |
Correct |
90 ms |
4872 KB |
Output is correct |
34 |
Correct |
67 ms |
4996 KB |
Output is correct |
35 |
Correct |
69 ms |
5064 KB |
Output is correct |
36 |
Correct |
67 ms |
4960 KB |
Output is correct |
37 |
Correct |
72 ms |
4940 KB |
Output is correct |
38 |
Correct |
55 ms |
5072 KB |
Output is correct |
39 |
Correct |
55 ms |
5056 KB |
Output is correct |
40 |
Correct |
58 ms |
5072 KB |
Output is correct |
41 |
Correct |
59 ms |
5068 KB |
Output is correct |
42 |
Correct |
70 ms |
5064 KB |
Output is correct |
43 |
Correct |
56 ms |
5092 KB |
Output is correct |
44 |
Correct |
50 ms |
4944 KB |
Output is correct |
45 |
Correct |
48 ms |
4980 KB |
Output is correct |
46 |
Correct |
48 ms |
5052 KB |
Output is correct |
47 |
Correct |
690 ms |
50808 KB |
Output is correct |
48 |
Correct |
2580 ms |
147800 KB |
Output is correct |
49 |
Correct |
2868 ms |
160244 KB |
Output is correct |
50 |
Correct |
2971 ms |
160256 KB |
Output is correct |
51 |
Correct |
2897 ms |
160352 KB |
Output is correct |
52 |
Correct |
2813 ms |
160248 KB |
Output is correct |
53 |
Correct |
2934 ms |
160256 KB |
Output is correct |
54 |
Correct |
2656 ms |
160428 KB |
Output is correct |
55 |
Correct |
3025 ms |
160364 KB |
Output is correct |
56 |
Correct |
2752 ms |
160412 KB |
Output is correct |
57 |
Correct |
2735 ms |
160428 KB |
Output is correct |
58 |
Correct |
2736 ms |
160348 KB |
Output is correct |
59 |
Correct |
2232 ms |
149344 KB |
Output is correct |
60 |
Correct |
2195 ms |
149360 KB |
Output is correct |
61 |
Correct |
2262 ms |
149360 KB |
Output is correct |
62 |
Correct |
2115 ms |
144336 KB |
Output is correct |
63 |
Correct |
2016 ms |
144588 KB |
Output is correct |
64 |
Correct |
2105 ms |
144288 KB |
Output is correct |
65 |
Correct |
1928 ms |
139196 KB |
Output is correct |
66 |
Correct |
2091 ms |
139376 KB |
Output is correct |
67 |
Correct |
1901 ms |
139304 KB |
Output is correct |