//gm --- akezhon
#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define tm (tl+tr)/2
#define TL v+v, tl, tm
#define TR v+v+1, tm+1, tr
#define DA l <= tl && tr <= r
#define NE r < tl || tr < l
#define double long double
// #define int long long
using namespace std;
const int N=2e5+7;
// const int mod=998244353;
const int inf=2e9;
int n, d, m;
int a[N], b[N], h[N];
map<pii,int>mp;
set<pii>t[N*4];
void init(int N, int D, int H[]){
n=N;
d=D;
for(int i=0; i < n; i++)h[i]=H[i];
}
void curseChanges(int U, int A[], int B[]){
m=U;
for(int i=0; i < m; i++)a[i]=A[i];
for(int i=0; i < m; i++)b[i]=B[i];
for(int i=0; i < m; i++)if(a[i]>b[i])swap(a[i],b[i]);
}
bool did_go;
vector<int>v1, v2;
void upd(int l, int r, pii x1, pii x2, int v=1, int tl=0, int tr=m){
if(DA){
t[v].insert(x1);
t[v].insert(x2);
return;
}
if(NE)return;
upd(l, r, x1, x2, TL);
upd(l, r, x1, x2, TR);
}
void get(int pos, int x1, int x2, int v=1, int tl=0, int tr=m){
auto it = t[v].lower_bound({x1, -inf});
while(it != t[v].end() && it->F == x1){
v1.pb(h[it->S]);
it=next(it);
}
it = t[v].lower_bound({x2, -inf});
while(it != t[v].end() && it->F == x2){
v2.pb(h[it->S]);
it=next(it);
}
if(tl==tr)return;
if(pos <= tm)get(pos, x1, x2, TL);
else get(pos, x1, x2, TR);
}
void go(){
if(did_go)return;
did_go=1;
set<pii>st;
for(int i=0; i < m; i++){
if(mp[{a[i],b[i]}] == 0)mp[{a[i],b[i]}]=i+1, st.insert({a[i], b[i]});
else {
upd(mp[{a[i],b[i]}], i, {a[i],b[i]}, {b[i],a[i]});
mp[{a[i], b[i]}]=0;
st.erase({a[i], b[i]});
}
}
for(auto [a, b] : st){
upd(mp[{a,b}], m, {a, b}, {b, a});
}
}
int mn(){
int cur=0, mnn=1e9;
if(v1.size()==0||v2.size()==0){
return mnn;
}
for(int i : v1){
while(v2[cur] < i && cur < v2.size()-1)cur++;
mnn=min(mnn, abs(i-v2[cur]));
if(cur)mnn=min(mnn, abs(i-v2[cur-1]));
}
return mnn;
}
int question(int X, int Y, int V){
go();
v1.clear();
v2.clear();
get(V, X, Y);
sort(all(v1));
sort(all(v2));
return mn();
}
// void AlemAmenov(){
// }
// signed main(){
// ios_base::sync_with_stdio(0);
// cin.tie(0);
// int RealName=1;
// cin >> RealName;
// freopen("newbarn.in", "r", stdin);
// freopen("newbarn.out", "w", stdout);
// while(RealName--){
// AlemAmenov();
// }
// return 0;
// }
# | 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... |