# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
370074 | 2021-02-23T07:41:09 Z | Mamnoon_Siam | Long Mansion (JOI17_long_mansion) | C++17 | 620 ms | 59100 KB |
#include <bits/stdc++.h> using namespace std; /* sorry, this is the bare minimum :'( */ using ll = long long; using ii = pair<int, int>; using vi = vector<int>; #define all(v) begin(v), end(v) #define sz(v) (int)(v).size() #define fi first #define se second const int N = 5e5 + 5; int n; vi indices[N]; int par[N]; ii ra[N]; int C[N]; bool has(int l, int r, int x) { return upper_bound(all(indices[x]), r) != lower_bound(all(indices[x]), l); } ii U(ii x, ii y) { // assumption: intersects return {min(x.fi, y.fi), max(x.se, y.se)}; } int find(int u) { assert(u); if(par[u] == u) return u; par[u] = find(par[u]); ra[par[u]] = U(ra[u], ra[par[u]]); return par[u]; } void unite(int u, int v) { int pu = find(u), pv = find(v); if(pu != pv) { par[pu] = pv; find(pu); } } int onstk[N], vis[N]; void dfs(int u) { vis[u] = 1; onstk[u] = 1; while(true) { int flag = 0; { ii& r = ra[find(u)]; if(r.fi > 1) if(has(r.fi, r.se, C[r.fi-1])) { ++flag; if(!vis[r.fi-1]) { dfs(r.fi-1); } else { if(onstk[r.fi-1]) { unite(u, r.fi-1); } else { r = U(r, ra[find(r.fi-1)]); } } } } { ii& r = ra[find(u)]; if(r.se < n) if(has(r.fi, r.se, C[r.se])) { ++flag; if(!vis[r.se+1]) { dfs(r.se+1); } else { if(onstk[r.se+1]) { unite(u, r.se+1); } else { r = U(r, ra[find(r.se+1)]); } } } } if(!flag) { break; } } onstk[u] = 0; } int main(int argc, char const *argv[]) { #ifdef LOCAL freopen("in", "r", stdin); #endif scanf("%d", &n); for(int i = 1; i < n; ++i) { scanf("%d", &C[i]); } for(int i = 1; i <= n; ++i) { ra[i] = {i, i}; par[i] = i; int B; scanf("%d", &B); while(B--) { int x; scanf("%d", &x); indices[x].emplace_back(i); } } for(int i = 1; i <= n; ++i) { if(!vis[i]) dfs(i); } int q; scanf("%d", &q); while(q--) { int x, y; scanf("%d %d", &x, &y); puts(ra[find(x)].fi <= y and y <= ra[find(x)].se ? "YES" : "NO"); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12268 KB | Output is correct |
2 | Correct | 13 ms | 12304 KB | Output is correct |
3 | Correct | 14 ms | 12524 KB | Output is correct |
4 | Correct | 11 ms | 12268 KB | Output is correct |
5 | Correct | 11 ms | 12396 KB | Output is correct |
6 | Correct | 11 ms | 12268 KB | Output is correct |
7 | Correct | 11 ms | 12268 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12268 KB | Output is correct |
2 | Correct | 13 ms | 12304 KB | Output is correct |
3 | Correct | 14 ms | 12524 KB | Output is correct |
4 | Correct | 11 ms | 12268 KB | Output is correct |
5 | Correct | 11 ms | 12396 KB | Output is correct |
6 | Correct | 11 ms | 12268 KB | Output is correct |
7 | Correct | 11 ms | 12268 KB | Output is correct |
8 | Correct | 141 ms | 13804 KB | Output is correct |
9 | Correct | 137 ms | 13676 KB | Output is correct |
10 | Correct | 146 ms | 13932 KB | Output is correct |
11 | Correct | 191 ms | 14444 KB | Output is correct |
12 | Correct | 140 ms | 13932 KB | Output is correct |
13 | Correct | 145 ms | 13932 KB | Output is correct |
14 | Correct | 146 ms | 14060 KB | Output is correct |
15 | Correct | 152 ms | 14060 KB | Output is correct |
16 | Correct | 140 ms | 14368 KB | Output is correct |
17 | Correct | 144 ms | 13932 KB | Output is correct |
18 | Correct | 144 ms | 13932 KB | Output is correct |
19 | Correct | 149 ms | 14060 KB | Output is correct |
20 | Correct | 142 ms | 14188 KB | Output is correct |
21 | Correct | 140 ms | 14572 KB | Output is correct |
22 | Correct | 141 ms | 14060 KB | Output is correct |
23 | Correct | 137 ms | 13804 KB | Output is correct |
24 | Correct | 142 ms | 14080 KB | Output is correct |
25 | Correct | 140 ms | 13932 KB | Output is correct |
26 | Correct | 137 ms | 13804 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 291 ms | 19180 KB | Output is correct |
2 | Correct | 292 ms | 19564 KB | Output is correct |
3 | Correct | 291 ms | 21460 KB | Output is correct |
4 | Correct | 304 ms | 19308 KB | Output is correct |
5 | Correct | 298 ms | 19564 KB | Output is correct |
6 | Correct | 248 ms | 21228 KB | Output is correct |
7 | Correct | 231 ms | 24940 KB | Output is correct |
8 | Correct | 232 ms | 25324 KB | Output is correct |
9 | Correct | 227 ms | 25324 KB | Output is correct |
10 | Correct | 225 ms | 25452 KB | Output is correct |
11 | Correct | 245 ms | 25580 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12268 KB | Output is correct |
2 | Correct | 13 ms | 12304 KB | Output is correct |
3 | Correct | 14 ms | 12524 KB | Output is correct |
4 | Correct | 11 ms | 12268 KB | Output is correct |
5 | Correct | 11 ms | 12396 KB | Output is correct |
6 | Correct | 11 ms | 12268 KB | Output is correct |
7 | Correct | 11 ms | 12268 KB | Output is correct |
8 | Correct | 141 ms | 13804 KB | Output is correct |
9 | Correct | 137 ms | 13676 KB | Output is correct |
10 | Correct | 146 ms | 13932 KB | Output is correct |
11 | Correct | 191 ms | 14444 KB | Output is correct |
12 | Correct | 140 ms | 13932 KB | Output is correct |
13 | Correct | 145 ms | 13932 KB | Output is correct |
14 | Correct | 146 ms | 14060 KB | Output is correct |
15 | Correct | 152 ms | 14060 KB | Output is correct |
16 | Correct | 140 ms | 14368 KB | Output is correct |
17 | Correct | 144 ms | 13932 KB | Output is correct |
18 | Correct | 144 ms | 13932 KB | Output is correct |
19 | Correct | 149 ms | 14060 KB | Output is correct |
20 | Correct | 142 ms | 14188 KB | Output is correct |
21 | Correct | 140 ms | 14572 KB | Output is correct |
22 | Correct | 141 ms | 14060 KB | Output is correct |
23 | Correct | 137 ms | 13804 KB | Output is correct |
24 | Correct | 142 ms | 14080 KB | Output is correct |
25 | Correct | 140 ms | 13932 KB | Output is correct |
26 | Correct | 137 ms | 13804 KB | Output is correct |
27 | Correct | 291 ms | 19180 KB | Output is correct |
28 | Correct | 292 ms | 19564 KB | Output is correct |
29 | Correct | 291 ms | 21460 KB | Output is correct |
30 | Correct | 304 ms | 19308 KB | Output is correct |
31 | Correct | 298 ms | 19564 KB | Output is correct |
32 | Correct | 248 ms | 21228 KB | Output is correct |
33 | Correct | 231 ms | 24940 KB | Output is correct |
34 | Correct | 232 ms | 25324 KB | Output is correct |
35 | Correct | 227 ms | 25324 KB | Output is correct |
36 | Correct | 225 ms | 25452 KB | Output is correct |
37 | Correct | 245 ms | 25580 KB | Output is correct |
38 | Correct | 434 ms | 34924 KB | Output is correct |
39 | Correct | 462 ms | 39788 KB | Output is correct |
40 | Correct | 392 ms | 34384 KB | Output is correct |
41 | Correct | 620 ms | 59100 KB | Output is correct |
42 | Correct | 256 ms | 25340 KB | Output is correct |
43 | Correct | 260 ms | 25196 KB | Output is correct |
44 | Correct | 363 ms | 32108 KB | Output is correct |
45 | Correct | 372 ms | 32364 KB | Output is correct |
46 | Correct | 369 ms | 32876 KB | Output is correct |
47 | Correct | 249 ms | 29292 KB | Output is correct |
48 | Correct | 235 ms | 28908 KB | Output is correct |
49 | Correct | 427 ms | 33260 KB | Output is correct |
50 | Correct | 392 ms | 35180 KB | Output is correct |
51 | Correct | 390 ms | 36332 KB | Output is correct |
52 | Correct | 284 ms | 35144 KB | Output is correct |
53 | Correct | 385 ms | 43496 KB | Output is correct |
54 | Correct | 419 ms | 49388 KB | Output is correct |
55 | Correct | 359 ms | 42348 KB | Output is correct |