답안 #155998

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
155998 2019-10-02T14:16:27 Z giorgikob Arranging Shoes (IOI19_shoes) C++14
컴파일 오류
0 ms 0 KB
#include "shoes.h"
 
int n,r,pos;

long long ans;

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

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

int get(int node,int tl,int tr){
	
	if(r<tl || tr<l)return 0;
	
	if(tr<=r && l<=tl)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) {
	
	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(!fix[i]){
		if(s[i]<0){
			int loc = locr[ -s[i] ][ indr[ -s[i] ] ];
			//cout<<loc<<" 1111"<<endl;
			r = loc;
			l = i+1;
			ans += loc - i - 1 - get(1,0,n-1);
			//cout<<ans<<" 111"<<endl;
			indr[ -s[i] ] ++;
			indl[ -s[i] ] ++;
			fix[loc]=1;
			upd(1,0,n-1,loc);
			
		} else {
			int loc = locl[ s[i] ][ indl[ s[i] ] ];
			//cout<<loc<<endl;
			r = loc;
			l = i+1;
			ans += loc - i - get(1,0,n-1);
			//cout<<ans<<endl;
			indl[ s[i] ] ++;
			indr[ s[i] ] ++;
			fix[loc]=1;
			upd(1,0,n-1,loc);
		}
	}
	
	return ans;
}

Compilation message

shoes.cpp: In function 'int get(int, int, int)':
shoes.cpp:31:16: error: 'l' was not declared in this scope
  if(r<tl || tr<l)return 0;
                ^
shoes.cpp:31:16: note: suggested alternative: 'tl'
  if(r<tl || tr<l)return 0;
                ^
                tl
shoes.cpp:33:14: error: 'l' was not declared in this scope
  if(tr<=r && l<=tl)return tree[node];
              ^
shoes.cpp:33:14: note: suggested alternative: 'tl'
  if(tr<=r && l<=tl)return tree[node];
              ^
              tl
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:59:4: error: 'l' was not declared in this scope
    l = i+1;
    ^
shoes.cpp:71:4: error: 'l' was not declared in this scope
    l = i+1;
    ^