#include<bits/stdc++.h>
#include "bubblesort2.h"
using namespace std ;
const int N = 5e5 + 7 ;
int n;
int tree[N * 3] , lazy[N * 3] ;
set<int> ixs[N];
void update(int node , int L , int R , int l , int r , int val){
if(l > R || r < L || l > r)
return ;
if(L>=l && R<=r){
lazy[node] += val ;
return ;
}
int mid = (L + R) >>1 ;
update(node*2+1 , L , mid , l , r , val) ;
update(node*2+2 , mid+1 , R , l , r, val) ;
tree[node] = max(tree[node *2 +1] + lazy[node*2+1] , tree[node*2+2] + lazy[node *2+2] );
}
int query(int node , int L , int R , int l , int r ){
if(l > R || r < L || l > r)
return -N ;
if(L>=l && R<=r)
return tree[node] + lazy[node];
int mid = (L+R) >> 1 ;
int s1 = query(node*2+1 , L , mid , l , r) ;
int s2 = query(node*2+2 , mid+1 , R , l , r ) ;
return max(s1 , s2) + lazy[node] ;
}
int js[N] ;
void add(int ix , int val){
ixs[ix].insert(val) ;
auto u = ixs[ix].end() ; u -- ;
int mx = *u ;
update(0 , 1, N , ix , ix , mx - js[ix]) ;
js[ix] = mx ;
}
void del(int ix , int val){
ixs[ix].erase(ixs[ix].find(val)) ;
auto u = ixs[ix].end() ; u -- ;
int mx = *u ;
update(0 , 1 , N , ix , ix , mx - js[ix]) ;
js[ix] = mx ;
}
unordered_map<int , int > com ;
vector<int> aux ;
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
int Q=X.size();
n = (int) A.size() ;
std::vector<int> answer(Q);
for(auto u : A)
aux.push_back(u) ;
for(auto u : V)
aux.push_back(u) ;
sort(aux.begin() , aux.end()) ;
int l = 0 , now = 0 ;
for(int i = 0 ;i < (int) aux.size() ;i++){
if(aux[i] > l)
now ++ ;
com[aux[i]] = now ;
l = aux[i] ;
}
for(int i = 0 ; i < n; i++){
A[i] = com[A[i]] ;
}
for(int i = 0 ;i < Q ;i++){
V[i] = com[V[i]] ;
}
for(int i = 1 ;i<=now ; i++){
add(i , -N ) ;
}
for(int i = 0 ; i < n; i++){
add(A[i] , i) ;
update( 0 , 1 , N , A[i] , now , -1) ;
}
for (int j=0;j<Q;j++) {
del(A[X[j]] , X[j]) ;
add(V[j] , X[j]) ;
if(V[j] >=A[X[j]]){
update( 0 , 1 , N , A[X[j]] , V[j] -1 , +1) ;
}
else{
update( 0 , 1 ,N , V[j] , A[X[j]] -1 , -1) ;
}
A[ X[j] ] = V[ j ] ;
answer[j] = query(0 , 1 , N , 1 , now ) +1;
answer[j] = max(answer[j] , -100) ;
}
return answer;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
24064 KB |
Output is correct |
2 |
Correct |
19 ms |
24096 KB |
Output is correct |
3 |
Correct |
19 ms |
24448 KB |
Output is correct |
4 |
Correct |
23 ms |
24448 KB |
Output is correct |
5 |
Correct |
20 ms |
24448 KB |
Output is correct |
6 |
Correct |
23 ms |
24448 KB |
Output is correct |
7 |
Correct |
32 ms |
24440 KB |
Output is correct |
8 |
Correct |
20 ms |
24448 KB |
Output is correct |
9 |
Correct |
19 ms |
24448 KB |
Output is correct |
10 |
Correct |
18 ms |
24448 KB |
Output is correct |
11 |
Correct |
19 ms |
24448 KB |
Output is correct |
12 |
Correct |
20 ms |
24448 KB |
Output is correct |
13 |
Correct |
19 ms |
24448 KB |
Output is correct |
14 |
Correct |
19 ms |
24448 KB |
Output is correct |
15 |
Correct |
19 ms |
24448 KB |
Output is correct |
16 |
Correct |
18 ms |
24320 KB |
Output is correct |
17 |
Correct |
18 ms |
24320 KB |
Output is correct |
18 |
Correct |
18 ms |
24320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
24064 KB |
Output is correct |
2 |
Correct |
19 ms |
24096 KB |
Output is correct |
3 |
Correct |
19 ms |
24448 KB |
Output is correct |
4 |
Correct |
23 ms |
24448 KB |
Output is correct |
5 |
Correct |
20 ms |
24448 KB |
Output is correct |
6 |
Correct |
23 ms |
24448 KB |
Output is correct |
7 |
Correct |
32 ms |
24440 KB |
Output is correct |
8 |
Correct |
20 ms |
24448 KB |
Output is correct |
9 |
Correct |
19 ms |
24448 KB |
Output is correct |
10 |
Correct |
18 ms |
24448 KB |
Output is correct |
11 |
Correct |
19 ms |
24448 KB |
Output is correct |
12 |
Correct |
20 ms |
24448 KB |
Output is correct |
13 |
Correct |
19 ms |
24448 KB |
Output is correct |
14 |
Correct |
19 ms |
24448 KB |
Output is correct |
15 |
Correct |
19 ms |
24448 KB |
Output is correct |
16 |
Correct |
18 ms |
24320 KB |
Output is correct |
17 |
Correct |
18 ms |
24320 KB |
Output is correct |
18 |
Correct |
18 ms |
24320 KB |
Output is correct |
19 |
Correct |
38 ms |
26104 KB |
Output is correct |
20 |
Correct |
42 ms |
26360 KB |
Output is correct |
21 |
Correct |
40 ms |
26368 KB |
Output is correct |
22 |
Correct |
42 ms |
26360 KB |
Output is correct |
23 |
Correct |
39 ms |
26104 KB |
Output is correct |
24 |
Correct |
40 ms |
26156 KB |
Output is correct |
25 |
Correct |
39 ms |
25976 KB |
Output is correct |
26 |
Correct |
38 ms |
25976 KB |
Output is correct |
27 |
Correct |
42 ms |
25848 KB |
Output is correct |
28 |
Correct |
37 ms |
25848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
25628 KB |
Output is correct |
2 |
Correct |
91 ms |
26868 KB |
Output is correct |
3 |
Correct |
143 ms |
28016 KB |
Output is correct |
4 |
Correct |
158 ms |
28080 KB |
Output is correct |
5 |
Correct |
143 ms |
28016 KB |
Output is correct |
6 |
Correct |
141 ms |
28016 KB |
Output is correct |
7 |
Correct |
147 ms |
28144 KB |
Output is correct |
8 |
Correct |
139 ms |
28016 KB |
Output is correct |
9 |
Correct |
142 ms |
28016 KB |
Output is correct |
10 |
Correct |
117 ms |
28016 KB |
Output is correct |
11 |
Correct |
122 ms |
28020 KB |
Output is correct |
12 |
Correct |
118 ms |
28016 KB |
Output is correct |
13 |
Correct |
120 ms |
28016 KB |
Output is correct |
14 |
Correct |
116 ms |
28016 KB |
Output is correct |
15 |
Correct |
121 ms |
28156 KB |
Output is correct |
16 |
Correct |
113 ms |
28016 KB |
Output is correct |
17 |
Correct |
114 ms |
28016 KB |
Output is correct |
18 |
Correct |
112 ms |
28016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
24064 KB |
Output is correct |
2 |
Correct |
19 ms |
24096 KB |
Output is correct |
3 |
Correct |
19 ms |
24448 KB |
Output is correct |
4 |
Correct |
23 ms |
24448 KB |
Output is correct |
5 |
Correct |
20 ms |
24448 KB |
Output is correct |
6 |
Correct |
23 ms |
24448 KB |
Output is correct |
7 |
Correct |
32 ms |
24440 KB |
Output is correct |
8 |
Correct |
20 ms |
24448 KB |
Output is correct |
9 |
Correct |
19 ms |
24448 KB |
Output is correct |
10 |
Correct |
18 ms |
24448 KB |
Output is correct |
11 |
Correct |
19 ms |
24448 KB |
Output is correct |
12 |
Correct |
20 ms |
24448 KB |
Output is correct |
13 |
Correct |
19 ms |
24448 KB |
Output is correct |
14 |
Correct |
19 ms |
24448 KB |
Output is correct |
15 |
Correct |
19 ms |
24448 KB |
Output is correct |
16 |
Correct |
18 ms |
24320 KB |
Output is correct |
17 |
Correct |
18 ms |
24320 KB |
Output is correct |
18 |
Correct |
18 ms |
24320 KB |
Output is correct |
19 |
Correct |
38 ms |
26104 KB |
Output is correct |
20 |
Correct |
42 ms |
26360 KB |
Output is correct |
21 |
Correct |
40 ms |
26368 KB |
Output is correct |
22 |
Correct |
42 ms |
26360 KB |
Output is correct |
23 |
Correct |
39 ms |
26104 KB |
Output is correct |
24 |
Correct |
40 ms |
26156 KB |
Output is correct |
25 |
Correct |
39 ms |
25976 KB |
Output is correct |
26 |
Correct |
38 ms |
25976 KB |
Output is correct |
27 |
Correct |
42 ms |
25848 KB |
Output is correct |
28 |
Correct |
37 ms |
25848 KB |
Output is correct |
29 |
Correct |
42 ms |
25628 KB |
Output is correct |
30 |
Correct |
91 ms |
26868 KB |
Output is correct |
31 |
Correct |
143 ms |
28016 KB |
Output is correct |
32 |
Correct |
158 ms |
28080 KB |
Output is correct |
33 |
Correct |
143 ms |
28016 KB |
Output is correct |
34 |
Correct |
141 ms |
28016 KB |
Output is correct |
35 |
Correct |
147 ms |
28144 KB |
Output is correct |
36 |
Correct |
139 ms |
28016 KB |
Output is correct |
37 |
Correct |
142 ms |
28016 KB |
Output is correct |
38 |
Correct |
117 ms |
28016 KB |
Output is correct |
39 |
Correct |
122 ms |
28020 KB |
Output is correct |
40 |
Correct |
118 ms |
28016 KB |
Output is correct |
41 |
Correct |
120 ms |
28016 KB |
Output is correct |
42 |
Correct |
116 ms |
28016 KB |
Output is correct |
43 |
Correct |
121 ms |
28156 KB |
Output is correct |
44 |
Correct |
113 ms |
28016 KB |
Output is correct |
45 |
Correct |
114 ms |
28016 KB |
Output is correct |
46 |
Correct |
112 ms |
28016 KB |
Output is correct |
47 |
Correct |
798 ms |
68104 KB |
Output is correct |
48 |
Runtime error |
1050 ms |
230256 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
49 |
Halted |
0 ms |
0 KB |
- |