#include<bits/stdc++.h>
#include "bubblesort2.h"
using namespace std;
#define ll int
#define fr first
#define sc second
#define pb push_back
#define ARRS ((ll)(2e6+100))
#define MAX ((ll)(1e9+100))
ll wl,wr,wx,wi;
struct nodes{
nodes *L,*R;
int x;
nodes(){
L=R=NULL;
x=0;
}
void updt(){
x=0;
if(L)x+=L->x;
if(R)x+=R->x;
}
};
void updt(ll l,ll r,nodes *& x){
if(wi<l||r-1<wi)return;
if(!x)x=new nodes();
if(l==r-1){
x->x+=wx;
return;
}
updt(l,l+r>>1,x->L);
updt(l+r>>1,r,x->R);
x->updt();
}
ll quer(ll l,ll r,nodes *& x){
if(wr<l||r-1<wl)return 0;
if(!x)return 0;
if(wl<=l&&r-1<=wr)return x->x;
return quer(l,l+r>>1,x->L)
+quer(l+r>>1,r,x->R);
}
struct node{
node *L,*R;
int x,s;
node(){
L=R=NULL;
s=0;
x=-MAX;
}
void updt(){
x=-MAX;
if(L)x=max(x,L->x);
if(R)x=max(x,R->x);
}
void shep(ll y){
s+=y;
x+=y;
}
void shplit(){
if(!L)L=new node();
if(!R)R=new node();
L->shep(s);
R->shep(s);
s=0;
}
};
void updt(ll l,ll r,node *& x){
if(wr<l||r-1<wl)return;
if(!x)x=new node();
if(wl<=l&&r-1<=wr){
x->shep(wx);
return;
}
x->shplit();
updt(l,l+r>>1,x->L);
updt(l+r>>1,r,x->R);
x->updt();
}
void updt1(ll l,ll r,node *& x){
if(wr<l||r-1<wl)return;
if(!x)x=new node();
if(wl<=l&&r-1<=wr){
x->x=wx;
x->s=0;
return;
}
x->shplit();
updt1(l,l+r>>1,x->L);
updt1(l+r>>1,r,x->R);
x->updt();
}
map<ll, set<ll> > mp;
node *rt=NULL;
nodes *rts=NULL;
void up(ll x){
if(mp[x].size()){
wl=x+1; wr=MAX;
wx=-(*mp[x].begin())+quer(-MAX,MAX,rts);
wl=wr=x;
// cout<<wl<<" "<<wx<<" "<<x<<" "<<(-*mp[x].begin())<<endl;
updt1(-MAX,MAX,rt);
}
else {
wl=wr=x;
wx=-MAX;
updt1(-MAX,MAX,rt);
}
}
ll a[ARRS],n;
void quer(ll i,ll x){
mp[a[i]].erase(n-i-1);
mp[x].insert(n-i-1);
wi=a[i];
wx=-1;
updt(-MAX,MAX,rts);
wi=x;
wx=1;
updt(-MAX,MAX,rts);
up(x);
up(a[i]);
if(a[i]<=x){
wl=a[i]+1;
wr=x-1;
wx=1;
}
else {
wl=x+1;
wr=a[i]-1;
wx=-1;
}
updt(-MAX,MAX,rt);
a[i]=x;
}
vector<int> countScans(vector<int> A,vector<int> X,vector<int> V){
n=A.size();
ll q=X.size();
vector<int> PAS;
for(int i=0; i<n; i++){
a[i]=A[i];
wi=a[i];
wx=1;
updt(-MAX,MAX,rts);
}
for(int i=0; i<n; i++){
mp[a[i]].insert(n-i-1);
up(a[i]);
}
//cout<<" ----> "<<rt->x<<endl;
for(int i=0; i<q; i++){
ll k=X[i];
ll p=V[i];
quer(k,p);
PAS.pb(rt->x);
}
return PAS;
}
Compilation message
bubblesort2.cpp: In function 'void updt(int, int, nodes*&)':
bubblesort2.cpp:35:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
updt(l,l+r>>1,x->L);
~^~
bubblesort2.cpp:36:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
updt(l+r>>1,r,x->R);
~^~
bubblesort2.cpp: In function 'int quer(int, int, nodes*&)':
bubblesort2.cpp:44:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
return quer(l,l+r>>1,x->L)
~^~
bubblesort2.cpp:45:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
+quer(l+r>>1,r,x->R);
~^~
bubblesort2.cpp: In function 'void updt(int, int, node*&)':
bubblesort2.cpp:82:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
updt(l,l+r>>1,x->L);
~^~
bubblesort2.cpp:83:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
updt(l+r>>1,r,x->R);
~^~
bubblesort2.cpp: In function 'void updt1(int, int, node*&)':
bubblesort2.cpp:96:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
updt1(l,l+r>>1,x->L);
~^~
bubblesort2.cpp:97:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
updt1(l+r>>1,r,x->R);
~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
2424 KB |
Output is correct |
2 |
Correct |
14 ms |
3560 KB |
Output is correct |
3 |
Correct |
33 ms |
7604 KB |
Output is correct |
4 |
Correct |
38 ms |
7604 KB |
Output is correct |
5 |
Correct |
30 ms |
7604 KB |
Output is correct |
6 |
Correct |
33 ms |
7604 KB |
Output is correct |
7 |
Correct |
38 ms |
7604 KB |
Output is correct |
8 |
Correct |
32 ms |
7604 KB |
Output is correct |
9 |
Correct |
46 ms |
7604 KB |
Output is correct |
10 |
Correct |
29 ms |
7604 KB |
Output is correct |
11 |
Correct |
25 ms |
7604 KB |
Output is correct |
12 |
Correct |
34 ms |
7604 KB |
Output is correct |
13 |
Correct |
23 ms |
7604 KB |
Output is correct |
14 |
Correct |
23 ms |
7604 KB |
Output is correct |
15 |
Correct |
22 ms |
7604 KB |
Output is correct |
16 |
Correct |
21 ms |
7604 KB |
Output is correct |
17 |
Correct |
22 ms |
7604 KB |
Output is correct |
18 |
Correct |
22 ms |
7604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
2424 KB |
Output is correct |
2 |
Correct |
14 ms |
3560 KB |
Output is correct |
3 |
Correct |
33 ms |
7604 KB |
Output is correct |
4 |
Correct |
38 ms |
7604 KB |
Output is correct |
5 |
Correct |
30 ms |
7604 KB |
Output is correct |
6 |
Correct |
33 ms |
7604 KB |
Output is correct |
7 |
Correct |
38 ms |
7604 KB |
Output is correct |
8 |
Correct |
32 ms |
7604 KB |
Output is correct |
9 |
Correct |
46 ms |
7604 KB |
Output is correct |
10 |
Correct |
29 ms |
7604 KB |
Output is correct |
11 |
Correct |
25 ms |
7604 KB |
Output is correct |
12 |
Correct |
34 ms |
7604 KB |
Output is correct |
13 |
Correct |
23 ms |
7604 KB |
Output is correct |
14 |
Correct |
23 ms |
7604 KB |
Output is correct |
15 |
Correct |
22 ms |
7604 KB |
Output is correct |
16 |
Correct |
21 ms |
7604 KB |
Output is correct |
17 |
Correct |
22 ms |
7604 KB |
Output is correct |
18 |
Correct |
22 ms |
7604 KB |
Output is correct |
19 |
Correct |
159 ms |
23060 KB |
Output is correct |
20 |
Correct |
167 ms |
25976 KB |
Output is correct |
21 |
Correct |
124 ms |
25976 KB |
Output is correct |
22 |
Correct |
207 ms |
25976 KB |
Output is correct |
23 |
Correct |
126 ms |
25976 KB |
Output is correct |
24 |
Correct |
127 ms |
25976 KB |
Output is correct |
25 |
Correct |
117 ms |
25976 KB |
Output is correct |
26 |
Correct |
110 ms |
25976 KB |
Output is correct |
27 |
Correct |
101 ms |
25976 KB |
Output is correct |
28 |
Correct |
101 ms |
25976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
25976 KB |
Output is correct |
2 |
Correct |
207 ms |
25976 KB |
Output is correct |
3 |
Correct |
377 ms |
25976 KB |
Output is correct |
4 |
Correct |
337 ms |
25976 KB |
Output is correct |
5 |
Correct |
354 ms |
25976 KB |
Output is correct |
6 |
Correct |
301 ms |
25976 KB |
Output is correct |
7 |
Correct |
337 ms |
25976 KB |
Output is correct |
8 |
Correct |
292 ms |
25976 KB |
Output is correct |
9 |
Correct |
268 ms |
25976 KB |
Output is correct |
10 |
Correct |
283 ms |
25976 KB |
Output is correct |
11 |
Correct |
280 ms |
25976 KB |
Output is correct |
12 |
Correct |
265 ms |
25976 KB |
Output is correct |
13 |
Correct |
259 ms |
25976 KB |
Output is correct |
14 |
Correct |
261 ms |
25976 KB |
Output is correct |
15 |
Correct |
228 ms |
25976 KB |
Output is correct |
16 |
Correct |
238 ms |
25976 KB |
Output is correct |
17 |
Correct |
258 ms |
25976 KB |
Output is correct |
18 |
Correct |
205 ms |
25976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
2424 KB |
Output is correct |
2 |
Correct |
14 ms |
3560 KB |
Output is correct |
3 |
Correct |
33 ms |
7604 KB |
Output is correct |
4 |
Correct |
38 ms |
7604 KB |
Output is correct |
5 |
Correct |
30 ms |
7604 KB |
Output is correct |
6 |
Correct |
33 ms |
7604 KB |
Output is correct |
7 |
Correct |
38 ms |
7604 KB |
Output is correct |
8 |
Correct |
32 ms |
7604 KB |
Output is correct |
9 |
Correct |
46 ms |
7604 KB |
Output is correct |
10 |
Correct |
29 ms |
7604 KB |
Output is correct |
11 |
Correct |
25 ms |
7604 KB |
Output is correct |
12 |
Correct |
34 ms |
7604 KB |
Output is correct |
13 |
Correct |
23 ms |
7604 KB |
Output is correct |
14 |
Correct |
23 ms |
7604 KB |
Output is correct |
15 |
Correct |
22 ms |
7604 KB |
Output is correct |
16 |
Correct |
21 ms |
7604 KB |
Output is correct |
17 |
Correct |
22 ms |
7604 KB |
Output is correct |
18 |
Correct |
22 ms |
7604 KB |
Output is correct |
19 |
Correct |
159 ms |
23060 KB |
Output is correct |
20 |
Correct |
167 ms |
25976 KB |
Output is correct |
21 |
Correct |
124 ms |
25976 KB |
Output is correct |
22 |
Correct |
207 ms |
25976 KB |
Output is correct |
23 |
Correct |
126 ms |
25976 KB |
Output is correct |
24 |
Correct |
127 ms |
25976 KB |
Output is correct |
25 |
Correct |
117 ms |
25976 KB |
Output is correct |
26 |
Correct |
110 ms |
25976 KB |
Output is correct |
27 |
Correct |
101 ms |
25976 KB |
Output is correct |
28 |
Correct |
101 ms |
25976 KB |
Output is correct |
29 |
Correct |
62 ms |
25976 KB |
Output is correct |
30 |
Correct |
207 ms |
25976 KB |
Output is correct |
31 |
Correct |
377 ms |
25976 KB |
Output is correct |
32 |
Correct |
337 ms |
25976 KB |
Output is correct |
33 |
Correct |
354 ms |
25976 KB |
Output is correct |
34 |
Correct |
301 ms |
25976 KB |
Output is correct |
35 |
Correct |
337 ms |
25976 KB |
Output is correct |
36 |
Correct |
292 ms |
25976 KB |
Output is correct |
37 |
Correct |
268 ms |
25976 KB |
Output is correct |
38 |
Correct |
283 ms |
25976 KB |
Output is correct |
39 |
Correct |
280 ms |
25976 KB |
Output is correct |
40 |
Correct |
265 ms |
25976 KB |
Output is correct |
41 |
Correct |
259 ms |
25976 KB |
Output is correct |
42 |
Correct |
261 ms |
25976 KB |
Output is correct |
43 |
Correct |
228 ms |
25976 KB |
Output is correct |
44 |
Correct |
238 ms |
25976 KB |
Output is correct |
45 |
Correct |
258 ms |
25976 KB |
Output is correct |
46 |
Correct |
205 ms |
25976 KB |
Output is correct |
47 |
Correct |
3556 ms |
353404 KB |
Output is correct |
48 |
Execution timed out |
7142 ms |
525312 KB |
Time limit exceeded (wall clock) |
49 |
Halted |
0 ms |
0 KB |
- |