Submission #157524

# Submission time Handle Problem Language Result Execution time Memory
157524 2019-10-12T07:22:19 Z tevdore Arranging Shoes (IOI19_shoes) C++14
0 / 100
880 ms 1048580 KB
#include<bits/stdc++.h>
#define mid (L+R)/2
using namespace std;
int i,ans,k;
int f[300001],sg[2000001];
queue<int>q1[1000001];
queue<int>q2[1000001];
vector<int>s;
void upd(int u,int L,int R,int pos,int y){
	if(R < pos || L > pos)return;
	if(R == L){sg[u]=y;return;}
	else{
		upd(u*2,L,mid,pos,y);
		upd(u*2+1,mid+1,R,pos,y);
		sg[u]=sg[u*2]+sg[u*2+1];
	}
}
int get(int u,int L,int R,int a,int b){
	if(b < L || a > R)return 0;
	if(a <= L && b >= R)return sg[u];
	return(get(u*2,L,mid,a,b)+get(u*2+1,mid+1,R,a,b));
}
int count_swaps(std:: vector<int>s){
    int n=s.size();
    for(i=0;i<s.size();i++){
        f[i+1]=s[i];
    }
    for(i=1;i<=n;i++){
        upd(1,1,n,i,1);
    }
    for(i=1;i<=n;i++){
		if(f[i] < 0){
		    k=-(f[i]);
			if(q2[k].size() == 0){
				q1[k].push(i);
				continue;
			}
			ans+=get(1,1,n,q2[k].front(),i)-1;
			upd(1,1,n,q2[k].front(),2);
			upd(1,1,n,i,0);
			q2[k].pop();
		}
		if(f[i] > 0){
		    k=f[i];
			if(q1[k].size() == 0){
				q2[k].push(i);
				continue;
			}
			ans+=get(1,1,n,q1[k].front(),i)-2;
			upd(1,1,n,q1[k].front(),2);
			upd(1,1,n,i,0);
			q1[k].pop();
		}
	}
	return ans;
}

Compilation message

shoes.cpp: In function 'int count_swaps(std::vector<int>)':
shoes.cpp:25:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<s.size();i++){
             ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 880 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 880 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 880 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 872 ms 1048576 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 880 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 880 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -