제출 #1111708

#제출 시각아이디문제언어결과실행 시간메모리
1111708epicci23늑대인간 (IOI18_werewolf)C++17
컴파일 에러
0 ms0 KiB
#include "bits/stdc++.h" #include "werewolf.h" //#define int long long #define all(v) v.begin() , v.end() #define sz(a) (int)a.size() using namespace std; const int INF = 1000000007; const int N = 400005; const int LOG = 20; vector<int> v[N]; struct DSU{ vector<int> par,siz,mini; DSU(int _n){ par.resize(_n+5); iota(all(par),0); siz.assign(_n+5,1); mini.resize(_n+5); iota(all(mini),0); } int find(int a){ if(par[a]==a) return a; return par[a]=find(par[a]); } void unite(int a,int b){ a=find(a),b=find(b); if(a==b) return; if(siz[a]>siz[b]) swap(a,b); par[a]=b; siz[b]+=siz[a]; } } vector<int> human[N],wolf[N]; vector<int> hin(N,INF),hout(N,-INF),win(N,INF),wout(N,-INF); int wift[N][LOG],hift[N][LOG],Tman[N],Twolf[N]; int hp,wp,ptr=0; void hfs(int c){ if(sz(human[c])){ hout[c]=hin[c]=++ptr; return; } for(int i=1;i<LOG;i++) hift[c][i]=hift[hift[c][i-1]][i-1]; for(int x:human[c]){ hift[x][0]=c; hfs(x); hin[c]=min(hin[c],hin[x]); hout[c]=max(hout[c],hout[x]); } } void wfs(int c){ if(sz(wolf[c])){ wout[c]=win[c]=++ptr; return; } for(int i=1;i<LOG;i++) wift[c][i]=wift[wift[c][i-1]][i-1]; for(int x:wolf[c]){ wift[x][0]=c; wfs(x); win[c]=min(win[c],win[x]); wout[c]=max(wout[c],wout[x]); } } struct SegT{ vector<vector<int>> seg; SegT(int _n){ seg.resize(4*_n+5); } void add(int rt,int l,int r,int ind,int u){ if(r<ind || l>ind) return; if(l==r){ seg[rt].push_back(u); return; } int m=(l+r)/2; add(rt*2,l,m,ind,u),add(rt*2+1,m+1,r,ind,u); seg[rt].push_back(u); } int query(int rt,int l,int r,int gl,int gr,int bl,int br){ if(r<gl || l>gr) return 0; if(l>=gl && r<=gr){ int it = lower_bound(all(seg[rt]),bl) - seg[rt].begin(); if(it<sz(seg[rt]) && seg[rt][it]<=br) return 1; return 0; } int m=(l+r)/2; return query(rt*2,l,m,gl,gr,bl,br) + query(rt*2+1,m+1,r,gl,gr,bl,br); } }; vector<int> check_validity(int _N, vector<int> X, vector<int> Y,vector<int> S, vector<int> E, vector<int> L, vector<int> R) { int n=_N,m=sz(X),q=sz(L); for(int i=0;i<m;i++){ int a=X[i],b=Y[i]; v[a].push_back(b); v[b].push_back(a); } hp=n; DSU dsu(N),dsu2(N); for(int i=n-1;i>=0;i--){ for(int x:v[i]){ if(x>i){ int A = dsu.find(i), B = dsu.find(x); if(A==B) continue; int parA = dsu.mini[dsu.find(i)], parB = dsu.mini[dsu.find(x)]; dsu.merge(A,B); human[hp].push_back(parA); human[hp].push_back(parB); Tman[hp]=i; dsu.mini[dsu.find(A)]=hp++; } } } wp=n; for(int i=0;i<n;i++){ for(int x:v[i]){ if(x<i){ int A = dsu2.find(i), B = dsu2.find(x); if(A==B) continue; int parA = dsu2.mini[dsu2.find(i)], parB = dsu2.mini[dsu2.find(x)]; dsu2.merge(A,B); wolf[wp].push_back(parA); wolf[wp].push_back(parB); Twolf[wp]=i; dsu2.mini[dsu2.find(A)]=wp++; } } } for(int i=0;i<LOG;i++) wift[wp][i]=wp,hift[hp][i]=hp; ptr=0; hfs(hp); ptr=0; wfs(wp); SegT T(N); for(int i=0;i<n;i++) T.add(1,1,n,hin[i],win[i]); for(int i=0;i<sz(T.seg);i++) sort(all(T.seg[i])); vector<int> res(q,0); for(int i=0;i<q;i++){ int st = S[i], fn = E[i]; for(int j=LOG-1;j>=0;j--){ if(Tman[hift[st][j]] < L[i]) continue; st = hift[st][j]; } for(int j=LOG-1;j>=0;j--){ if(Twolf[wift[fn][j]] > R[i]) continue; fn = wift[fn][j]; } if(T.query(1,1,n,hin[st],hout[st],win[fn],wout[fn])) res[i]=1; else res[i]=0; } return res; }

컴파일 시 표준 에러 (stderr) 메시지

werewolf.cpp:35:13: error: invalid declarator before 'human'
   35 | vector<int> human[N],wolf[N];
      |             ^~~~~
werewolf.cpp: In function 'void hfs(int)':
werewolf.cpp:41:9: error: 'human' was not declared in this scope
   41 |   if(sz(human[c])){
      |         ^~~~~
werewolf.cpp:5:20: note: in definition of macro 'sz'
    5 | #define sz(a) (int)a.size()
      |                    ^
werewolf.cpp:46:13: error: 'human' was not declared in this scope
   46 |   for(int x:human[c]){
      |             ^~~~~
werewolf.cpp: In function 'void wfs(int)':
werewolf.cpp:55:9: error: 'wolf' was not declared in this scope; did you mean 'Twolf'?
   55 |   if(sz(wolf[c])){
      |         ^~~~
werewolf.cpp:5:20: note: in definition of macro 'sz'
    5 | #define sz(a) (int)a.size()
      |                    ^
werewolf.cpp:60:13: error: 'wolf' was not declared in this scope; did you mean 'Twolf'?
   60 |   for(int x:wolf[c]){
      |             ^~~~
      |             Twolf
werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:113:13: error: 'struct DSU' has no member named 'merge'
  113 |         dsu.merge(A,B);
      |             ^~~~~
werewolf.cpp:114:9: error: 'human' was not declared in this scope
  114 |         human[hp].push_back(parA);
      |         ^~~~~
werewolf.cpp:129:14: error: 'struct DSU' has no member named 'merge'
  129 |         dsu2.merge(A,B);
      |              ^~~~~
werewolf.cpp:130:9: error: 'wolf' was not declared in this scope; did you mean 'Twolf'?
  130 |         wolf[wp].push_back(parA);
      |         ^~~~
      |         Twolf