제출 #295454

#제출 시각아이디문제언어결과실행 시간메모리
295454eohomegrownapps늑대인간 (IOI18_werewolf)C++14
0 / 100
4056 ms38172 KiB
#include "werewolf.h" #include <bits/stdc++.h> using namespace std; vector<int> l; vector<int> r; int n,q; int sqrtn; vector<vector<int>> adjlist; bool comp(int a, int b){ if (l[a]/sqrtn == l[b]/sqrtn){ return r[a]<r[b]; } else { return l[a]<l[b]; } } std::vector<int> check_validity(int N, std::vector<int> x, std::vector<int> y, std::vector<int> s, std::vector<int> e, std::vector<int> L, std::vector<int> R) { q = s.size(); l=L;r=R;n=N; sqrtn=sqrt(n); vector<int> inds(q); for (int i = 0; i<q; i++){ inds[i]=i; } sort(inds.begin(),inds.end(),comp); adjlist.resize(n); for (int i = 0; i<x.size(); i++){ //cout<<x[i]<<' '<<y[i]<<endl; adjlist[x[i]].push_back(y[i]); adjlist[y[i]].push_back(x[i]); } int start = -1; for (int i = 0; i<n; i++){ if (adjlist[i].size()==1){ start=i; break; } } int cur = start; int pre = -1; int ptr = 0; vector<int> ind2pop(n); vector<int> pop2ind(n); do { ind2pop[ptr]=cur; pop2ind[cur]=ptr; if (adjlist[cur][0]==pre){ pre=cur; cur=adjlist[cur][1]; } else { pre=cur; cur=adjlist[cur][0]; } ptr++; } while (adjlist[cur].size()!=1); ind2pop[ptr]=cur; pop2ind[cur]=ptr; vector<int> ans(q); for (int i : ind2pop){ cout<<i<<' '; }cout<<'\n'; int lv = 0; int rv = 0; set<int> lvals; set<int> rvals; for (int i = 1; i<n; i++){ rvals.insert(pop2ind[i]); } lvals.insert(-1); lvals.insert(n); rvals.insert(-1); rvals.insert(n); for (int i = 0; i<q; i++){ if (lv<l[inds[i]]){ while (lv<l[inds[i]]){ lvals.insert(pop2ind[lv]); lv++; } lv--; } else if (lv>l[inds[i]]){ while (lv>=l[inds[i]]){ lvals.erase(pop2ind[lv]); lv--; } lv++; } if (rv<r[inds[i]]){ while (rv<=r[inds[i]]){ rvals.erase(pop2ind[rv]); rv++; } rv--; } else if (rv>r[inds[i]]){ while (rv>r[inds[i]]){ rvals.insert(pop2ind[rv]); rv--; } rv++; } /*cout<<"indices in l: "; for (int i : lvals){ cout<<i<<' '; }cout<<'\n'; cout<<"indices in r: "; for (int i : rvals){ cout<<i<<' '; }cout<<'\n';*/ int ls = *(prev(lvals.lower_bound(pop2ind[s[inds[i]]]),1)); int le = *(lvals.lower_bound(pop2ind[s[inds[i]]])); int rs = *(prev(rvals.lower_bound(pop2ind[e[inds[i]]]),1)); int re = *(rvals.lower_bound(pop2ind[e[inds[i]]])); if (le<rs||re<ls){ ans[i]=0; } else { ans[i]=1; } } return ans; }

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

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:35:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for (int i = 0; i<x.size(); i++){
      |                     ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...