답안 #155987

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
155987 2019-10-02T13:48:53 Z giorgikob Arranging Shoes (IOI19_shoes) C++14
0 / 100
65 ms 47944 KB
#include "shoes.h"

int n,r,pos;

long long ans;

std::vector<int>locl[500001],locr[500001];
int indl[500001],indr[500001];

int tree[500001];

void upd(int node,int tl,int tr){
	
	if(tl==tr){
		tree[node] = 1;
		return;
	}
	
	int mid = (tl+tr)/2;
	
	if(pos<mid)
		upd(node*2,tl,mid);
	else
		upd(node*2+1,mid+1,tr);
	
	tree[node] = tree[node*2] + tree[node*2+1];
}

int get(int node,int tl,int tr){
	
	if(r<tl)return 0;
	
	if(tr<=r)return tree[node];
	
	int mid = (tr+tl)/2;
	
	int x = get(node*2,tl,mid);
	int y = get(node*2+1,mid+1,tr);
	
	return x+y;
}

long long count_swaps(std::vector<int> s) {
	
	n = s.size();
	
	for(int i=0;i<n;i++){
		if(s[i]<0){
			locl[-s[i]].push_back(i);
		} else {
			locr[s[i]].push_back(i);
		}
	}
	
	for(int i=0;i<n;i++){
		if(s[i]<0){
			int loc = locr[ s[i] ][ indr[ s[i] ] ];
			r = loc;
			ans += loc - i - get(1,0,n-1);
			indr[ s[i] ] ++;
			pos = loc;
			upd(1,0,n-1);
			
		} else {
			int loc = locl[ s[i] ][ indl[ s[i] ] ];
			r = loc;
			ans += loc - i + 1 - get(1,0,n-1);
			indl[ s[i] ] ++;
			pos = loc;
			upd(1,0,n-1);
		}
	}
	
	return ans;
}

Compilation message

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:57:39: warning: array subscript is below array bounds [-Warray-bounds]
    int loc = locr[ s[i] ][ indr[ s[i] ] ];
                            ~~~~~~~~~~~^
shoes.cpp:57:41: warning: array subscript is below array bounds [-Warray-bounds]
    int loc = locr[ s[i] ][ indr[ s[i] ] ];
                                         ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 54 ms 47864 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 54 ms 47864 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 54 ms 47864 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 65 ms 47944 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 54 ms 47864 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 54 ms 47864 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -