답안 #294556

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
294556 2020-09-09T04:37:37 Z nandonathaniel The Potion of Great Power (CEOI20_potion) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN=100005;

int h[MAXN],C[MAXN],n,D;
vector<pii> adj[MAXN];
vector<vector<int> > preCompute[MAXN];

void init(int N, int d, int H[]) {
	n=N;D=d;
	for(int i=0;i<n;i++)h[i]=H[i];
}

void curseChanges(int U, int A[], int B[]) {
	for(int i=0;i<U;i++){
		adj[A[i]].push_back({B[i],i+1});
		adj[B[i]].push_back({A[i],i+1});
	}
	for(int i=0;i<n;i++){
		C[i]=(int)sqrt((int)adj[i].size());
		if(C[i]==0)C[i]=1;
		set<int> S;
		preCompute[i].push_back(vector<int>());
		for(int j=0;j<adj[i].size();j++){
			if(S.count(adj[i][j].first)){
				S.erase(adj[i][j].first);
			}
			else S.insert(adj[i][j].first);
			if((j+1)%C[i]==0){
				preCompute[i].push_back(vector<int>());
				for(int isi : S)preCompute[i].back().push_back(isi);
			}
		}
	}
}

bitset<100005> stat;

int question(int a, int b, int d) {
	int ans=1e9;
	if(d==0){
		return ans;
	}
	int ki=0,ka=adj[a].size()-1,res=-1;
	while(ki<=ka){
		int mid=(ki+ka)/2;
		if(adj[a][mid].second<=d){
			res=mid;
			ki=mid+1;
		}
		else ka=mid-1;
	}
	stat.reset();
	vector<int> A;
	if(res!=-1){
		for(auto isi : preCompute[a][res/C[a]])stat[isi]=true;
		for(int i=(res/C[a])*C[a];i<=res;i++){
			stat[adj[a][i].first]=stat[adj[a][i].first]^1;
		}
		for(auto isi : preCompute[a][res/C[a]]){
			if(stat[isi])A.push_back(h[isi]);
		}
		for(int i=(res/C[a])*C[a];i<=res;i++){
			if(stat[adj[a][i].first])A.push_back(h[adj[a][i].first]);
		}
	}
	ki=0;ka=adj[b].size()-1;res=-1;
	while(ki<=ka){
		int mid=(ki+ka)/2;
		if(adj[b][mid].second<=d){
			res=mid;
			ki=mid+1;
		}
		else ka=mid-1;
	}
	stat.reset();
	vector<int> B;
	if(res!=-1){
		for(auto isi : preCompute[b][res/C[b]])stat[isi]=true;
		for(int i=(res/C[b])*C[b];i<=res;i++){
			stat[adj[b][i].first]=stat[adj[b][i].first]^1;
		}
		for(auto isi : preCompute[b][res/C[b]]){
			if(stat[isi])B.push_back(h[isi]);
		}
		for(int i=(res/C[b])*C[b];i<=res;i++){
			if(stat[adj[b][i].first])B.push_back(h[adj[b][i].first]);
		}
	}
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	int x=0,y=0;
	while(x<(int)A.size() && y<(int)B.size()){
		ans=min(ans,abs(A[x]-B[y]));
		if(A[x]<B[y])x++;
		else y++;
	}
	return ans;
}

Compilation message

potion.cpp:6:8: error: 'pii' was not declared in this scope
    6 | vector<pii> adj[MAXN];
      |        ^~~
potion.cpp:6:11: error: template argument 1 is invalid
    6 | vector<pii> adj[MAXN];
      |           ^
potion.cpp:6:11: error: template argument 2 is invalid
potion.cpp: In function 'void curseChanges(int, int*, int*)':
potion.cpp:16:13: error: request for member 'push_back' in 'adj[(*(A + ((sizetype)(((long unsigned int)i) * 4))))]', which is of non-class type 'int'
   16 |   adj[A[i]].push_back({B[i],i+1});
      |             ^~~~~~~~~
potion.cpp:17:13: error: request for member 'push_back' in 'adj[(*(B + ((sizetype)(((long unsigned int)i) * 4))))]', which is of non-class type 'int'
   17 |   adj[B[i]].push_back({A[i],i+1});
      |             ^~~~~~~~~
potion.cpp:20:30: error: request for member 'size' in 'adj[i]', which is of non-class type 'int'
   20 |   C[i]=(int)sqrt((int)adj[i].size());
      |                              ^~~~
potion.cpp:24:24: error: request for member 'size' in 'adj[i]', which is of non-class type 'int'
   24 |   for(int j=0;j<adj[i].size();j++){
      |                        ^~~~
potion.cpp:25:23: error: invalid types 'int[int]' for array subscript
   25 |    if(S.count(adj[i][j].first)){
      |                       ^
potion.cpp:26:21: error: invalid types 'int[int]' for array subscript
   26 |     S.erase(adj[i][j].first);
      |                     ^
potion.cpp:28:26: error: invalid types 'int[int]' for array subscript
   28 |    else S.insert(adj[i][j].first);
      |                          ^
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:44:21: error: request for member 'size' in 'adj[a]', which is of non-class type 'int'
   44 |  int ki=0,ka=adj[a].size()-1,res=-1;
      |                     ^~~~
potion.cpp:47:16: error: invalid types 'int[int]' for array subscript
   47 |   if(adj[a][mid].second<=d){
      |                ^
potion.cpp:48:4: error: 'res' was not declared in this scope
   48 |    res=mid;
      |    ^~~
potion.cpp:55:5: error: 'res' was not declared in this scope
   55 |  if(res!=-1){
      |     ^~~
potion.cpp:58:17: error: invalid types 'int[int]' for array subscript
   58 |    stat[adj[a][i].first]=stat[adj[a][i].first]^1;
      |                 ^
potion.cpp:58:39: error: invalid types 'int[int]' for array subscript
   58 |    stat[adj[a][i].first]=stat[adj[a][i].first]^1;
      |                                       ^
potion.cpp:64:20: error: invalid types 'int[int]' for array subscript
   64 |    if(stat[adj[a][i].first])A.push_back(h[adj[a][i].first]);
      |                    ^
potion.cpp:64:51: error: invalid types 'int[int]' for array subscript
   64 |    if(stat[adj[a][i].first])A.push_back(h[adj[a][i].first]);
      |                                                   ^
potion.cpp:67:17: error: request for member 'size' in 'adj[b]', which is of non-class type 'int'
   67 |  ki=0;ka=adj[b].size()-1;res=-1;
      |                 ^~~~
potion.cpp:67:26: error: 'res' was not declared in this scope
   67 |  ki=0;ka=adj[b].size()-1;res=-1;
      |                          ^~~
potion.cpp:70:16: error: invalid types 'int[int]' for array subscript
   70 |   if(adj[b][mid].second<=d){
      |                ^
potion.cpp:81:17: error: invalid types 'int[int]' for array subscript
   81 |    stat[adj[b][i].first]=stat[adj[b][i].first]^1;
      |                 ^
potion.cpp:81:39: error: invalid types 'int[int]' for array subscript
   81 |    stat[adj[b][i].first]=stat[adj[b][i].first]^1;
      |                                       ^
potion.cpp:87:20: error: invalid types 'int[int]' for array subscript
   87 |    if(stat[adj[b][i].first])B.push_back(h[adj[b][i].first]);
      |                    ^
potion.cpp:87:51: error: invalid types 'int[int]' for array subscript
   87 |    if(stat[adj[b][i].first])B.push_back(h[adj[b][i].first]);
      |                                                   ^