#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(x) x.begin(),x.end()
#define PB push_back
using vi=vector<int>;
using pi=pair<int,int>;
const int inf=INT_MAX/2;
struct SegTree{
vi mx,lz;
int s;
SegTree(int n){
s=1;
while(s<n)s*=2;
mx.resize(s*2,0);
lz.resize(s*2,0);
}
void Propagate(int i){
mx[i]+=lz[i];
lz[i*2]+=lz[i];
lz[i*2+1]+=lz[i];
lz[i]=0;
}
int Get(int i){
return mx[i]+lz[i];
}
void Add(int b,int e,int v,int l,int r,int i){
if(e<=l||r<=b)return;
if(b<=l&&r<=e){
lz[i]+=v;
return;
}
Propagate(i);
Add(b,e,v,l,(l+r)/2,i*2);
Add(b,e,v,(l+r)/2,r,i*2+1);
mx[i]=max(Get(i*2),Get(i*2+1));
}
void Add(int b,int e,int v){
if(b<e)
Add(b,e,v,0,s,1);
}
int Get(){
return Get(1);
}
};
vector<int> countScans(vector<int> a,vector<int> x,vector<int> v){
int n=a.size(),q=x.size();
vector<pi> crd;
REP(i,n)crd.PB(pi(a[i],i));
REP(i,q)crd.PB(pi(v[i],x[i]));
sort(ALL(crd));
crd.erase(unique(ALL(crd)),crd.end());
int s=crd.size();
SegTree seg(s);
seg.Add(0,s,-inf);
const auto Ins=[&](int p,int r){
int i=lower_bound(ALL(crd),pi(p,r))-crd.begin();
seg.Add(i,i+1,inf+r);
seg.Add(i+1,s,-1);
};
const auto Ers=[&](int p,int r){
int i=lower_bound(ALL(crd),pi(p,r))-crd.begin();
seg.Add(i,i+1,-(inf+r));
seg.Add(i+1,s,1);
};
REP(i,n)
Ins(a[i],i);
vi res(q);
REP(i,q){
Ers(a[x[i]],x[i]);
Ins(v[i],x[i]);
a[x[i]]=v[i];
res[i]=seg.Get();
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
484 KB |
Output is correct |
3 |
Correct |
13 ms |
560 KB |
Output is correct |
4 |
Correct |
8 ms |
736 KB |
Output is correct |
5 |
Correct |
8 ms |
736 KB |
Output is correct |
6 |
Correct |
7 ms |
740 KB |
Output is correct |
7 |
Correct |
10 ms |
768 KB |
Output is correct |
8 |
Correct |
8 ms |
768 KB |
Output is correct |
9 |
Correct |
7 ms |
768 KB |
Output is correct |
10 |
Correct |
8 ms |
772 KB |
Output is correct |
11 |
Correct |
9 ms |
772 KB |
Output is correct |
12 |
Correct |
8 ms |
792 KB |
Output is correct |
13 |
Correct |
8 ms |
792 KB |
Output is correct |
14 |
Correct |
9 ms |
792 KB |
Output is correct |
15 |
Correct |
8 ms |
792 KB |
Output is correct |
16 |
Correct |
19 ms |
792 KB |
Output is correct |
17 |
Correct |
12 ms |
896 KB |
Output is correct |
18 |
Correct |
8 ms |
896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
484 KB |
Output is correct |
3 |
Correct |
13 ms |
560 KB |
Output is correct |
4 |
Correct |
8 ms |
736 KB |
Output is correct |
5 |
Correct |
8 ms |
736 KB |
Output is correct |
6 |
Correct |
7 ms |
740 KB |
Output is correct |
7 |
Correct |
10 ms |
768 KB |
Output is correct |
8 |
Correct |
8 ms |
768 KB |
Output is correct |
9 |
Correct |
7 ms |
768 KB |
Output is correct |
10 |
Correct |
8 ms |
772 KB |
Output is correct |
11 |
Correct |
9 ms |
772 KB |
Output is correct |
12 |
Correct |
8 ms |
792 KB |
Output is correct |
13 |
Correct |
8 ms |
792 KB |
Output is correct |
14 |
Correct |
9 ms |
792 KB |
Output is correct |
15 |
Correct |
8 ms |
792 KB |
Output is correct |
16 |
Correct |
19 ms |
792 KB |
Output is correct |
17 |
Correct |
12 ms |
896 KB |
Output is correct |
18 |
Correct |
8 ms |
896 KB |
Output is correct |
19 |
Correct |
32 ms |
1172 KB |
Output is correct |
20 |
Correct |
34 ms |
1172 KB |
Output is correct |
21 |
Correct |
33 ms |
1172 KB |
Output is correct |
22 |
Correct |
32 ms |
1172 KB |
Output is correct |
23 |
Correct |
45 ms |
1196 KB |
Output is correct |
24 |
Correct |
30 ms |
1196 KB |
Output is correct |
25 |
Correct |
86 ms |
1200 KB |
Output is correct |
26 |
Correct |
31 ms |
1200 KB |
Output is correct |
27 |
Correct |
30 ms |
1380 KB |
Output is correct |
28 |
Correct |
38 ms |
1380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
1704 KB |
Output is correct |
2 |
Correct |
148 ms |
2984 KB |
Output is correct |
3 |
Correct |
394 ms |
4896 KB |
Output is correct |
4 |
Correct |
368 ms |
4896 KB |
Output is correct |
5 |
Correct |
401 ms |
4980 KB |
Output is correct |
6 |
Correct |
287 ms |
4980 KB |
Output is correct |
7 |
Correct |
316 ms |
4980 KB |
Output is correct |
8 |
Correct |
327 ms |
4980 KB |
Output is correct |
9 |
Correct |
239 ms |
4980 KB |
Output is correct |
10 |
Correct |
236 ms |
4980 KB |
Output is correct |
11 |
Correct |
212 ms |
4980 KB |
Output is correct |
12 |
Correct |
256 ms |
4980 KB |
Output is correct |
13 |
Correct |
247 ms |
4980 KB |
Output is correct |
14 |
Correct |
186 ms |
4980 KB |
Output is correct |
15 |
Correct |
206 ms |
4980 KB |
Output is correct |
16 |
Correct |
177 ms |
4980 KB |
Output is correct |
17 |
Correct |
229 ms |
4980 KB |
Output is correct |
18 |
Correct |
213 ms |
4980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
484 KB |
Output is correct |
3 |
Correct |
13 ms |
560 KB |
Output is correct |
4 |
Correct |
8 ms |
736 KB |
Output is correct |
5 |
Correct |
8 ms |
736 KB |
Output is correct |
6 |
Correct |
7 ms |
740 KB |
Output is correct |
7 |
Correct |
10 ms |
768 KB |
Output is correct |
8 |
Correct |
8 ms |
768 KB |
Output is correct |
9 |
Correct |
7 ms |
768 KB |
Output is correct |
10 |
Correct |
8 ms |
772 KB |
Output is correct |
11 |
Correct |
9 ms |
772 KB |
Output is correct |
12 |
Correct |
8 ms |
792 KB |
Output is correct |
13 |
Correct |
8 ms |
792 KB |
Output is correct |
14 |
Correct |
9 ms |
792 KB |
Output is correct |
15 |
Correct |
8 ms |
792 KB |
Output is correct |
16 |
Correct |
19 ms |
792 KB |
Output is correct |
17 |
Correct |
12 ms |
896 KB |
Output is correct |
18 |
Correct |
8 ms |
896 KB |
Output is correct |
19 |
Correct |
32 ms |
1172 KB |
Output is correct |
20 |
Correct |
34 ms |
1172 KB |
Output is correct |
21 |
Correct |
33 ms |
1172 KB |
Output is correct |
22 |
Correct |
32 ms |
1172 KB |
Output is correct |
23 |
Correct |
45 ms |
1196 KB |
Output is correct |
24 |
Correct |
30 ms |
1196 KB |
Output is correct |
25 |
Correct |
86 ms |
1200 KB |
Output is correct |
26 |
Correct |
31 ms |
1200 KB |
Output is correct |
27 |
Correct |
30 ms |
1380 KB |
Output is correct |
28 |
Correct |
38 ms |
1380 KB |
Output is correct |
29 |
Correct |
42 ms |
1704 KB |
Output is correct |
30 |
Correct |
148 ms |
2984 KB |
Output is correct |
31 |
Correct |
394 ms |
4896 KB |
Output is correct |
32 |
Correct |
368 ms |
4896 KB |
Output is correct |
33 |
Correct |
401 ms |
4980 KB |
Output is correct |
34 |
Correct |
287 ms |
4980 KB |
Output is correct |
35 |
Correct |
316 ms |
4980 KB |
Output is correct |
36 |
Correct |
327 ms |
4980 KB |
Output is correct |
37 |
Correct |
239 ms |
4980 KB |
Output is correct |
38 |
Correct |
236 ms |
4980 KB |
Output is correct |
39 |
Correct |
212 ms |
4980 KB |
Output is correct |
40 |
Correct |
256 ms |
4980 KB |
Output is correct |
41 |
Correct |
247 ms |
4980 KB |
Output is correct |
42 |
Correct |
186 ms |
4980 KB |
Output is correct |
43 |
Correct |
206 ms |
4980 KB |
Output is correct |
44 |
Correct |
177 ms |
4980 KB |
Output is correct |
45 |
Correct |
229 ms |
4980 KB |
Output is correct |
46 |
Correct |
213 ms |
4980 KB |
Output is correct |
47 |
Correct |
1076 ms |
15172 KB |
Output is correct |
48 |
Correct |
4181 ms |
36948 KB |
Output is correct |
49 |
Correct |
4268 ms |
38624 KB |
Output is correct |
50 |
Correct |
4441 ms |
38716 KB |
Output is correct |
51 |
Correct |
4801 ms |
38716 KB |
Output is correct |
52 |
Correct |
4505 ms |
38728 KB |
Output is correct |
53 |
Correct |
4091 ms |
38728 KB |
Output is correct |
54 |
Correct |
3675 ms |
38728 KB |
Output is correct |
55 |
Correct |
4103 ms |
38728 KB |
Output is correct |
56 |
Correct |
4311 ms |
38728 KB |
Output is correct |
57 |
Correct |
3979 ms |
38728 KB |
Output is correct |
58 |
Correct |
3742 ms |
38728 KB |
Output is correct |
59 |
Correct |
3379 ms |
38728 KB |
Output is correct |
60 |
Correct |
3780 ms |
38728 KB |
Output is correct |
61 |
Correct |
3646 ms |
38728 KB |
Output is correct |
62 |
Correct |
3426 ms |
38728 KB |
Output is correct |
63 |
Correct |
3252 ms |
38728 KB |
Output is correct |
64 |
Correct |
3038 ms |
38728 KB |
Output is correct |
65 |
Correct |
3379 ms |
38728 KB |
Output is correct |
66 |
Correct |
3662 ms |
38728 KB |
Output is correct |
67 |
Correct |
3076 ms |
38728 KB |
Output is correct |