# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1159254 | gazizmadi11 | The Potion of Great Power (CEOI20_potion) | C++20 | 0 ms | 0 KiB |
//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=2e12;
int n, d, m;
vector<int>h, a, b;
set<int>st[N];
vector<int>vec[N];
void init(int N, int D, vector<int>H){
n=N;d=D;h=H;
}
void curseChanges(int M, vector<int>A, vector<int>B){
m=M;a=A;b=B;
}
bool did_go;
void go(){
if(did_go)return;
did_go=1;
for(int i=0; i < m; i++){
if(st[a[i]].find(b[i]) != st[a[i]].end()){
st[a[i]].erase(b[i]);
st[b[i]].erase(a[i]);
}
else{
st[a[i]].insert(b[i]);
st[b[i]].insert(a[i]);
}
}
for(int i=0; i < n; i++){
for(int j : st[i])vec[i].pb(h[j]);
sort(all(vec[i]));
}
}
int question(int x, int y, int v){
go();
int cur=0, mn=1e9;
for(int i : vec[x]){
while(vec[y][cur] < i && cur < vec[y].size()-1)cur++;
mn=min(mn, abs(i-vec[y][cur]));
if(cur)mn=min(mn, abs(i-vec[y][cur-1]));
}
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;
// }