# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
443046 |
2021-07-09T14:14:01 Z |
peijar |
Werewolf (IOI18_werewolf) |
C++17 |
|
998 ms |
167660 KB |
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5;
const int MAXP = 18;
vector<int> adj[MAXN], adjMin[MAXN], adjMax[MAXN];
vector<int> S, E;
int tin[MAXN], tout[MAXN];
int curTime;
int parMin[MAXP][MAXN], parMax[MAXP][MAXN];
int nbSommets, nbAretes, nbRequetes;
vector<int> ans;
vector<int> queryAtNode[MAXN];
int idMin[MAXN], largestMin[MAXN], idMax[MAXN], smallestMax[MAXN];
void dfs(int u) {
tin[u] = curTime++;
for (int v : adjMin[u])
dfs(v);
tout[u] = curTime++;
}
set<int> dfs2(int u) {
vector<set<int>> childs = {{tin[u]}};
for (int v : adjMax[u]) {
childs.push_back(dfs2(v));
}
for (int i = 1; i < (int)childs.size(); ++i)
if (childs[i].size() > childs[0].size())
swap(childs[i], childs[0]);
for (int i = 1; i < (int)childs.size(); ++i)
for (auto v : childs[i])
childs[0].insert(v);
set<int> ret = move(childs[0]);
for (int iRequete : queryAtNode[u]) {
auto it = ret.lower_bound(tin[S[iRequete]]);
if (it != ret.end() and *it <= tout[S[iRequete]])
ans[iRequete] = 1;
}
return ret;
}
// Min tree : We want the minimum vertex on a path to be the largest possible.
int findMin(int u) { return idMin[u] < 0 ? u : idMin[u] = findMin(idMin[u]); }
int findMax(int u) { return idMax[u] < 0 ? u : idMax[u] = findMax(idMax[u]); }
void mergeMin(int a, int b) {
a = findMin(a), b = findMin(b);
if (a == b)
return;
if (largestMin[a] < largestMin[b])
swap(a, b);
parMin[0][largestMin[a]] = largestMin[b];
adjMin[largestMin[b]].push_back(largestMin[a]);
idMin[a] += idMin[b];
idMin[b] = a;
largestMin[a] = largestMin[b];
}
void mergeMax(int a, int b) {
a = findMax(a), b = findMax(b);
if (a == b)
return;
if (smallestMax[a] > smallestMax[b])
swap(a, b);
parMax[0][smallestMax[a]] = smallestMax[b];
adjMax[smallestMax[b]].push_back(smallestMax[a]);
idMax[a] += idMax[b];
idMax[b] = a;
smallestMax[a] = smallestMax[b];
}
vector<int> check_validity(int N, vector<int> X, vector<int> Y, vector<int> _S,
vector<int> _E, vector<int> L, vector<int> R) {
S = _S, E = _E;
nbSommets = N;
nbAretes = X.size();
for (int i = 0; i < nbAretes; ++i) {
adj[X[i]].push_back(Y[i]);
adj[Y[i]].push_back(X[i]);
}
for (int i = 0; i < nbSommets; ++i) {
largestMin[i] = smallestMax[i] = i;
idMin[i] = idMax[i] = -1;
}
for (int i = nbSommets - 1; i >= 0; --i)
for (int j : adj[i])
if (j > i) {
mergeMin(j, i);
}
for (int i = 0; i < nbSommets; ++i)
for (int j : adj[i])
if (j < i)
mergeMax(j, i);
parMax[0][nbSommets - 1] = nbSommets - 1;
for (int p = 0; p < MAXP - 1; ++p)
for (int i = 0; i < nbSommets; ++i) {
parMax[p + 1][i] = parMax[p][parMax[p][i]];
parMin[p + 1][i] = parMin[p][parMin[p][i]];
}
nbRequetes = S.size();
for (int i = 0; i < nbRequetes; ++i)
for (int p = MAXP - 1; p >= 0; --p)
if (parMin[p][S[i]] >= L[i])
S[i] = parMin[p][S[i]];
ans.resize(nbRequetes);
for (int i = 0; i < nbRequetes; ++i)
for (int p = MAXP - 1; p >= 0; --p)
if (parMax[p][E[i]] <= R[i])
E[i] = parMax[p][E[i]];
for (int i = 0; i < nbRequetes; ++i)
queryAtNode[E[i]].push_back(i);
dfs(0);
dfs2(nbSommets - 1);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
19276 KB |
Output is correct |
2 |
Correct |
13 ms |
19404 KB |
Output is correct |
3 |
Correct |
13 ms |
19276 KB |
Output is correct |
4 |
Correct |
13 ms |
19216 KB |
Output is correct |
5 |
Correct |
13 ms |
19336 KB |
Output is correct |
6 |
Correct |
13 ms |
19276 KB |
Output is correct |
7 |
Correct |
13 ms |
19296 KB |
Output is correct |
8 |
Correct |
13 ms |
19264 KB |
Output is correct |
9 |
Correct |
13 ms |
19280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
19276 KB |
Output is correct |
2 |
Correct |
13 ms |
19404 KB |
Output is correct |
3 |
Correct |
13 ms |
19276 KB |
Output is correct |
4 |
Correct |
13 ms |
19216 KB |
Output is correct |
5 |
Correct |
13 ms |
19336 KB |
Output is correct |
6 |
Correct |
13 ms |
19276 KB |
Output is correct |
7 |
Correct |
13 ms |
19296 KB |
Output is correct |
8 |
Correct |
13 ms |
19264 KB |
Output is correct |
9 |
Correct |
13 ms |
19280 KB |
Output is correct |
10 |
Correct |
19 ms |
20688 KB |
Output is correct |
11 |
Correct |
18 ms |
20568 KB |
Output is correct |
12 |
Correct |
18 ms |
20440 KB |
Output is correct |
13 |
Correct |
19 ms |
21340 KB |
Output is correct |
14 |
Correct |
19 ms |
21324 KB |
Output is correct |
15 |
Correct |
20 ms |
20600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
831 ms |
94248 KB |
Output is correct |
2 |
Correct |
837 ms |
120680 KB |
Output is correct |
3 |
Correct |
775 ms |
104664 KB |
Output is correct |
4 |
Correct |
733 ms |
98980 KB |
Output is correct |
5 |
Correct |
720 ms |
98856 KB |
Output is correct |
6 |
Correct |
777 ms |
99508 KB |
Output is correct |
7 |
Correct |
847 ms |
101768 KB |
Output is correct |
8 |
Correct |
816 ms |
120900 KB |
Output is correct |
9 |
Correct |
589 ms |
104640 KB |
Output is correct |
10 |
Correct |
530 ms |
98612 KB |
Output is correct |
11 |
Correct |
542 ms |
98424 KB |
Output is correct |
12 |
Correct |
601 ms |
98880 KB |
Output is correct |
13 |
Correct |
880 ms |
137116 KB |
Output is correct |
14 |
Correct |
888 ms |
137156 KB |
Output is correct |
15 |
Correct |
882 ms |
137188 KB |
Output is correct |
16 |
Correct |
908 ms |
137064 KB |
Output is correct |
17 |
Correct |
798 ms |
101496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
19276 KB |
Output is correct |
2 |
Correct |
13 ms |
19404 KB |
Output is correct |
3 |
Correct |
13 ms |
19276 KB |
Output is correct |
4 |
Correct |
13 ms |
19216 KB |
Output is correct |
5 |
Correct |
13 ms |
19336 KB |
Output is correct |
6 |
Correct |
13 ms |
19276 KB |
Output is correct |
7 |
Correct |
13 ms |
19296 KB |
Output is correct |
8 |
Correct |
13 ms |
19264 KB |
Output is correct |
9 |
Correct |
13 ms |
19280 KB |
Output is correct |
10 |
Correct |
19 ms |
20688 KB |
Output is correct |
11 |
Correct |
18 ms |
20568 KB |
Output is correct |
12 |
Correct |
18 ms |
20440 KB |
Output is correct |
13 |
Correct |
19 ms |
21340 KB |
Output is correct |
14 |
Correct |
19 ms |
21324 KB |
Output is correct |
15 |
Correct |
20 ms |
20600 KB |
Output is correct |
16 |
Correct |
831 ms |
94248 KB |
Output is correct |
17 |
Correct |
837 ms |
120680 KB |
Output is correct |
18 |
Correct |
775 ms |
104664 KB |
Output is correct |
19 |
Correct |
733 ms |
98980 KB |
Output is correct |
20 |
Correct |
720 ms |
98856 KB |
Output is correct |
21 |
Correct |
777 ms |
99508 KB |
Output is correct |
22 |
Correct |
847 ms |
101768 KB |
Output is correct |
23 |
Correct |
816 ms |
120900 KB |
Output is correct |
24 |
Correct |
589 ms |
104640 KB |
Output is correct |
25 |
Correct |
530 ms |
98612 KB |
Output is correct |
26 |
Correct |
542 ms |
98424 KB |
Output is correct |
27 |
Correct |
601 ms |
98880 KB |
Output is correct |
28 |
Correct |
880 ms |
137116 KB |
Output is correct |
29 |
Correct |
888 ms |
137156 KB |
Output is correct |
30 |
Correct |
882 ms |
137188 KB |
Output is correct |
31 |
Correct |
908 ms |
137064 KB |
Output is correct |
32 |
Correct |
798 ms |
101496 KB |
Output is correct |
33 |
Correct |
811 ms |
104588 KB |
Output is correct |
34 |
Correct |
338 ms |
54216 KB |
Output is correct |
35 |
Correct |
904 ms |
117076 KB |
Output is correct |
36 |
Correct |
771 ms |
102408 KB |
Output is correct |
37 |
Correct |
896 ms |
113220 KB |
Output is correct |
38 |
Correct |
808 ms |
105192 KB |
Output is correct |
39 |
Correct |
981 ms |
166440 KB |
Output is correct |
40 |
Correct |
899 ms |
122920 KB |
Output is correct |
41 |
Correct |
669 ms |
108996 KB |
Output is correct |
42 |
Correct |
619 ms |
100756 KB |
Output is correct |
43 |
Correct |
998 ms |
131208 KB |
Output is correct |
44 |
Correct |
828 ms |
111796 KB |
Output is correct |
45 |
Correct |
887 ms |
167660 KB |
Output is correct |
46 |
Correct |
813 ms |
167236 KB |
Output is correct |
47 |
Correct |
944 ms |
137260 KB |
Output is correct |
48 |
Correct |
862 ms |
137156 KB |
Output is correct |
49 |
Correct |
867 ms |
137388 KB |
Output is correct |
50 |
Correct |
891 ms |
137120 KB |
Output is correct |
51 |
Correct |
801 ms |
122908 KB |
Output is correct |
52 |
Correct |
789 ms |
123456 KB |
Output is correct |