답안 #349700

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
349700 2021-01-18T08:17:08 Z Bill_00 The Potion of Great Power (CEOI20_potion) C++14
컴파일 오류
0 ms 0 KB
int h[N],pre[N];
unordered_map<int,vector<int> >v[N];
vector<int>day[N];
void init(int N, int D, int H[]) {
}

void curseChanges(int u, int A[], int B[]){
	for(int i=1;i<=u;i++){
		int a=A[i-1],b=B[i-1];
		day[a].pb(i);
		day[b].pb(i);
		if(pre[a]==0){
			v[a][i].pb(b);
			pre[a]=i;
		}
		else{
			bool flag=0;
			for(int j:v[a][pre[a]]){
				if(j==b){
					flag=1;
					continue;
				}
				v[a][i].pb(j);
			}
			if(flag==0) v[a][i].pb(b);
			pre[a]=i;
		}
		if(pre[b]==0){
			v[b][i].pb(a);
			pre[b]=i;
		}
		else{
			bool flag=0;
			for(int j:v[b][pre[b]]){
				if(j==a){
					flag=1;
					continue;
				}
				v[b][i].pb(j);
			}
			if(flag==0) v[b][i].pb(a);
			pre[b]=i;
		}
	}
}

int question(int x, int y, int z) {
	int ans=1e9;
	int id=upper_bound(day[x].begin(),day[x].end(),z)-day[x].begin();
	--id;
	if(id<0){
		return ans;
	}
	int a=day[x][id];
	id=upper_bound(day[y].begin(),day[y].end(),z)-day[y].begin();
	--id;
	if(id<0){
		return ans;
	}
	int b=day[y][id];
	// cout << a << ' ' << b << '\n';
	if(v[x][a].size()==0 || v[y][b].size()==0){
		return ans;
	}
	vector<int>xx,yy;
	for(int V:v[y][b]){
		yy.pb(h[V]);
	}
	sort(yy.begin(),yy.end());
	for(int U:v[x][a]){
		int id=lower_bound(yy.begin(),yy.end(),h[U])-yy.begin();
		ans=min(ans,abs(h[U]-yy[max(0,id-1)]));
		ans=min(ans,abs(yy[id]-h[U]));
	}
	return ans;
}

Compilation message

potion.cpp:1:7: error: 'N' was not declared in this scope
    1 | int h[N],pre[N];
      |       ^
potion.cpp:1:14: error: 'N' was not declared in this scope
    1 | int h[N],pre[N];
      |              ^
potion.cpp:2:1: error: 'unordered_map' does not name a type
    2 | unordered_map<int,vector<int> >v[N];
      | ^~~~~~~~~~~~~
potion.cpp:3:1: error: 'vector' does not name a type
    3 | vector<int>day[N];
      | ^~~~~~
potion.cpp: In function 'void curseChanges(int, int*, int*)':
potion.cpp:10:3: error: 'day' was not declared in this scope
   10 |   day[a].pb(i);
      |   ^~~
potion.cpp:12:6: error: 'pre' was not declared in this scope
   12 |   if(pre[a]==0){
      |      ^~~
potion.cpp:13:4: error: 'v' was not declared in this scope
   13 |    v[a][i].pb(b);
      |    ^
potion.cpp:18:14: error: 'v' was not declared in this scope
   18 |    for(int j:v[a][pre[a]]){
      |              ^
potion.cpp:25:16: error: 'v' was not declared in this scope
   25 |    if(flag==0) v[a][i].pb(b);
      |                ^
potion.cpp:28:6: error: 'pre' was not declared in this scope
   28 |   if(pre[b]==0){
      |      ^~~
potion.cpp:29:4: error: 'v' was not declared in this scope
   29 |    v[b][i].pb(a);
      |    ^
potion.cpp:34:14: error: 'v' was not declared in this scope
   34 |    for(int j:v[b][pre[b]]){
      |              ^
potion.cpp:41:16: error: 'v' was not declared in this scope
   41 |    if(flag==0) v[b][i].pb(a);
      |                ^
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:49:21: error: 'day' was not declared in this scope
   49 |  int id=upper_bound(day[x].begin(),day[x].end(),z)-day[x].begin();
      |                     ^~~
potion.cpp:49:9: error: 'upper_bound' was not declared in this scope
   49 |  int id=upper_bound(day[x].begin(),day[x].end(),z)-day[x].begin();
      |         ^~~~~~~~~~~
potion.cpp:62:5: error: 'v' was not declared in this scope
   62 |  if(v[x][a].size()==0 || v[y][b].size()==0){
      |     ^
potion.cpp:65:2: error: 'vector' was not declared in this scope
   65 |  vector<int>xx,yy;
      |  ^~~~~~
potion.cpp:65:9: error: expected primary-expression before 'int'
   65 |  vector<int>xx,yy;
      |         ^~~
potion.cpp:66:12: error: 'v' was not declared in this scope
   66 |  for(int V:v[y][b]){
      |            ^
potion.cpp:67:3: error: 'yy' was not declared in this scope; did you mean 'y'?
   67 |   yy.pb(h[V]);
      |   ^~
      |   y
potion.cpp:67:9: error: 'h' was not declared in this scope
   67 |   yy.pb(h[V]);
      |         ^
potion.cpp:69:7: error: 'yy' was not declared in this scope; did you mean 'y'?
   69 |  sort(yy.begin(),yy.end());
      |       ^~
      |       y
potion.cpp:69:2: error: 'sort' was not declared in this scope; did you mean 'short'?
   69 |  sort(yy.begin(),yy.end());
      |  ^~~~
      |  short
potion.cpp:70:12: error: 'v' was not declared in this scope
   70 |  for(int U:v[x][a]){
      |            ^
potion.cpp:71:42: error: 'h' was not declared in this scope
   71 |   int id=lower_bound(yy.begin(),yy.end(),h[U])-yy.begin();
      |                                          ^
potion.cpp:71:10: error: 'lower_bound' was not declared in this scope
   71 |   int id=lower_bound(yy.begin(),yy.end(),h[U])-yy.begin();
      |          ^~~~~~~~~~~
potion.cpp:72:27: error: 'max' was not declared in this scope
   72 |   ans=min(ans,abs(h[U]-yy[max(0,id-1)]));
      |                           ^~~
potion.cpp:72:15: error: 'abs' was not declared in this scope; did you mean 'ans'?
   72 |   ans=min(ans,abs(h[U]-yy[max(0,id-1)]));
      |               ^~~
      |               ans
potion.cpp:72:7: error: 'min' was not declared in this scope
   72 |   ans=min(ans,abs(h[U]-yy[max(0,id-1)]));
      |       ^~~