# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
778392 |
2023-07-10T09:07:11 Z |
IBory |
Werewolf (IOI18_werewolf) |
C++17 |
|
869 ms |
187516 KB |
#include "werewolf.h"
#include <bits/stdc++.h>
#define pii pair<int, int>
using namespace std;
const int SZ = 1 << 19;
int inv[SZ];
struct BIT {
int T[SZ];
void Update(int i, int v) {
for (; i < SZ; i += i & -i) T[i] += v;
}
int Query(int L, int R) {
int ret = 0; L--;
for (; R; R -= R & -R) ret += T[R];
for (; L; L -= L & -L) ret -= T[L];
return ret;
}
} T;
struct UFTree {
int R[SZ], A[SZ], in[SZ], out[SZ], P[19][SZ], node, dn;
vector<int> G[SZ];
UFTree(int N, vector<pii>& E, int type) {
iota(R, R + SZ, 0);
node = N - 1;
Construct(E, type);
DFS(node);
}
int Find(int n) {
if (n == R[n]) return n;
return R[n] = Find(R[n]);
}
bool Union(int a, int b, int c) {
R[a] = c, R[b] = c;
return 1;
}
void Construct(vector<pii>& E, int type) {
for (int i = 0; i <= node; ++i) A[i] = i;
for (auto [a, b] : E) {
a = Find(a), b = Find(b);
if (a != b) {
P[0][a] = P[0][b] = ++node;
Union(a, b, node);
G[node].push_back(a);
G[node].push_back(b);
A[node] = (type == 1 ? max(A[a], A[b]) : min(A[a], A[b]));
}
}
P[0][node] = node;
for (int n = 1; n < 19; ++n) for (int i = 0; i <= node; ++i) {
P[n][i] = P[n - 1][P[n - 1][i]];
}
}
void DFS(int cur) {
in[cur] = ++dn;
for (int next : G[cur]) DFS(next);
out[cur] = dn;
}
};
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 M = X.size(), Q = S.size();
vector<pii> Eord[2];
for (int i = 0; i < M; ++i) {
Eord[0].emplace_back(X[i], Y[i]);
Eord[1].emplace_back(X[i], Y[i]);
}
sort(Eord[0].begin(), Eord[0].end(), [&](pii& a, pii& b) {
return max(a.first, a.second) < max(b.first, b.second);
});
sort(Eord[1].begin(), Eord[1].end(), [&](pii& a, pii& b) {
return min(a.first, a.second) > min(b.first, b.second);
});
UFTree T1(N, Eord[1], 0);
UFTree T2(N, Eord[0], 1);
vector<int> ans(Q);
vector<pair<pii, pair<pii, int>>> Qord;
for (int i = 0; i < Q; ++i) {
int s = S[i], e = E[i];
for (int n = 18; n >= 0; --n) {
if (L[i] <= T1.A[T1.P[n][s]]) s = T1.P[n][s];
if (T2.A[T2.P[n][e]] <= R[i]) {
e = T2.P[n][e];
}
}
pii r = {T2.in[e], T2.out[e]};
Qord.emplace_back(pii{T1.in[s], -1}, pair<pii, int>{r, i});
Qord.emplace_back(pii{T1.out[s], 1}, pair<pii, int>{r, i});
}
pii dummy = {0, 0};
for (int i = 0; i < N; ++i) Qord.emplace_back(pii{T1.in[i], 0}, pair<pii, int>{dummy, Q});
sort(Qord.begin(), Qord.end());
for (int i = 0; i < N; ++i) inv[T1.in[i]] = T2.in[i];
for (auto [p1, p2] : Qord) {
auto [x, type] = p1;
auto [p3, qn] = p2;
auto [l, r] = p3;
if (type == -1) ans[qn] -= T.Query(l, r);
else if (type == 0) T.Update(inv[x], 1);
else ans[qn] += T.Query(l, r);
}
for (int& n : ans) n = n > 0;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
119372 KB |
Output is correct |
2 |
Correct |
44 ms |
119372 KB |
Output is correct |
3 |
Correct |
45 ms |
119368 KB |
Output is correct |
4 |
Correct |
45 ms |
119248 KB |
Output is correct |
5 |
Correct |
50 ms |
119440 KB |
Output is correct |
6 |
Correct |
44 ms |
119380 KB |
Output is correct |
7 |
Correct |
45 ms |
119368 KB |
Output is correct |
8 |
Correct |
44 ms |
119268 KB |
Output is correct |
9 |
Correct |
45 ms |
119380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
119372 KB |
Output is correct |
2 |
Correct |
44 ms |
119372 KB |
Output is correct |
3 |
Correct |
45 ms |
119368 KB |
Output is correct |
4 |
Correct |
45 ms |
119248 KB |
Output is correct |
5 |
Correct |
50 ms |
119440 KB |
Output is correct |
6 |
Correct |
44 ms |
119380 KB |
Output is correct |
7 |
Correct |
45 ms |
119368 KB |
Output is correct |
8 |
Correct |
44 ms |
119268 KB |
Output is correct |
9 |
Correct |
45 ms |
119380 KB |
Output is correct |
10 |
Correct |
52 ms |
120156 KB |
Output is correct |
11 |
Correct |
50 ms |
120108 KB |
Output is correct |
12 |
Correct |
50 ms |
120148 KB |
Output is correct |
13 |
Correct |
55 ms |
120228 KB |
Output is correct |
14 |
Correct |
50 ms |
120212 KB |
Output is correct |
15 |
Correct |
51 ms |
120228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
791 ms |
166980 KB |
Output is correct |
2 |
Correct |
683 ms |
177880 KB |
Output is correct |
3 |
Correct |
672 ms |
176312 KB |
Output is correct |
4 |
Correct |
707 ms |
175548 KB |
Output is correct |
5 |
Correct |
690 ms |
175428 KB |
Output is correct |
6 |
Correct |
734 ms |
175356 KB |
Output is correct |
7 |
Correct |
781 ms |
175340 KB |
Output is correct |
8 |
Correct |
577 ms |
177940 KB |
Output is correct |
9 |
Correct |
447 ms |
176280 KB |
Output is correct |
10 |
Correct |
404 ms |
175456 KB |
Output is correct |
11 |
Correct |
477 ms |
175452 KB |
Output is correct |
12 |
Correct |
477 ms |
175464 KB |
Output is correct |
13 |
Correct |
809 ms |
177928 KB |
Output is correct |
14 |
Correct |
724 ms |
177912 KB |
Output is correct |
15 |
Correct |
717 ms |
178000 KB |
Output is correct |
16 |
Correct |
703 ms |
177968 KB |
Output is correct |
17 |
Correct |
769 ms |
175424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
119372 KB |
Output is correct |
2 |
Correct |
44 ms |
119372 KB |
Output is correct |
3 |
Correct |
45 ms |
119368 KB |
Output is correct |
4 |
Correct |
45 ms |
119248 KB |
Output is correct |
5 |
Correct |
50 ms |
119440 KB |
Output is correct |
6 |
Correct |
44 ms |
119380 KB |
Output is correct |
7 |
Correct |
45 ms |
119368 KB |
Output is correct |
8 |
Correct |
44 ms |
119268 KB |
Output is correct |
9 |
Correct |
45 ms |
119380 KB |
Output is correct |
10 |
Correct |
52 ms |
120156 KB |
Output is correct |
11 |
Correct |
50 ms |
120108 KB |
Output is correct |
12 |
Correct |
50 ms |
120148 KB |
Output is correct |
13 |
Correct |
55 ms |
120228 KB |
Output is correct |
14 |
Correct |
50 ms |
120212 KB |
Output is correct |
15 |
Correct |
51 ms |
120228 KB |
Output is correct |
16 |
Correct |
791 ms |
166980 KB |
Output is correct |
17 |
Correct |
683 ms |
177880 KB |
Output is correct |
18 |
Correct |
672 ms |
176312 KB |
Output is correct |
19 |
Correct |
707 ms |
175548 KB |
Output is correct |
20 |
Correct |
690 ms |
175428 KB |
Output is correct |
21 |
Correct |
734 ms |
175356 KB |
Output is correct |
22 |
Correct |
781 ms |
175340 KB |
Output is correct |
23 |
Correct |
577 ms |
177940 KB |
Output is correct |
24 |
Correct |
447 ms |
176280 KB |
Output is correct |
25 |
Correct |
404 ms |
175456 KB |
Output is correct |
26 |
Correct |
477 ms |
175452 KB |
Output is correct |
27 |
Correct |
477 ms |
175464 KB |
Output is correct |
28 |
Correct |
809 ms |
177928 KB |
Output is correct |
29 |
Correct |
724 ms |
177912 KB |
Output is correct |
30 |
Correct |
717 ms |
178000 KB |
Output is correct |
31 |
Correct |
703 ms |
177968 KB |
Output is correct |
32 |
Correct |
769 ms |
175424 KB |
Output is correct |
33 |
Correct |
869 ms |
176032 KB |
Output is correct |
34 |
Correct |
363 ms |
163424 KB |
Output is correct |
35 |
Correct |
813 ms |
178548 KB |
Output is correct |
36 |
Correct |
855 ms |
175964 KB |
Output is correct |
37 |
Correct |
865 ms |
177604 KB |
Output is correct |
38 |
Correct |
860 ms |
176412 KB |
Output is correct |
39 |
Correct |
831 ms |
180624 KB |
Output is correct |
40 |
Correct |
736 ms |
187256 KB |
Output is correct |
41 |
Correct |
523 ms |
177172 KB |
Output is correct |
42 |
Correct |
504 ms |
175992 KB |
Output is correct |
43 |
Correct |
622 ms |
184076 KB |
Output is correct |
44 |
Correct |
620 ms |
177672 KB |
Output is correct |
45 |
Correct |
479 ms |
180988 KB |
Output is correct |
46 |
Correct |
493 ms |
180688 KB |
Output is correct |
47 |
Correct |
698 ms |
178212 KB |
Output is correct |
48 |
Correct |
696 ms |
178140 KB |
Output is correct |
49 |
Correct |
668 ms |
178176 KB |
Output is correct |
50 |
Correct |
664 ms |
177996 KB |
Output is correct |
51 |
Correct |
541 ms |
187496 KB |
Output is correct |
52 |
Correct |
574 ms |
187516 KB |
Output is correct |