이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define dl double long
const int maxn = 200200;
int n,m,q;
int tim;
int t[4 * maxn];
int tin1[maxn];
int tout1[maxn];
int tin2[maxn];
int tout2[maxn];
int o1[maxn];
int o2[maxn];
int p[maxn];
int d1[maxn][25];
int d2[maxn][25];
vector < int > g[maxn];
vector < int > v[maxn];
vector < pair < int , int > > gg[maxn];
void upd( int x , int l , int r , int p , int val )
{
if( l == r ){
t[x] = val;
return;
}
int m = (l + r) / 2;
if( p <= m )upd( x + x , l , m , p , val );
else upd( x + x + 1 , m + 1 , r , p , val );
t[x] = max( t[x + x] , t[x + x + 1] );
}
int get( int x , int l , int r , int tl , int tr )
{
if( tl > tr )return -1;
if( l == tl && r == tr )return t[x];
int m = (l + r) / 2;
return max( get( x + x , l , m , tl , min( tr , m ) ) ,
get( x + x + 1 , m + 1 , r , max( tl , m + 1 ) , tr ) );
}
int get( int x )
{
return (p[x] == x ? x : p[x] = get(p[x]));
}
void meg( int x , int y )
{
int px = get(x);
int py = get(y);
if( px == py )return;
p[px] = py;
g[py].push_back(px);
g[px].push_back(py);
}
void dfs( int x , int p )
{
d1[x][0] = p;
for( int i = 1; i < 25; i++ ){
d1[x][i] = d1[d1[x][i - 1]][i - 1];
}
tin1[x] = ++tim;
o1[tim] = x;
for( auto y : g[x] ){
if( y == p )continue;
dfs( y , x );
}
tout1[x] = tim;
}
int ff( int x , int y )
{
for( int i = 24; i >= 0; i-- ){
if( d2[x][i] <= y ){
x = d2[x][i];
}
}
return x;
}
int ff1( int x , int y )
{
for( int i = 24; i >= 0; i-- ){
if( d1[x][i] >= y ){
x = d1[x][i];
}
}
return x;
}
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 = (int)X.size();
q = (int)S.size();
for( int i = 1; i <= n; i++ ){
p[i] = i;
}
for( int i = 0; i < m; i++ ){
v[X[i]].push_back(Y[i]);
v[Y[i]].push_back(X[i]);
}
for( int i = 0; i < n; i++ ){
for( auto x : v[i] ){
if( x > i )continue;
meg( x , i );
}
}
dfs( n - 1 , n - 1 );
for( int i = 0; i <= n; i++ ){
tin2[i] = tin1[i];
tout2[i] = tout1[i];
o2[i] = o1[i];
g[i].clear();
p[i] = i;
for( int j = 0; j < 25; j++ ){
d2[i][j] = d1[i][j];
}
}
tim = 0;
for( int i = n - 1; i >= 0; i-- ){
for( auto x : v[i] ){
if( x < i )continue;
meg( x , i );
}
}
dfs( 0 , 0 );
for( int i = 0; i < q; i++ ){
gg[R[i]].push_back({L[i] , i});
}
vector < int > ans(q , -1);
for( int i = 0; i <= n; i++ ){
//upd( 1 , 0 , n , tin1[i] , tin2[i] );
for( auto x : gg[i] ){
int yy = ff( E[x.se] , i );
int y = ff1( S[x.se] , x.fi );
bool f = false;
for( int i1 = tin2[yy]; i1 <= tout2[yy]; i1++ ){
for( int j1 = tin1[y]; j1 <= tout1[y]; j1++ ){
if( o2[i1] < x.fi || o2[i1] > i || o1[j1] < x.fi || o1[j1] > i )continue;
f |= ( o2[i1] == o1[j1] );
}
}
ans[x.se] = f;
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |