#include <bits/stdc++.h>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const int N = 2e5 + 10;
struct qq {
int s, e, l, r, id;
int mx, mn;
qq( int s, int e, int l, int r, int id ) : s(s), e(e), l(l), r(r), id(id) {}
};
bool cmpl( qq a, qq b ) { return a.l < b.l; }
bool cmpr( qq a, qq b ) { return a.r < b.r; }
int n, par[2*N], va[2*N], m, q, lb[2*N], rb[2*N];
set<int> roots[2*N];
vector<qq> want[2*N], que;
vector<int> ans, tmin[2*N], tmax[2*N], g[2*N], pred;
int findroot( int now ) {
if( par[now] == now ) return now;
else return par[now] = findroot( par[now] );
}
void pre( int u = 2*n-2 ) {
if( u < n ) pred.emplace_back( u );
for( int v : tmin[u] ) pre( v );
}
void dfs( int u = 2*n-2 ) {
lb[u] = 1e9, rb[u] = -1;
if( u < n ) lb[u] = rb[u] = va[u];
for( int v : tmin[u] ) {
dfs( v );
lb[u] = min( lb[u], lb[v] ), rb[u] = max( rb[u], rb[v] );
}
}
void solve( int u = n*2-2 ) {
if( u < n ) roots[u].insert( va[u] );
pii hv( 0, -1 );
for( int v : tmax[u] ) {
solve( v );
hv = max( hv, pii( roots[v].size(), v ) );
}
if( hv.y != -1 ) {
swap( roots[hv.y], roots[u] );
for( int v : tmax[u] ) {
for( int x : roots[v] ) roots[u].insert( x );
}
}
for( qq i : want[u] ) ans[i.id] = roots[u].upper_bound( rb[i.mn] ) != roots[u].upper_bound( lb[i.mn] - 1 );
}
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();
for( int i = 0 ; i < q ; i++ ) que.emplace_back( qq( S[i], E[i], L[i], R[i], i ) );
for( int i = 0 ; i < m ; i++ ) g[X[i]].emplace_back( Y[i] ), g[Y[i]].emplace_back( X[i] );
for( int i = 0 ; i <= 2*n ; i++ ) par[i] = i;
sort( que.begin(), que.end(), cmpr );
int cnt = n-1, pos = 0;
for( int i = 0 ; i < n ; i++ ) {
for( int v : g[i] ) {
if( v < i ) {
int a = findroot( i ), b = findroot( v );
if( a == b ) continue;
par[a] = par[b] = ++cnt;
tmin[cnt].emplace_back( a ), tmin[cnt].emplace_back( b );
}
}
while( pos < q && que[pos].r == i ) {
que[pos].mn = findroot( que[pos].e );
pos++;
}
}
for( int i = 0 ; i <= 2*n ; i++ ) par[i] = i;
sort( que.begin(), que.end(), cmpl );
reverse( que.begin(), que.end() );
cnt = n-1, pos = 0;
for( int i = n-1 ; i >= 0 ; i-- ) {
for( int v : g[i] ) {
if( v > i ) {
int a = findroot( i ), b = findroot( v );
if( a == b ) continue;
par[a] = par[b] = ++cnt;
tmax[cnt].emplace_back( a ), tmax[cnt].emplace_back( b );
}
}
while( pos < q && que[pos].l == i ) {
que[pos].mx = findroot( que[pos].s );
pos++;
}
}
pre();
for( int i = 0 ; i < n ; i++ ) va[pred[i]] = i;
dfs();
ans.resize( q );
for( int i = 0 ; i < q ; i++ ) want[que[i].mx].emplace_back( que[i] );
solve();
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
56704 KB |
Output is correct |
2 |
Correct |
40 ms |
56704 KB |
Output is correct |
3 |
Correct |
40 ms |
56704 KB |
Output is correct |
4 |
Correct |
41 ms |
56704 KB |
Output is correct |
5 |
Correct |
41 ms |
56704 KB |
Output is correct |
6 |
Correct |
39 ms |
56696 KB |
Output is correct |
7 |
Correct |
41 ms |
56696 KB |
Output is correct |
8 |
Correct |
41 ms |
56696 KB |
Output is correct |
9 |
Correct |
40 ms |
56704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
56704 KB |
Output is correct |
2 |
Correct |
40 ms |
56704 KB |
Output is correct |
3 |
Correct |
40 ms |
56704 KB |
Output is correct |
4 |
Correct |
41 ms |
56704 KB |
Output is correct |
5 |
Correct |
41 ms |
56704 KB |
Output is correct |
6 |
Correct |
39 ms |
56696 KB |
Output is correct |
7 |
Correct |
41 ms |
56696 KB |
Output is correct |
8 |
Correct |
41 ms |
56696 KB |
Output is correct |
9 |
Correct |
40 ms |
56704 KB |
Output is correct |
10 |
Correct |
47 ms |
58104 KB |
Output is correct |
11 |
Correct |
47 ms |
58104 KB |
Output is correct |
12 |
Correct |
45 ms |
58104 KB |
Output is correct |
13 |
Correct |
50 ms |
58240 KB |
Output is correct |
14 |
Correct |
50 ms |
58312 KB |
Output is correct |
15 |
Correct |
50 ms |
58232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1062 ms |
172428 KB |
Output is correct |
2 |
Correct |
903 ms |
142068 KB |
Output is correct |
3 |
Correct |
966 ms |
149596 KB |
Output is correct |
4 |
Correct |
962 ms |
162780 KB |
Output is correct |
5 |
Correct |
948 ms |
165852 KB |
Output is correct |
6 |
Correct |
992 ms |
171608 KB |
Output is correct |
7 |
Correct |
1032 ms |
173540 KB |
Output is correct |
8 |
Correct |
906 ms |
141928 KB |
Output is correct |
9 |
Correct |
812 ms |
148192 KB |
Output is correct |
10 |
Correct |
837 ms |
162520 KB |
Output is correct |
11 |
Correct |
887 ms |
163944 KB |
Output is correct |
12 |
Correct |
935 ms |
169560 KB |
Output is correct |
13 |
Correct |
790 ms |
141400 KB |
Output is correct |
14 |
Correct |
785 ms |
141272 KB |
Output is correct |
15 |
Correct |
826 ms |
141148 KB |
Output is correct |
16 |
Correct |
782 ms |
141148 KB |
Output is correct |
17 |
Correct |
1018 ms |
171736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
56704 KB |
Output is correct |
2 |
Correct |
40 ms |
56704 KB |
Output is correct |
3 |
Correct |
40 ms |
56704 KB |
Output is correct |
4 |
Correct |
41 ms |
56704 KB |
Output is correct |
5 |
Correct |
41 ms |
56704 KB |
Output is correct |
6 |
Correct |
39 ms |
56696 KB |
Output is correct |
7 |
Correct |
41 ms |
56696 KB |
Output is correct |
8 |
Correct |
41 ms |
56696 KB |
Output is correct |
9 |
Correct |
40 ms |
56704 KB |
Output is correct |
10 |
Correct |
47 ms |
58104 KB |
Output is correct |
11 |
Correct |
47 ms |
58104 KB |
Output is correct |
12 |
Correct |
45 ms |
58104 KB |
Output is correct |
13 |
Correct |
50 ms |
58240 KB |
Output is correct |
14 |
Correct |
50 ms |
58312 KB |
Output is correct |
15 |
Correct |
50 ms |
58232 KB |
Output is correct |
16 |
Correct |
1062 ms |
172428 KB |
Output is correct |
17 |
Correct |
903 ms |
142068 KB |
Output is correct |
18 |
Correct |
966 ms |
149596 KB |
Output is correct |
19 |
Correct |
962 ms |
162780 KB |
Output is correct |
20 |
Correct |
948 ms |
165852 KB |
Output is correct |
21 |
Correct |
992 ms |
171608 KB |
Output is correct |
22 |
Correct |
1032 ms |
173540 KB |
Output is correct |
23 |
Correct |
906 ms |
141928 KB |
Output is correct |
24 |
Correct |
812 ms |
148192 KB |
Output is correct |
25 |
Correct |
837 ms |
162520 KB |
Output is correct |
26 |
Correct |
887 ms |
163944 KB |
Output is correct |
27 |
Correct |
935 ms |
169560 KB |
Output is correct |
28 |
Correct |
790 ms |
141400 KB |
Output is correct |
29 |
Correct |
785 ms |
141272 KB |
Output is correct |
30 |
Correct |
826 ms |
141148 KB |
Output is correct |
31 |
Correct |
782 ms |
141148 KB |
Output is correct |
32 |
Correct |
1018 ms |
171736 KB |
Output is correct |
33 |
Correct |
1037 ms |
145628 KB |
Output is correct |
34 |
Correct |
455 ms |
90588 KB |
Output is correct |
35 |
Correct |
1079 ms |
142812 KB |
Output is correct |
36 |
Correct |
1008 ms |
146076 KB |
Output is correct |
37 |
Correct |
1079 ms |
142556 KB |
Output is correct |
38 |
Correct |
1043 ms |
144856 KB |
Output is correct |
39 |
Correct |
1014 ms |
159324 KB |
Output is correct |
40 |
Correct |
1043 ms |
144092 KB |
Output is correct |
41 |
Correct |
973 ms |
141480 KB |
Output is correct |
42 |
Correct |
930 ms |
144216 KB |
Output is correct |
43 |
Correct |
1184 ms |
145284 KB |
Output is correct |
44 |
Correct |
1022 ms |
142300 KB |
Output is correct |
45 |
Correct |
961 ms |
149848 KB |
Output is correct |
46 |
Correct |
1012 ms |
159324 KB |
Output is correct |
47 |
Correct |
788 ms |
141216 KB |
Output is correct |
48 |
Correct |
764 ms |
141024 KB |
Output is correct |
49 |
Correct |
787 ms |
141148 KB |
Output is correct |
50 |
Correct |
766 ms |
141176 KB |
Output is correct |
51 |
Correct |
983 ms |
144344 KB |
Output is correct |
52 |
Correct |
1054 ms |
144348 KB |
Output is correct |