Submission #255591

# Submission time Handle Problem Language Result Execution time Memory
255591 2020-08-01T11:53:07 Z kshitij_sodani Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
2009 ms 62724 KB
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second

 
#include "bubblesort2.h"
int ind[1000001];
int tree[4000001];
int lazy[4000001];
int tree2[1000001];
void u(int i,int j){
	while(i<1000001){
		tree2[i]+=j;
		i+=(i&-i);
	}
}
int s(int i){
	int su=0;
	while(i>0){
		su+=tree2[i];
		i-=(i&-i);
	}
	return su;
}
void push(int no,int l,int r){
	tree[no]+=lazy[no];
	if(l<r){
		lazy[no*2+1]+=lazy[no];
		lazy[no*2+2]+=lazy[no];
	}
	lazy[no]=0;

}
void update(int no,int l,int r,int aa,int bb,int val){
	push(no,l,r);
	if(r<aa or l>bb){
		return;
	}
	if(aa<=l and r<=bb){
		tree[no]+=val;
		if(l<r){
			lazy[no*2+1]+=val;
			lazy[no*2+2]+=val;
		}
	}
	else{
		int mid=(l+r)/2;
		update(no*2+1,l,mid,aa,bb,val);
		update(no*2+2,mid+1,r,aa,bb,val);
		tree[no]=max(tree[no*2+1],tree[no*2+2]);
	}
}
void update2(int no,int l,int r,int i,int val){
	push(no,l,r);
	if(l==r){
		tree[no]=val;
	}
	else{
		int mid=(l+r)/2;
		push(no*2+1,l,mid);
		push(no*2+2,mid+1,r);
		if(i<=mid){
			update2(no*2+1,l,mid,i,val);
		}
		else{
			update2(no*2+2,mid+1,r,i,val);
		}
		tree[no]=max(tree[no*2+1],tree[no*2+2]);
	}
}

int val[500001];
std::vector<int> countScans(std::vector<int> it,std::vector<int> X,std::vector<int> V){
	int q=X.size();
	int n=it.size();
	vector<pair<pair<int,int>,int>> cur;

	for(int i=0;i<n;i++){
		cur.pb({{it[i],i},i});
	}
	for(int i=0;i<q;i++){
		cur.pb({{V[i],X[i]},i+n});
	}
	sort(cur.begin(),cur.end());
	for(int i=0;i<n+q;i++){
		ind[cur[i].b]=i;
	}
	for(int i=0;i<4*(n+q);i++){
		tree[i]=-1e9;
	}
	vector<int> ans;
	for(int i=0;i<n;i++){
		u(ind[i]+1,1);
	}
	for(int i=0;i<n;i++){
		val[i]=ind[i];
		update2(0,0,n+q-1,ind[i],i-s(ind[i]));
	}
	for(int i=0;i<q;i++){
		u(val[X[i]]+1,-1);
		u(ind[i+n]+1,1);
		update2(0,0,n+q-1,ind[i+n],X[i]-s(ind[i+n]));
		update2(0,0,n+q-1,val[X[i]],-1e9);

		if(ind[i+n]<n+q-1){
			update(0,0,n+q-1,ind[i+n]+1,n+q-1,-1);
		}
		if(val[X[i]]<n+q-1){
			update(0,0,n+q-1,val[X[i]]+1,n+q-1,1);
		}

		val[X[i]]=ind[i+n];
		ans.pb(tree[0]);
	}
	/*for(auto j:ans){
		cout<<j<<",";
	}
	cout<<endl;*/
	return ans;
}
 
//#define endl '\n'
 
/*int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int nn,qq;
	cin>>nn>>qq;
	int pp;
	vector<int> ac;
	vector<int> bc;
	vector<int> dc;
 
	for(int i=0;i<nn;i++){
		cin>>pp;
		ac.pb(pp);
	}
	for(int i=0;i<qq;i++){
		cin>>pp;
		bc.pb(pp);
		cin>>pp;
		dc.pb(pp);
	}
	countScans(ac,bc,dc);
 
	return 0;
}*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 5 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 4 ms 768 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 4 ms 768 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 5 ms 768 KB Output is correct
11 Correct 4 ms 768 KB Output is correct
12 Correct 4 ms 768 KB Output is correct
13 Correct 4 ms 768 KB Output is correct
14 Correct 4 ms 768 KB Output is correct
15 Correct 4 ms 768 KB Output is correct
16 Correct 4 ms 768 KB Output is correct
17 Correct 4 ms 768 KB Output is correct
18 Correct 4 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 5 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 4 ms 768 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 4 ms 768 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 5 ms 768 KB Output is correct
11 Correct 4 ms 768 KB Output is correct
12 Correct 4 ms 768 KB Output is correct
13 Correct 4 ms 768 KB Output is correct
14 Correct 4 ms 768 KB Output is correct
15 Correct 4 ms 768 KB Output is correct
16 Correct 4 ms 768 KB Output is correct
17 Correct 4 ms 768 KB Output is correct
18 Correct 4 ms 768 KB Output is correct
19 Correct 16 ms 1472 KB Output is correct
20 Correct 18 ms 1600 KB Output is correct
21 Correct 18 ms 1600 KB Output is correct
22 Correct 27 ms 1600 KB Output is correct
23 Correct 26 ms 1600 KB Output is correct
24 Correct 27 ms 1600 KB Output is correct
25 Correct 19 ms 1600 KB Output is correct
26 Correct 17 ms 1600 KB Output is correct
27 Correct 18 ms 1600 KB Output is correct
28 Correct 25 ms 1600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 2172 KB Output is correct
2 Correct 64 ms 4172 KB Output is correct
3 Correct 115 ms 7276 KB Output is correct
4 Correct 122 ms 7276 KB Output is correct
5 Correct 117 ms 7404 KB Output is correct
6 Correct 122 ms 7404 KB Output is correct
7 Correct 112 ms 7404 KB Output is correct
8 Correct 118 ms 7404 KB Output is correct
9 Correct 119 ms 7276 KB Output is correct
10 Correct 109 ms 7404 KB Output is correct
11 Correct 118 ms 7404 KB Output is correct
12 Correct 113 ms 7416 KB Output is correct
13 Correct 120 ms 7404 KB Output is correct
14 Correct 117 ms 7528 KB Output is correct
15 Correct 110 ms 7404 KB Output is correct
16 Correct 111 ms 7404 KB Output is correct
17 Correct 108 ms 7404 KB Output is correct
18 Correct 110 ms 7404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 5 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 4 ms 768 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 4 ms 768 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 5 ms 768 KB Output is correct
11 Correct 4 ms 768 KB Output is correct
12 Correct 4 ms 768 KB Output is correct
13 Correct 4 ms 768 KB Output is correct
14 Correct 4 ms 768 KB Output is correct
15 Correct 4 ms 768 KB Output is correct
16 Correct 4 ms 768 KB Output is correct
17 Correct 4 ms 768 KB Output is correct
18 Correct 4 ms 768 KB Output is correct
19 Correct 16 ms 1472 KB Output is correct
20 Correct 18 ms 1600 KB Output is correct
21 Correct 18 ms 1600 KB Output is correct
22 Correct 27 ms 1600 KB Output is correct
23 Correct 26 ms 1600 KB Output is correct
24 Correct 27 ms 1600 KB Output is correct
25 Correct 19 ms 1600 KB Output is correct
26 Correct 17 ms 1600 KB Output is correct
27 Correct 18 ms 1600 KB Output is correct
28 Correct 25 ms 1600 KB Output is correct
29 Correct 18 ms 2172 KB Output is correct
30 Correct 64 ms 4172 KB Output is correct
31 Correct 115 ms 7276 KB Output is correct
32 Correct 122 ms 7276 KB Output is correct
33 Correct 117 ms 7404 KB Output is correct
34 Correct 122 ms 7404 KB Output is correct
35 Correct 112 ms 7404 KB Output is correct
36 Correct 118 ms 7404 KB Output is correct
37 Correct 119 ms 7276 KB Output is correct
38 Correct 109 ms 7404 KB Output is correct
39 Correct 118 ms 7404 KB Output is correct
40 Correct 113 ms 7416 KB Output is correct
41 Correct 120 ms 7404 KB Output is correct
42 Correct 117 ms 7528 KB Output is correct
43 Correct 110 ms 7404 KB Output is correct
44 Correct 111 ms 7404 KB Output is correct
45 Correct 108 ms 7404 KB Output is correct
46 Correct 110 ms 7404 KB Output is correct
47 Correct 525 ms 21776 KB Output is correct
48 Correct 1788 ms 58404 KB Output is correct
49 Correct 1832 ms 62716 KB Output is correct
50 Correct 1946 ms 62704 KB Output is correct
51 Correct 1918 ms 62724 KB Output is correct
52 Correct 1828 ms 62664 KB Output is correct
53 Correct 1905 ms 62560 KB Output is correct
54 Correct 2009 ms 62632 KB Output is correct
55 Correct 1952 ms 62612 KB Output is correct
56 Correct 1741 ms 62460 KB Output is correct
57 Correct 1815 ms 62508 KB Output is correct
58 Correct 1777 ms 62456 KB Output is correct
59 Correct 1668 ms 62444 KB Output is correct
60 Correct 1682 ms 62412 KB Output is correct
61 Correct 1787 ms 62284 KB Output is correct
62 Correct 1707 ms 62092 KB Output is correct
63 Correct 1593 ms 62156 KB Output is correct
64 Correct 1621 ms 62156 KB Output is correct
65 Correct 1524 ms 62292 KB Output is correct
66 Correct 1561 ms 62280 KB Output is correct
67 Correct 1516 ms 62028 KB Output is correct