답안 #155977

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
155977 2019-10-02T13:37:40 Z GioChkhaidze Arranging Shoes (IOI19_shoes) C++14
10 / 100
2 ms 380 KB
#include "shoes.h"
using namespace std;
const int N=100005;
int a[2*N],G[2*N],f1[2*N],f2[2*N];
 
void Upd(int x,int dl) {
	while (x<=2*N) {
		G[x]+=dl;
		x+=(x & -x);
	}
}
 
int Get(int x) {
	int res=0;
	while (0<x) {
		res+=G[x];
		x-=(x & -x);
	}
	return res;
}
 
long long count_swaps(std::vector<int> s) {
	long long ans=0;
  	int n=s.size();
	for (int i=0; i<n; i++) {
		a[i+1]=s[i];
		if (a[i+1]>0) f1[a[i+1]]=i+1;
		if (a[i+1]<0) f2[-a[i+1]]=i+1;
		Upd(i+1,1);
	}
	
	for (int i=1; i<=n/2; i++) {
		int l=1,r=n,mid,idx=-1;
		
		while (l<=r) {
			mid=(l+r)/2;
			if (1<=Get(mid)) { idx=mid; r=mid-1; } 
								   else l=mid+1;
		}
		
		if (a[idx]<0) {
			int x=-a[idx];
			ans+=Get(f1[x]-1)-1;
			Upd(idx,-1);
			Upd(f1[x],-1);
		}
			else {
			int x=a[idx];
			ans+=Get(f2[x]-1);
			Upd(idx,-1);
			Upd(f2[x],-1);
		}
	}
	
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 336 KB Output is correct
14 Incorrect 2 ms 376 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 336 KB Output is correct
14 Incorrect 2 ms 376 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 336 KB Output is correct
14 Incorrect 2 ms 376 KB Output isn't correct
15 Halted 0 ms 0 KB -