#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
typedef long long ll;
const int B = 1 << 18;
ll n, m, q, par[B], a, b, d[B][2], u[B][2], t;
vector<int> adj[B], seg[B * 2];
vector<int> g[B], vl[B], vr[B];
int find(int x){return par[x] == -1 ? x : par[x] = find(par[x]);}
void dfs(int x, int f){
!f ? d[x][0] = t++ : u[x][0] = t++;
for(int& nx : g[x]) dfs(nx, f);
!f ? d[x][1] = t - 1 : u[x][1] = t - 1;
return;
}
int qry(int l, int r, int k){
l += B; r += B;
int ret = n;
while(l <= r){
if(l & 1){
auto it = lower_bound(all(seg[l]), k);
if(it != seg[l].end()) ret = min(ret, *it);
l++;
}
if(!(r & 1)){
auto it = lower_bound(all(seg[r]), k);
if(it != seg[r].end()) ret = min(ret, *it);
r--;
}
l /= 2; r /= 2;
}
return ret;
}
vector<int> check_validity(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R) {
n = N, m = X.size(), q = S.size();
vector<int> A(q);
for(int i = 0; i < m; i++){
a = X[i]; b = Y[i];
adj[a].emplace_back(b);
adj[b].emplace_back(a);
}
for(int i = 0; i < q; i++){
vl[L[i]].emplace_back(i);
vr[R[i]].emplace_back(i);
}
memset(par, -1, sizeof(par));
for(int x = n - 1; x >= 0; x--){
for(int y : adj[x]){
if(y < x) continue;
y = find(y);
if(x == y) continue;
par[y] = x;
g[x].emplace_back(y);
}
for(int& i : vl[x])
S[i] = find(S[i]);
}
dfs(0, 0);
memset(par, -1, sizeof(par));
for(int i = 0; i < n; i++) g[i].clear();
for(int x = 0; x < n; x++) {
for(int y : adj[x]){
if(y > x) continue;
y = find(y);
if(x == y) continue;
par[y] = x;
g[x].emplace_back(y);
}
for(int& i : vr[x])
E[i] = find(E[i]);
}
t = 0; dfs(n - 1, 1);
for(int i = 0; i < n; i++) seg[B + u[i][0]].emplace_back(d[i][0]);
for(int i = B - 1; i; i--){
seg[i].resize(seg[i * 2].size() + seg[i * 2 + 1].size());
merge(all(seg[i * 2]), all(seg[i * 2 + 1]), seg[i].begin());
}
for(int i = 0; i < q; i++){
a = u[E[i]][0]; b = u[E[i]][1];
if(qry(a, b, d[S[i]][0]) <= d[S[i]][1]) A[i] = 1;
else A[i] = 0;
//cout << i << ' ' << A[i] << '\n';
}
return A;
}
/*
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m >> q;
vector<int> X(m), Y(m), S(q), E(q), L(q), R(q), ans;
for(int i = 0; i < m; i++) cin >> X[i] >> Y[i];
for(int i = 0; i < q; i++) cin >> S[i] >> E[i] >> L[i] >> R[i];
ans = check_validity(n, X, Y, S, E, L, R);
for(int i = 0; i < q; i++) cout << ans[i] << ' ';
return 0;
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
39252 KB |
Output is correct |
2 |
Correct |
20 ms |
39288 KB |
Output is correct |
3 |
Correct |
21 ms |
39276 KB |
Output is correct |
4 |
Correct |
19 ms |
39296 KB |
Output is correct |
5 |
Correct |
19 ms |
39252 KB |
Output is correct |
6 |
Correct |
19 ms |
39284 KB |
Output is correct |
7 |
Correct |
20 ms |
39292 KB |
Output is correct |
8 |
Correct |
19 ms |
39252 KB |
Output is correct |
9 |
Correct |
24 ms |
39252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
39252 KB |
Output is correct |
2 |
Correct |
20 ms |
39288 KB |
Output is correct |
3 |
Correct |
21 ms |
39276 KB |
Output is correct |
4 |
Correct |
19 ms |
39296 KB |
Output is correct |
5 |
Correct |
19 ms |
39252 KB |
Output is correct |
6 |
Correct |
19 ms |
39284 KB |
Output is correct |
7 |
Correct |
20 ms |
39292 KB |
Output is correct |
8 |
Correct |
19 ms |
39252 KB |
Output is correct |
9 |
Correct |
24 ms |
39252 KB |
Output is correct |
10 |
Correct |
25 ms |
40276 KB |
Output is correct |
11 |
Correct |
26 ms |
40324 KB |
Output is correct |
12 |
Correct |
24 ms |
40292 KB |
Output is correct |
13 |
Correct |
26 ms |
40464 KB |
Output is correct |
14 |
Correct |
27 ms |
40444 KB |
Output is correct |
15 |
Correct |
25 ms |
40384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
558 ms |
98808 KB |
Output is correct |
2 |
Correct |
604 ms |
110692 KB |
Output is correct |
3 |
Correct |
658 ms |
108436 KB |
Output is correct |
4 |
Correct |
599 ms |
107460 KB |
Output is correct |
5 |
Correct |
590 ms |
107400 KB |
Output is correct |
6 |
Correct |
554 ms |
107220 KB |
Output is correct |
7 |
Correct |
475 ms |
104980 KB |
Output is correct |
8 |
Correct |
575 ms |
110704 KB |
Output is correct |
9 |
Correct |
501 ms |
107268 KB |
Output is correct |
10 |
Correct |
437 ms |
106088 KB |
Output is correct |
11 |
Correct |
407 ms |
106164 KB |
Output is correct |
12 |
Correct |
561 ms |
106948 KB |
Output is correct |
13 |
Correct |
572 ms |
111936 KB |
Output is correct |
14 |
Correct |
527 ms |
111940 KB |
Output is correct |
15 |
Correct |
544 ms |
111968 KB |
Output is correct |
16 |
Correct |
569 ms |
111972 KB |
Output is correct |
17 |
Correct |
464 ms |
104908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
39252 KB |
Output is correct |
2 |
Correct |
20 ms |
39288 KB |
Output is correct |
3 |
Correct |
21 ms |
39276 KB |
Output is correct |
4 |
Correct |
19 ms |
39296 KB |
Output is correct |
5 |
Correct |
19 ms |
39252 KB |
Output is correct |
6 |
Correct |
19 ms |
39284 KB |
Output is correct |
7 |
Correct |
20 ms |
39292 KB |
Output is correct |
8 |
Correct |
19 ms |
39252 KB |
Output is correct |
9 |
Correct |
24 ms |
39252 KB |
Output is correct |
10 |
Correct |
25 ms |
40276 KB |
Output is correct |
11 |
Correct |
26 ms |
40324 KB |
Output is correct |
12 |
Correct |
24 ms |
40292 KB |
Output is correct |
13 |
Correct |
26 ms |
40464 KB |
Output is correct |
14 |
Correct |
27 ms |
40444 KB |
Output is correct |
15 |
Correct |
25 ms |
40384 KB |
Output is correct |
16 |
Correct |
558 ms |
98808 KB |
Output is correct |
17 |
Correct |
604 ms |
110692 KB |
Output is correct |
18 |
Correct |
658 ms |
108436 KB |
Output is correct |
19 |
Correct |
599 ms |
107460 KB |
Output is correct |
20 |
Correct |
590 ms |
107400 KB |
Output is correct |
21 |
Correct |
554 ms |
107220 KB |
Output is correct |
22 |
Correct |
475 ms |
104980 KB |
Output is correct |
23 |
Correct |
575 ms |
110704 KB |
Output is correct |
24 |
Correct |
501 ms |
107268 KB |
Output is correct |
25 |
Correct |
437 ms |
106088 KB |
Output is correct |
26 |
Correct |
407 ms |
106164 KB |
Output is correct |
27 |
Correct |
561 ms |
106948 KB |
Output is correct |
28 |
Correct |
572 ms |
111936 KB |
Output is correct |
29 |
Correct |
527 ms |
111940 KB |
Output is correct |
30 |
Correct |
544 ms |
111968 KB |
Output is correct |
31 |
Correct |
569 ms |
111972 KB |
Output is correct |
32 |
Correct |
464 ms |
104908 KB |
Output is correct |
33 |
Correct |
691 ms |
108356 KB |
Output is correct |
34 |
Correct |
270 ms |
72552 KB |
Output is correct |
35 |
Correct |
772 ms |
111108 KB |
Output is correct |
36 |
Correct |
599 ms |
107888 KB |
Output is correct |
37 |
Correct |
768 ms |
110120 KB |
Output is correct |
38 |
Correct |
645 ms |
108460 KB |
Output is correct |
39 |
Correct |
735 ms |
116992 KB |
Output is correct |
40 |
Correct |
593 ms |
114324 KB |
Output is correct |
41 |
Correct |
617 ms |
109596 KB |
Output is correct |
42 |
Correct |
441 ms |
106612 KB |
Output is correct |
43 |
Correct |
846 ms |
114880 KB |
Output is correct |
44 |
Correct |
688 ms |
110204 KB |
Output is correct |
45 |
Correct |
577 ms |
115992 KB |
Output is correct |
46 |
Correct |
625 ms |
115904 KB |
Output is correct |
47 |
Correct |
547 ms |
112108 KB |
Output is correct |
48 |
Correct |
555 ms |
111824 KB |
Output is correct |
49 |
Correct |
531 ms |
112076 KB |
Output is correct |
50 |
Correct |
557 ms |
111936 KB |
Output is correct |
51 |
Correct |
534 ms |
112960 KB |
Output is correct |
52 |
Correct |
517 ms |
112872 KB |
Output is correct |