#include <bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); i++)
#define R(i, j, k) for(int i = (j); i >= (k); i--)
#define ll long long
#define sz(a) ((int) a.size())
#define all(a) a.begin(), a.end()
#define vi vector<int>
#define pb emplace_back
#define me(a, x) memset(a, x, sizeof(a))
#define fst first
#define snd second
#define ii pair<int,int>
using namespace std;
const int MAXN=1e5+1,MAXU=2e5+1,INF=1e9;
int h[MAXN],cnt[MAXN][2];
set<ii>evs[MAXN][2];
map<ii,int>parity;
void init(int N, int D, int H[]) {
L(i,0,N-1)h[i]=H[i];
L(i,0,N-1){
evs[i][0].insert({-1,0});
evs[i][1].insert({-1,0});
}
}
void curseChanges(int U, int A[], int B[]) {
L(i,0,U-1){
int a=A[i],b=B[i];
if(a>b)swap(a,b);
ii p={a,b};
parity[p]++;
if(parity[p]%2){
cnt[a][h[b]]++;
cnt[b][h[a]]++;
}else{
cnt[a][h[b]]--;
cnt[b][h[a]]--;
}
evs[a][h[b]].insert({i+1,cnt[a][h[b]]>0});
evs[b][h[a]].insert({i+1,cnt[b][h[a]]>0});
}
}
int question(int x, int y, int v) {
int ans=INF;
bool hasX=false,hasY=false;
for(int f:{0,1}) {
auto e1=prev(evs[x][f].upper_bound({v,-1}));
auto e2=prev(evs[y][f].upper_bound({v,-1}));
if(e1->snd)hasX=true;
if(e2->snd)hasY=true;
if(e1->snd&&e2->snd)ans=0;
}
if(!hasX||!hasY) return INF;
if(sz(evs[x][0])&&sz(evs[y][1])){
auto e1=evs[x][0].upper_bound({v,-1});
e1--;
auto e2=evs[y][1].upper_bound({v,-1});
e2--;
if(e1->snd==1&&e2->snd==1)ans=1;
}
if(sz(evs[x][1])&&sz(evs[y][0])){
auto e1=evs[x][1].upper_bound({v,-1});
e1--;
auto e2=evs[y][0].upper_bound({v,-1});
e2--;
if(e1->snd==1&&e2->snd==1)ans=1;
}
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... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |