Submission #1020200

#TimeUsernameProblemLanguageResultExecution timeMemory
1020200IssaWerewolf (IOI18_werewolf)C++17
49 / 100
272 ms78420 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 3e3 + 100; int n; int pref[maxn][maxn]; int suf[maxn][maxn]; vector<int> g[200100]; int get(int v, int p[]){ if(p[v] == v) return v; return p[v] = get(p[v], p); } void join(int a, int b, int p[]){ p[get(a, p)] = get(b, p); } void add(vector<int> &v){ for(int &x: v) x++; } int mx[22][200100]; int mn[22][200100]; int b[200100], t; int lg[200100]; void dfs(int v, int p = 0){ t++; b[v] = t; mx[0][t] = mn[0][t] = v; for(int to: g[v]){ if(to == p) continue; dfs(to, v); } } int getmn(int l, int r){ int k = lg[r - l + 1]; return min(mn[k][l], mn[k][r-(1<<k)+1]); } int getmx(int l, int r){ int k = lg[r - l + 1]; return max(mx[k][l], mx[k][r-(1<<k)+1]); } 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){ add(X); add(Y); add(S); add(E); add(L); add(R); n = N; for(int i = 0; i < X.size(); i++){ g[X[i]].push_back(Y[i]); g[Y[i]].push_back(X[i]); } if(n <= 3000){ for(int i = 1; i <= n; i++){ pref[0][i] = suf[n+1][i] = i; } for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ pref[i][j] = pref[i-1][j]; } for(int to: g[i]){ if(to < i) join(to, i, pref[i]); } } for(int i = n; i > 0; i--){ for(int j = 1; j <= n; j++){ suf[i][j] = suf[i+1][j]; } for(int to: g[i]){ if(to > i) join(to, i, suf[i]); } } vector<int> ans; for(int i = 0; i < S.size(); i++){ int s = S[i], e = E[i]; int l = L[i], r = R[i]; int res = 0; for(int k = l; k <= r; k++){ if(get(s, suf[l]) == get(k, suf[l]) && get(k, pref[r]) == get(e, pref[r])){ res = 1; } } ans.push_back(res); } return ans; } else{ for(int i = 1; i <= n; i++){ if(g[i].size() == 1){ dfs(i); break; } } for(int i = 2; i <= n; i++){ lg[i] = lg[i >> 1] + 1; } for(int k = 1; k <= lg[n]; k++){ for(int i = 1; i + (1<<k) - 1 <= n; i++){ mx[k][i] = max(mx[k-1][i], mx[k-1][i+(1<<(k-1))]); mn[k][i] = min(mn[k-1][i], mn[k-1][i+(1<<(k-1))]); } } vector<int> ans; for(int i = 0; i < S.size(); i++){ int s = S[i], e = E[i]; int l = L[i], r = R[i]; s = b[s]; e = b[e]; int res = 0; if(s <= e){ int tr = s - 1, tl = e + 1; for(int bl = s, br = e; bl <= br;){ int mid = (bl + br) >> 1; if(getmn(s, mid) < l) br = mid - 1; else bl = mid + 1, tr = mid; } for(int bl = s, br = e; bl <= br;){ int mid = (bl + br) >> 1; if(getmx(mid, e) > r) bl = mid + 1; else br = mid - 1, tl = mid; } if(tl <= tr) res = 1; } else{ int tr = e - 1, tl = s + 1; for(int bl = e, br = s; bl <= br;){ int mid = (bl + br) >> 1; if(getmn(mid, s) < l) bl = mid + 1; else br = mid - 1, tl = mid; } for(int bl = e, br = s; bl <= br;){ int mid = (bl + br) >> 1; if(getmx(e, mid) > r) br = mid - 1; else bl = mid + 1, tr = mid; } if(tl <= tr) res = 1; } ans.push_back(res); } return ans; } }

Compilation message (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:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(int i = 0; i < X.size(); i++){
      |                    ~~^~~~~~~~~~
werewolf.cpp:77:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |         for(int i = 0; i < S.size(); i++){
      |                        ~~^~~~~~~~~~
werewolf.cpp:106:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |         for(int i = 0; i < S.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...