Submission #385632

# Submission time Handle Problem Language Result Execution time Memory
385632 2021-04-04T16:21:43 Z keta_tsimakuridze Bubble Sort 2 (JOI18_bubblesort2) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#include "bubblesort2.h"
#define f first
#define int long long
#define s second
using namespace std;
const int N=2e5+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<long long int> countScans(std::vector<long long int>, std::vector<long long int>, std::vector<long long int>)':
bubblesort2.cpp:63:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |  for(int i=0;i<p.size();i++){
      |              ~^~~~~~~~~
/tmp/ccpywimf.o: In function `main':
grader.cpp:(.text.startup+0x123): undefined reference to `countScans(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status