Submission #206435

# Submission time Handle Problem Language Result Execution time Memory
206435 2020-03-03T09:41:05 Z GioChkhaidze Bubble Sort 2 (JOI18_bubblesort2) C++14
38 / 100
25 ms 4072 KB
#include <bits/stdc++.h>
#include "bubblesort2.h"
#define Tree int h,int l,int r
#define Left (h<<1),l,(l+r)>>1
#define Right ((h<<1)|1),((l+r)>>1)+1,r
#define ll long long 
#define F first
#define S second
using namespace std;
const int N=5e5+5;
ll n,q,S,L,R,dl,idx,val,Xx,Yy,a[N],pos[N],x[N],G[4*N],inf=-1e18;
vector < int > answer;  
vector < pair < pair < ll , ll > , pair < bool , ll >  > > s;
typedef struct { ll x; ll add; } res;
res v[8*N];

inline void Shift(Tree) {
	if (!v[h].add) return ;
	v[(h<<1)].x+=v[h].add;
	v[((h<<1)|1)].x+=v[h].add;
	v[(h<<1)].add+=v[h].add;
	v[((h<<1)|1)].add+=v[h].add;
	v[h].add=0;
}

void Updlr(Tree) {
	if (R<l || r<L) return ;
	if (L<=l && r<=R) { v[h].add+=dl; v[h].x+=dl; return ; }
	Shift(h,l,r);
	Updlr(Left),Updlr(Right);
	v[h].x=max(v[(h<<1)].x,v[((h<<1)|1)].x);
}

void Upd(Tree) {
	if (r<idx || idx<l) return ;
	if (l==idx && r==idx) { v[h].x=val; return ; }
	Shift(h,l,r);
	Upd(Left),Upd(Right);
	v[h].x=max(v[(h<<1)].x,v[((h<<1)|1)].x);
}

void Up(int x,ll dl) { while (x<=S) { G[x]+=dl; x+=(x & -x); } }
ll Ge(int x) { ll Res=0; while (x>0) { Res+=G[x]; x-=(x & -x); } return Res; }

std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
	n=A.size(),q=X.size();
	
	for (int i=1; i<=n; i++) 
		a[i]=A[i-1],s.push_back({{a[i],n-i},{1,i}});
	for (int i=1; i<=q; i++) 
		pos[i]=X[i-1]+1,x[i]=V[i-1],s.push_back({{x[i],n-pos[i]},{0,i}});
	
	sort(s.begin(),s.end()),S=s.size();
	
	for (int i=0; i<S; i++) 
		if (s[i].S.F) a[s[i].S.S]=i+1;
			else x[s[i].S.S]=i+1;
		
	for (int i=1; i<=n; i++) Up(a[i],1);
	for (int i=1; i<=4*S; i++) v[i].x=inf;
	for (int i=1; i<=n; i++) 
		idx=a[i],val=i-Ge(a[i]),Upd(1,1,S);

	for (int i=1; i<=q; i++) {	
		Xx=a[pos[i]],Yy=x[i];
		Up(a[pos[i]],-1),Up(x[i],1);
 	
 		if (Xx<=Yy) dl=1; else dl=-1;
 	
 		idx=Xx,val=inf,Upd(1,1,S);
		L=min(Xx,Yy)+1,R=max(Xx,Yy)-1;
		if (L<=R) Updlr(1,1,S);	
		idx=Yy,val=pos[i]-Ge(x[i]),Upd(1,1,S);

		a[pos[i]]=x[i];
		answer.push_back(max(v[1].x,0LL));
	}

	return answer;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 6 ms 632 KB Output is correct
3 Correct 9 ms 1016 KB Output is correct
4 Correct 9 ms 1016 KB Output is correct
5 Correct 8 ms 1016 KB Output is correct
6 Correct 8 ms 1016 KB Output is correct
7 Correct 8 ms 1016 KB Output is correct
8 Correct 9 ms 1016 KB Output is correct
9 Correct 9 ms 1020 KB Output is correct
10 Correct 9 ms 1016 KB Output is correct
11 Correct 9 ms 1020 KB Output is correct
12 Correct 8 ms 1016 KB Output is correct
13 Correct 9 ms 1016 KB Output is correct
14 Correct 9 ms 1016 KB Output is correct
15 Correct 9 ms 1016 KB Output is correct
16 Correct 9 ms 1016 KB Output is correct
17 Correct 8 ms 1016 KB Output is correct
18 Correct 8 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 6 ms 632 KB Output is correct
3 Correct 9 ms 1016 KB Output is correct
4 Correct 9 ms 1016 KB Output is correct
5 Correct 8 ms 1016 KB Output is correct
6 Correct 8 ms 1016 KB Output is correct
7 Correct 8 ms 1016 KB Output is correct
8 Correct 9 ms 1016 KB Output is correct
9 Correct 9 ms 1020 KB Output is correct
10 Correct 9 ms 1016 KB Output is correct
11 Correct 9 ms 1020 KB Output is correct
12 Correct 8 ms 1016 KB Output is correct
13 Correct 9 ms 1016 KB Output is correct
14 Correct 9 ms 1016 KB Output is correct
15 Correct 9 ms 1016 KB Output is correct
16 Correct 9 ms 1016 KB Output is correct
17 Correct 8 ms 1016 KB Output is correct
18 Correct 8 ms 1016 KB Output is correct
19 Correct 20 ms 2416 KB Output is correct
20 Correct 21 ms 2672 KB Output is correct
21 Correct 21 ms 2676 KB Output is correct
22 Correct 22 ms 2668 KB Output is correct
23 Correct 21 ms 2668 KB Output is correct
24 Correct 22 ms 2672 KB Output is correct
25 Correct 23 ms 2668 KB Output is correct
26 Correct 21 ms 2672 KB Output is correct
27 Correct 20 ms 2672 KB Output is correct
28 Correct 21 ms 2676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 4072 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 6 ms 632 KB Output is correct
3 Correct 9 ms 1016 KB Output is correct
4 Correct 9 ms 1016 KB Output is correct
5 Correct 8 ms 1016 KB Output is correct
6 Correct 8 ms 1016 KB Output is correct
7 Correct 8 ms 1016 KB Output is correct
8 Correct 9 ms 1016 KB Output is correct
9 Correct 9 ms 1020 KB Output is correct
10 Correct 9 ms 1016 KB Output is correct
11 Correct 9 ms 1020 KB Output is correct
12 Correct 8 ms 1016 KB Output is correct
13 Correct 9 ms 1016 KB Output is correct
14 Correct 9 ms 1016 KB Output is correct
15 Correct 9 ms 1016 KB Output is correct
16 Correct 9 ms 1016 KB Output is correct
17 Correct 8 ms 1016 KB Output is correct
18 Correct 8 ms 1016 KB Output is correct
19 Correct 20 ms 2416 KB Output is correct
20 Correct 21 ms 2672 KB Output is correct
21 Correct 21 ms 2676 KB Output is correct
22 Correct 22 ms 2668 KB Output is correct
23 Correct 21 ms 2668 KB Output is correct
24 Correct 22 ms 2672 KB Output is correct
25 Correct 23 ms 2668 KB Output is correct
26 Correct 21 ms 2672 KB Output is correct
27 Correct 20 ms 2672 KB Output is correct
28 Correct 21 ms 2676 KB Output is correct
29 Incorrect 25 ms 4072 KB Output isn't correct
30 Halted 0 ms 0 KB -