#include "werewolf.h"
#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include <bits/stdc++.h>
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define eb emplace_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;}
#define si(a) (ll)(a.size())
using namespace std;
using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pld = pair<ld,ld>;
const ll maxn = 200005;
ll n,m,q;
ll dsu[maxn];
ll root(ll x) {
while(x!=dsu[x]) {
dsu[x] = dsu[dsu[x]];
x = dsu[x];
}
return x;
}
void upd(ll x,ll y) {
y = root(y),x = root(x);
if(x>y) swap(x,y);
dsu[y] = x;
}
vector<ll> g[maxn];
map<pll,ll> mpl;
map<pll,ll> mpr;
vector<ll> ask[maxn];
std::vector<int> check_validity(int N, std::vector<int> X, std::vector<int> Y,
std::vector<int> S, std::vector<int> E,
std::vector<int> L, std::vector<int> R) {
n = N;
m = si(X);
for(ll i = 0;i<m;i++) {
ll x = X[i],y = Y[i];
x++; y++;
g[x].pb(y);
g[y].pb(x);
}
q = si(S);
for(ll i = 0;i<q;i++) {
L[i]++;
S[i]++;
ask[L[i]].pb(S[i]);
}
iota(dsu+1,dsu+1+n,1);
for(ll i = n;i>=1;i--) {
for(ll j : g[i]) {
if(j>=i) {
upd(i,j);
}
}
for(ll x : ask[i]) {
mpl[{i,x}] = root(x);
}
}
for(ll i = 1;i<=n;i++) ask[i].clear();
for(ll i = 0;i<q;i++) {
R[i]++;
E[i]++;
ask[R[i]].pb(E[i]);
}
iota(dsu+1,dsu+1+n,1);
for(ll i = 1;i<=n;i++) {
for(ll j : g[i]) {
if(j<=i) {
upd(i,j);
}
}
for(ll x : ask[i]) {
mpr[{i,x}] = root(x);
}
}
vector<int> ans;
for(ll i = 0;i<q;i++) {
ll x = mpr[{R[i],E[i]}];
ll y = mpl[{L[i],S[i]}];
ll tl = L[i],tr = R[i];
if(x>=tl&&y>=tl&&x<=tr&&y<=tr) ans.pb(1);
else ans.pb(0);
}
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... |