#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define ff first
#define ss second
const int MAXN = 1e6 + 100;
int tree[4*MAXN];
int lazy[4*MAXN];
int n;
const int inf = 1e9;
void propagate(int no,int i,int j){
if(lazy[no]==0)return;
tree[no]+=lazy[no];
if(i!=j){
lazy[2*no]+=lazy[no];
lazy[2*no+1]+=lazy[no];
}
lazy[no] = 0;
}
void update(int no,int i,int j,int a,int b,int v){
if(a > b)return;
propagate(no,i,j);
if(i>b || j<a || i>j)return;
if(a<=i && j<=b){
tree[no] += v;
if(i!=j){
lazy[2*no]+=v;
lazy[2*no+1]+=v;
}
return;
}
int m = (i+j)/2;
int l = 2*no,r=2*no+1;
update(l,i,m,a,b,v);
update(r,m+1,j,a,b,v);
tree[no] = max(tree[l],tree[r]);
}
int query(int no,int i,int j,int a,int b){
if(i>b || j<a || i>j)return -inf;
propagate(no,i,j);
if(a<=i && j<=b)return tree[no];
int m = (i+j)/2;
int l = 2*no,r=2*no+1;
return max(query(l,i,m,a,b),query(r,m+1,j,a,b));
}
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
int Q=X.size();
std::vector<int> answer(Q);
vector<pii> vec;
int n = A.size();
for(int i=0;i<n;i++){
vec.push_back(pii(A[i],i));
}
for(int i=0;i<Q;i++){
vec.push_back(pii(V[i],X[i]));
}
sort(vec.begin(),vec.end());
vec.erase(unique(vec.begin(),vec.end()),vec.end());
int tam = vec.size();
auto Pos = [&](int id){
return (lower_bound(vec.begin(),vec.end(),pii(A[id],id)) - vec.begin()) + 1;
};
for(int i=0;i<n;i++){
int pos = Pos(i);
update(1,1,tam,pos,pos,i);
update(1,1,tam,pos+1,tam,-1);
}
for (int j=0;j<Q;j++) {
int pos = Pos(X[j]);
update(1,1,tam,pos,pos,-X[j]);
update(1,1,tam,pos+1,tam,+1);
A[X[j]] = V[j];
pos = Pos(X[j]);
update(1,1,tam,pos,pos,+X[j]);
update(1,1,tam,pos+1,tam,-1);
answer[j] = query(1,1,tam,1,tam);
}
return answer;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
6 ms |
468 KB |
Output is correct |
4 |
Correct |
11 ms |
496 KB |
Output is correct |
5 |
Correct |
7 ms |
496 KB |
Output is correct |
6 |
Correct |
4 ms |
468 KB |
Output is correct |
7 |
Correct |
5 ms |
468 KB |
Output is correct |
8 |
Correct |
5 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
468 KB |
Output is correct |
10 |
Correct |
5 ms |
500 KB |
Output is correct |
11 |
Correct |
5 ms |
468 KB |
Output is correct |
12 |
Correct |
6 ms |
468 KB |
Output is correct |
13 |
Correct |
6 ms |
468 KB |
Output is correct |
14 |
Correct |
6 ms |
468 KB |
Output is correct |
15 |
Correct |
6 ms |
468 KB |
Output is correct |
16 |
Correct |
4 ms |
468 KB |
Output is correct |
17 |
Correct |
4 ms |
468 KB |
Output is correct |
18 |
Correct |
5 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
6 ms |
468 KB |
Output is correct |
4 |
Correct |
11 ms |
496 KB |
Output is correct |
5 |
Correct |
7 ms |
496 KB |
Output is correct |
6 |
Correct |
4 ms |
468 KB |
Output is correct |
7 |
Correct |
5 ms |
468 KB |
Output is correct |
8 |
Correct |
5 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
468 KB |
Output is correct |
10 |
Correct |
5 ms |
500 KB |
Output is correct |
11 |
Correct |
5 ms |
468 KB |
Output is correct |
12 |
Correct |
6 ms |
468 KB |
Output is correct |
13 |
Correct |
6 ms |
468 KB |
Output is correct |
14 |
Correct |
6 ms |
468 KB |
Output is correct |
15 |
Correct |
6 ms |
468 KB |
Output is correct |
16 |
Correct |
4 ms |
468 KB |
Output is correct |
17 |
Correct |
4 ms |
468 KB |
Output is correct |
18 |
Correct |
5 ms |
468 KB |
Output is correct |
19 |
Correct |
18 ms |
1000 KB |
Output is correct |
20 |
Correct |
22 ms |
980 KB |
Output is correct |
21 |
Correct |
19 ms |
980 KB |
Output is correct |
22 |
Correct |
21 ms |
980 KB |
Output is correct |
23 |
Correct |
19 ms |
980 KB |
Output is correct |
24 |
Correct |
20 ms |
980 KB |
Output is correct |
25 |
Correct |
26 ms |
980 KB |
Output is correct |
26 |
Correct |
19 ms |
1012 KB |
Output is correct |
27 |
Correct |
18 ms |
1016 KB |
Output is correct |
28 |
Correct |
18 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
1368 KB |
Output is correct |
2 |
Correct |
97 ms |
2748 KB |
Output is correct |
3 |
Correct |
174 ms |
4640 KB |
Output is correct |
4 |
Correct |
156 ms |
4552 KB |
Output is correct |
5 |
Correct |
166 ms |
4532 KB |
Output is correct |
6 |
Correct |
186 ms |
4528 KB |
Output is correct |
7 |
Correct |
169 ms |
4624 KB |
Output is correct |
8 |
Correct |
157 ms |
4640 KB |
Output is correct |
9 |
Correct |
154 ms |
4592 KB |
Output is correct |
10 |
Correct |
133 ms |
3580 KB |
Output is correct |
11 |
Correct |
164 ms |
3496 KB |
Output is correct |
12 |
Correct |
144 ms |
3568 KB |
Output is correct |
13 |
Correct |
138 ms |
3520 KB |
Output is correct |
14 |
Correct |
149 ms |
3612 KB |
Output is correct |
15 |
Correct |
140 ms |
3592 KB |
Output is correct |
16 |
Correct |
123 ms |
3568 KB |
Output is correct |
17 |
Correct |
123 ms |
3608 KB |
Output is correct |
18 |
Correct |
130 ms |
3556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
6 ms |
468 KB |
Output is correct |
4 |
Correct |
11 ms |
496 KB |
Output is correct |
5 |
Correct |
7 ms |
496 KB |
Output is correct |
6 |
Correct |
4 ms |
468 KB |
Output is correct |
7 |
Correct |
5 ms |
468 KB |
Output is correct |
8 |
Correct |
5 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
468 KB |
Output is correct |
10 |
Correct |
5 ms |
500 KB |
Output is correct |
11 |
Correct |
5 ms |
468 KB |
Output is correct |
12 |
Correct |
6 ms |
468 KB |
Output is correct |
13 |
Correct |
6 ms |
468 KB |
Output is correct |
14 |
Correct |
6 ms |
468 KB |
Output is correct |
15 |
Correct |
6 ms |
468 KB |
Output is correct |
16 |
Correct |
4 ms |
468 KB |
Output is correct |
17 |
Correct |
4 ms |
468 KB |
Output is correct |
18 |
Correct |
5 ms |
468 KB |
Output is correct |
19 |
Correct |
18 ms |
1000 KB |
Output is correct |
20 |
Correct |
22 ms |
980 KB |
Output is correct |
21 |
Correct |
19 ms |
980 KB |
Output is correct |
22 |
Correct |
21 ms |
980 KB |
Output is correct |
23 |
Correct |
19 ms |
980 KB |
Output is correct |
24 |
Correct |
20 ms |
980 KB |
Output is correct |
25 |
Correct |
26 ms |
980 KB |
Output is correct |
26 |
Correct |
19 ms |
1012 KB |
Output is correct |
27 |
Correct |
18 ms |
1016 KB |
Output is correct |
28 |
Correct |
18 ms |
980 KB |
Output is correct |
29 |
Correct |
29 ms |
1368 KB |
Output is correct |
30 |
Correct |
97 ms |
2748 KB |
Output is correct |
31 |
Correct |
174 ms |
4640 KB |
Output is correct |
32 |
Correct |
156 ms |
4552 KB |
Output is correct |
33 |
Correct |
166 ms |
4532 KB |
Output is correct |
34 |
Correct |
186 ms |
4528 KB |
Output is correct |
35 |
Correct |
169 ms |
4624 KB |
Output is correct |
36 |
Correct |
157 ms |
4640 KB |
Output is correct |
37 |
Correct |
154 ms |
4592 KB |
Output is correct |
38 |
Correct |
133 ms |
3580 KB |
Output is correct |
39 |
Correct |
164 ms |
3496 KB |
Output is correct |
40 |
Correct |
144 ms |
3568 KB |
Output is correct |
41 |
Correct |
138 ms |
3520 KB |
Output is correct |
42 |
Correct |
149 ms |
3612 KB |
Output is correct |
43 |
Correct |
140 ms |
3592 KB |
Output is correct |
44 |
Correct |
123 ms |
3568 KB |
Output is correct |
45 |
Correct |
123 ms |
3608 KB |
Output is correct |
46 |
Correct |
130 ms |
3556 KB |
Output is correct |
47 |
Correct |
644 ms |
14856 KB |
Output is correct |
48 |
Correct |
2107 ms |
48696 KB |
Output is correct |
49 |
Correct |
2311 ms |
51300 KB |
Output is correct |
50 |
Correct |
2341 ms |
51188 KB |
Output is correct |
51 |
Correct |
2244 ms |
51200 KB |
Output is correct |
52 |
Correct |
2175 ms |
51256 KB |
Output is correct |
53 |
Correct |
2144 ms |
51368 KB |
Output is correct |
54 |
Correct |
1955 ms |
51340 KB |
Output is correct |
55 |
Correct |
2099 ms |
51480 KB |
Output is correct |
56 |
Correct |
2011 ms |
51528 KB |
Output is correct |
57 |
Correct |
2017 ms |
51472 KB |
Output is correct |
58 |
Correct |
1954 ms |
51560 KB |
Output is correct |
59 |
Correct |
1857 ms |
50196 KB |
Output is correct |
60 |
Correct |
1799 ms |
50016 KB |
Output is correct |
61 |
Correct |
1936 ms |
50100 KB |
Output is correct |
62 |
Correct |
1851 ms |
49948 KB |
Output is correct |
63 |
Correct |
1859 ms |
49924 KB |
Output is correct |
64 |
Correct |
1877 ms |
50012 KB |
Output is correct |
65 |
Correct |
1739 ms |
49928 KB |
Output is correct |
66 |
Correct |
1731 ms |
49896 KB |
Output is correct |
67 |
Correct |
1736 ms |
49760 KB |
Output is correct |