Submission #157517

# Submission time Handle Problem Language Result Execution time Memory
157517 2019-10-12T06:56:08 Z tevdore Arranging Shoes (IOI19_shoes) C++14
0 / 100
275 ms 269640 KB
#include<bits/stdc++.h>
#define mid (L+R)/2
using namespace std;
int n,i,ans,k;
int x[200001],sg[200001];
queue<int>q1[200001];
queue<int>q2[200001];
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){
    for(i=0;i<s.size();i++){
        upd(1,1,s.size(),i+1,1);
    }
    for(i=0;i<s.size();i++){
		if(s[i] < 0){
		    k=-(s[i]);
			if(q2[k].size() == 0){
				q1[k].push(i+1);
				continue;
			}
			ans+=get(1,1,s.size(),q2[k].front()+1,i+1)-1;
			upd(1,1,s.size(),q2[k].front()+1,2);
			upd(1,1,s.size(),i+1,0);
			q2[k].pop();
		}
		if(s[i] > 0){
		    k=s[i];
			if(q1[k].size() == 0){
				q2[k].push(i+1);
				continue;
			}
			ans+=get(1,1,s.size(),q1[k].front()+1,i+1)-2;
			upd(1,1,s.size(),q1[k].front()+1,2);
			upd(1,1,s.size(),i+1,0);
			q1[k].pop();
		}
	}
	return ans;
}

Compilation message

shoes.cpp: In function 'int count_swaps(std::vector<int>)':
shoes.cpp:23:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<s.size();i++){
             ~^~~~~~~~~
shoes.cpp:26: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 Incorrect 275 ms 269560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 275 ms 269560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 275 ms 269560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 275 ms 269640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 275 ms 269560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 275 ms 269560 KB Output isn't correct
2 Halted 0 ms 0 KB -