Submission #385636

# Submission time Handle Problem Language Result Execution time Memory
385636 2021-04-04T16:23:33 Z keta_tsimakuridze Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
7505 ms 130216 KB
#include<bits/stdc++.h>
#include "bubblesort2.h"
#define f first
#define s second
using namespace std;
const int N=1e6+5,mod=1e9+7;
int t,lazy[4*N],ind[N],b[N],a[N],n,q;
map<pair<int,int>,int>idx;
string s;
vector<pair<int,int> >p;
pair<int,int> tree[4*N];
vector<int>ans;
void update(int u,int start,int end,int l,int r,int type,int val){
	if(lazy[u]){
		tree[u].s+=lazy[u];
		if(l!=r){
			lazy[2*u]+=lazy[u];
			lazy[2*u+1]+=lazy[u];
		}
		lazy[u]=0;
	}
	if(l>end || r<start) return;
	if(start<=l && r<=end){
		if(type==1) {
			tree[u].f+=val;
			return;
		}
		tree[u].s+=val;
		lazy[u]=val;
		if(l!=r){
			lazy[2*u]+=lazy[u];
			lazy[2*u+1]+=lazy[u];
		}
		lazy[u]=0;
		return;
	}
	int mid=(l+r)/2;
	update(2*u,start,end,l,mid,type,val);
	update(2*u+1,start,end,mid+1,r,type,val);
	if(tree[2*u].f && tree[2*u+1].f) tree[u]={1,max(tree[2*u+1].s,tree[2*u].s)};
	else if(tree[2*u].f) tree[u]={1,tree[2*u].s};
	else if(tree[2*u+1].f) tree[u]={1,tree[2*u+1].s};
	else tree[u]={0,0};
}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V){
	// t=1;
	int n=A.size();
	int q=X.size();

	for(int i=1;i<=n;i++){
		a[i]=A[i-1]; 
		p.push_back({a[i],i});
	}
	for(int i=1;i<=q;i++){
		ind[i]=X[i-1];
		b[i]=V[i-1];
		ind[i]++;
		p.push_back({b[i],ind[i]});
	}
	sort(p.begin(),p.end());
	int cur=0;
	for(int i=0;i<p.size();i++){
		if(!i || p[i].f!=p[i-1].f || p[i].s!=p[i-1].s) cur++;
		idx[{p[i].f,p[i].s}] = cur;
	}
	for(int i=1;i<=n;i++){
		update(1,idx[{a[i],i}],idx[{a[i],i}],1,cur,1,1);
		update(1,idx[{a[i],i}],idx[{a[i],i}],1,cur,0,i-1);  
		update(1,idx[{a[i],i}]+1,cur,1,cur,0,-1);	
	}
	for(int i=1;i<=q;i++){
		if(a[ind[i]]<b[i]) {
			update(1,idx[{a[ind[i]],ind[i]}]+1,idx[{b[i],ind[i]}],1,cur,0,1);
			
		} 
		else {
			update(1,idx[{b[i],ind[i]}]+1,idx[{a[ind[i]],ind[i]}],1,cur,0,-1);
		}
		update(1,idx[{a[ind[i]],ind[i]}],idx[{a[ind[i]],ind[i]}],1,cur,1,-1);
		update(1,idx[{a[ind[i]],ind[i]}],idx[{a[ind[i]],ind[i]}],1,cur,0,-ind[i]+1);
		update(1,idx[{b[i],ind[i]}],idx[{b[i],ind[i]}],1,cur,0,ind[i]-1);
		update(1,idx[{b[i],ind[i]}],idx[{b[i],ind[i]}],1,cur,1,+1);
		a[ind[i]]=b[i];			
		ans.push_back(tree[1].s);
	}
	return ans;
}/*
main(){
	cin>>n>>q;
	vector<int>V,X,A;
	for(int i=0;i<n;i++){
		int b;
		cin>>b;
		A.push_back(b);
	}
	for(int i=0;i<q;i++){
		int b;
		cin>>b;
		X.push_back(b);
	}
	for(int i=0;i<q;i++){
		int b;
		cin>>b;
		V.push_back(b);
	}
	vector<int> ans(q);
	ans=countScans(A,X,V);
	for(int i=0;i<q;i++){
		cout<<ans[i]<<" ";
	}
}
*/

Compilation message

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:62:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |  for(int i=0;i<p.size();i++){
      |              ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 492 KB Output is correct
2 Correct 5 ms 620 KB Output is correct
3 Correct 11 ms 876 KB Output is correct
4 Correct 11 ms 876 KB Output is correct
5 Correct 11 ms 876 KB Output is correct
6 Correct 11 ms 868 KB Output is correct
7 Correct 11 ms 876 KB Output is correct
8 Correct 11 ms 876 KB Output is correct
9 Correct 12 ms 876 KB Output is correct
10 Correct 11 ms 748 KB Output is correct
11 Correct 11 ms 748 KB Output is correct
12 Correct 11 ms 748 KB Output is correct
13 Correct 10 ms 748 KB Output is correct
14 Correct 12 ms 876 KB Output is correct
15 Correct 10 ms 748 KB Output is correct
16 Correct 11 ms 876 KB Output is correct
17 Correct 10 ms 748 KB Output is correct
18 Correct 10 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 492 KB Output is correct
2 Correct 5 ms 620 KB Output is correct
3 Correct 11 ms 876 KB Output is correct
4 Correct 11 ms 876 KB Output is correct
5 Correct 11 ms 876 KB Output is correct
6 Correct 11 ms 868 KB Output is correct
7 Correct 11 ms 876 KB Output is correct
8 Correct 11 ms 876 KB Output is correct
9 Correct 12 ms 876 KB Output is correct
10 Correct 11 ms 748 KB Output is correct
11 Correct 11 ms 748 KB Output is correct
12 Correct 11 ms 748 KB Output is correct
13 Correct 10 ms 748 KB Output is correct
14 Correct 12 ms 876 KB Output is correct
15 Correct 10 ms 748 KB Output is correct
16 Correct 11 ms 876 KB Output is correct
17 Correct 10 ms 748 KB Output is correct
18 Correct 10 ms 748 KB Output is correct
19 Correct 45 ms 2028 KB Output is correct
20 Correct 50 ms 2284 KB Output is correct
21 Correct 59 ms 2284 KB Output is correct
22 Correct 58 ms 2284 KB Output is correct
23 Correct 47 ms 2156 KB Output is correct
24 Correct 53 ms 2156 KB Output is correct
25 Correct 45 ms 2028 KB Output is correct
26 Correct 45 ms 2156 KB Output is correct
27 Correct 45 ms 2028 KB Output is correct
28 Correct 43 ms 2028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 3560 KB Output is correct
2 Correct 243 ms 7652 KB Output is correct
3 Correct 455 ms 12640 KB Output is correct
4 Correct 462 ms 12856 KB Output is correct
5 Correct 467 ms 12612 KB Output is correct
6 Correct 444 ms 12640 KB Output is correct
7 Correct 429 ms 12640 KB Output is correct
8 Correct 491 ms 12640 KB Output is correct
9 Correct 433 ms 12512 KB Output is correct
10 Correct 301 ms 8288 KB Output is correct
11 Correct 341 ms 8288 KB Output is correct
12 Correct 308 ms 8416 KB Output is correct
13 Correct 315 ms 8288 KB Output is correct
14 Correct 318 ms 8416 KB Output is correct
15 Correct 300 ms 8416 KB Output is correct
16 Correct 303 ms 8544 KB Output is correct
17 Correct 280 ms 8416 KB Output is correct
18 Correct 278 ms 8288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 492 KB Output is correct
2 Correct 5 ms 620 KB Output is correct
3 Correct 11 ms 876 KB Output is correct
4 Correct 11 ms 876 KB Output is correct
5 Correct 11 ms 876 KB Output is correct
6 Correct 11 ms 868 KB Output is correct
7 Correct 11 ms 876 KB Output is correct
8 Correct 11 ms 876 KB Output is correct
9 Correct 12 ms 876 KB Output is correct
10 Correct 11 ms 748 KB Output is correct
11 Correct 11 ms 748 KB Output is correct
12 Correct 11 ms 748 KB Output is correct
13 Correct 10 ms 748 KB Output is correct
14 Correct 12 ms 876 KB Output is correct
15 Correct 10 ms 748 KB Output is correct
16 Correct 11 ms 876 KB Output is correct
17 Correct 10 ms 748 KB Output is correct
18 Correct 10 ms 748 KB Output is correct
19 Correct 45 ms 2028 KB Output is correct
20 Correct 50 ms 2284 KB Output is correct
21 Correct 59 ms 2284 KB Output is correct
22 Correct 58 ms 2284 KB Output is correct
23 Correct 47 ms 2156 KB Output is correct
24 Correct 53 ms 2156 KB Output is correct
25 Correct 45 ms 2028 KB Output is correct
26 Correct 45 ms 2156 KB Output is correct
27 Correct 45 ms 2028 KB Output is correct
28 Correct 43 ms 2028 KB Output is correct
29 Correct 71 ms 3560 KB Output is correct
30 Correct 243 ms 7652 KB Output is correct
31 Correct 455 ms 12640 KB Output is correct
32 Correct 462 ms 12856 KB Output is correct
33 Correct 467 ms 12612 KB Output is correct
34 Correct 444 ms 12640 KB Output is correct
35 Correct 429 ms 12640 KB Output is correct
36 Correct 491 ms 12640 KB Output is correct
37 Correct 433 ms 12512 KB Output is correct
38 Correct 301 ms 8288 KB Output is correct
39 Correct 341 ms 8288 KB Output is correct
40 Correct 308 ms 8416 KB Output is correct
41 Correct 315 ms 8288 KB Output is correct
42 Correct 318 ms 8416 KB Output is correct
43 Correct 300 ms 8416 KB Output is correct
44 Correct 303 ms 8544 KB Output is correct
45 Correct 280 ms 8416 KB Output is correct
46 Correct 278 ms 8288 KB Output is correct
47 Correct 1763 ms 40348 KB Output is correct
48 Correct 6597 ms 109480 KB Output is correct
49 Correct 7157 ms 129996 KB Output is correct
50 Correct 7505 ms 130032 KB Output is correct
51 Correct 7274 ms 130060 KB Output is correct
52 Correct 7165 ms 130020 KB Output is correct
53 Correct 7279 ms 130196 KB Output is correct
54 Correct 6457 ms 130212 KB Output is correct
55 Correct 7048 ms 130216 KB Output is correct
56 Correct 6536 ms 130152 KB Output is correct
57 Correct 7111 ms 130132 KB Output is correct
58 Correct 6783 ms 130120 KB Output is correct
59 Correct 6136 ms 120968 KB Output is correct
60 Correct 5940 ms 120992 KB Output is correct
61 Correct 5966 ms 121080 KB Output is correct
62 Correct 5717 ms 117124 KB Output is correct
63 Correct 5572 ms 117072 KB Output is correct
64 Correct 5580 ms 117056 KB Output is correct
65 Correct 5207 ms 112928 KB Output is correct
66 Correct 5235 ms 113156 KB Output is correct
67 Correct 5316 ms 112960 KB Output is correct