# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1020169 |
2024-07-11T16:15:31 Z |
Issa |
Werewolf (IOI18_werewolf) |
C++17 |
|
205 ms |
119096 KB |
#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[l][k], mn[r-(1<<k)+1][k]);
}
int getmx(int l, int r){
int k = lg[r - l + 1];
return max(mx[l][k], mx[r-(1<<k)+1][k]);
}
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);
if(i > 1) 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) br = mid - 1;
else bl = mid + 1, tr = mid;
}
for(int bl = e, br = s; bl <= br;){
int mid = (bl + br) >> 1;
if(getmx(e, mid) > r) bl = mid + 1;
else br = mid - 1, tl = mid;
}
if(tl <= tr) res = 1;
}
ans.push_back(res);
}
return ans;
}
}
Compilation message
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:101:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | for(int i = 0; i < S.size(); i++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7004 KB |
Output is correct |
2 |
Correct |
3 ms |
5980 KB |
Output is correct |
3 |
Correct |
4 ms |
5212 KB |
Output is correct |
4 |
Correct |
2 ms |
5212 KB |
Output is correct |
5 |
Correct |
3 ms |
6052 KB |
Output is correct |
6 |
Correct |
2 ms |
7004 KB |
Output is correct |
7 |
Correct |
2 ms |
7004 KB |
Output is correct |
8 |
Correct |
2 ms |
7004 KB |
Output is correct |
9 |
Correct |
2 ms |
5980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7004 KB |
Output is correct |
2 |
Correct |
3 ms |
5980 KB |
Output is correct |
3 |
Correct |
4 ms |
5212 KB |
Output is correct |
4 |
Correct |
2 ms |
5212 KB |
Output is correct |
5 |
Correct |
3 ms |
6052 KB |
Output is correct |
6 |
Correct |
2 ms |
7004 KB |
Output is correct |
7 |
Correct |
2 ms |
7004 KB |
Output is correct |
8 |
Correct |
2 ms |
7004 KB |
Output is correct |
9 |
Correct |
2 ms |
5980 KB |
Output is correct |
10 |
Correct |
87 ms |
77996 KB |
Output is correct |
11 |
Correct |
84 ms |
78160 KB |
Output is correct |
12 |
Correct |
67 ms |
78196 KB |
Output is correct |
13 |
Correct |
84 ms |
79188 KB |
Output is correct |
14 |
Correct |
69 ms |
79156 KB |
Output is correct |
15 |
Correct |
78 ms |
79188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
205 ms |
119096 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7004 KB |
Output is correct |
2 |
Correct |
3 ms |
5980 KB |
Output is correct |
3 |
Correct |
4 ms |
5212 KB |
Output is correct |
4 |
Correct |
2 ms |
5212 KB |
Output is correct |
5 |
Correct |
3 ms |
6052 KB |
Output is correct |
6 |
Correct |
2 ms |
7004 KB |
Output is correct |
7 |
Correct |
2 ms |
7004 KB |
Output is correct |
8 |
Correct |
2 ms |
7004 KB |
Output is correct |
9 |
Correct |
2 ms |
5980 KB |
Output is correct |
10 |
Correct |
87 ms |
77996 KB |
Output is correct |
11 |
Correct |
84 ms |
78160 KB |
Output is correct |
12 |
Correct |
67 ms |
78196 KB |
Output is correct |
13 |
Correct |
84 ms |
79188 KB |
Output is correct |
14 |
Correct |
69 ms |
79156 KB |
Output is correct |
15 |
Correct |
78 ms |
79188 KB |
Output is correct |
16 |
Runtime error |
205 ms |
119096 KB |
Execution killed with signal 11 |
17 |
Halted |
0 ms |
0 KB |
- |