#include<bits/stdc++.h>
using namespace std;
const int BL = 1000 , NN = 2e5 + 2;
vector<int> a , b , h;
queue<int> g[NN / BL + 2][NN];
set<int> gg[NN];
int n , d;
void init(int N, int D, int H[]) {
h = vector<int> (N , 0);
n = N , d = D;
for(int i = 0;i < n; ++ i) h[i] = H[i];
}
void curseChanges(int U, int A[], int B[]) {
for(int i = 0;i < U; ++ i){
if(A[i] > B[i]) swap(A[i] , B[i]);
a.push_back(A[i]);
b.push_back(B[i]);
if(gg[a[i]].find(b[i]) == gg[a[i]].end()){
gg[a[i]].insert(b[i]);
gg[b[i]].insert(a[i]);
}
else{
gg[a[i]].erase(b[i]);
gg[b[i]].erase(a[i]);
}
if((i + 1) % BL == 0){
for(int i = 0;i < n; ++ i){
for(auto to : gg[i]){
g[(i + 1) / BL][i].push(to);
}
}
}
}
}
int question(int x, int y, int v) {
if(x > y) swap(x , y);
v --;
unordered_set<int> vx , vy;
while(g[(v + 1) / BL][x].size()){
vx.insert(g[(v + 1) / BL][x].front());
g[(v + 1) / BL][x].pop();
}
while(g[(v + 1) / BL][y].size()){
vy.insert(g[(v + 1) / BL][y].front());
g[(v + 1) / BL][y].pop();
}
for(auto to : vx) g[(v + 1) / BL][x].push(to);
for(auto to : vy) g[(v + 1) / BL][y].push(to);
for(int i = (v + 1) / BL * BL;i <= v; ++ i){
//cout << i << ' ';
if(a[i] == x or b[i] == x){
int f = a[i] + b[i] - x;
if(! vx.count(f)) vx.insert(f);
else vx.erase(f);
}
if(a[i] == y or b[i] == y){
int f = a[i] + b[i] - y;
if(! vy.count(f)) vy.insert(f);
else vy.erase(f);
}
}
vector<int> hx , hy;
//cout << x << ' ' << y << ' ';
for(auto to : vx){
//cout << to << ' ';
hx.push_back(h[to]);
}
for(auto to : vy){
//cout << to << ' ';
hy.push_back(h[to]);
}
if(hx.size() == 0 or hy.size() == 0) return 1000000000;
sort(hx.begin() , hx.end());
sort(hy.begin() , hy.end());
int j = 0 , answ = 1e9;
for(auto to : hx){
while(j < hy.size() and hy[j] <= to) j ++;
answ = min({answ , abs(to - hy[max(0 , j - 1)]) , abs(to - hy[min(n - 1 , j)])});
}
return answ;
}
컴파일 시 표준 에러 (stderr) 메시지
/tmp/ccnLKN1q.o: in function `init(int, int, int*)':
potion.cpp:(.text+0x87d): relocation truncated to fit: R_X86_64_PC32 against symbol `h' defined in .bss section in /tmp/ccnLKN1q.o
potion.cpp:(.text+0x884): relocation truncated to fit: R_X86_64_PC32 against symbol `h' defined in .bss section in /tmp/ccnLKN1q.o
potion.cpp:(.text+0x88b): relocation truncated to fit: R_X86_64_PC32 against symbol `h' defined in .bss section in /tmp/ccnLKN1q.o
potion.cpp:(.text+0x892): relocation truncated to fit: R_X86_64_PC32 against symbol `h' defined in .bss section in /tmp/ccnLKN1q.o
potion.cpp:(.text+0x899): relocation truncated to fit: R_X86_64_PC32 against symbol `h' defined in .bss section in /tmp/ccnLKN1q.o
potion.cpp:(.text+0x8b3): relocation truncated to fit: R_X86_64_PC32 against symbol `h' defined in .bss section in /tmp/ccnLKN1q.o
/tmp/ccnLKN1q.o: in function `curseChanges(int, int*, int*)':
potion.cpp:(.text+0x9ab): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/ccnLKN1q.o
potion.cpp:(.text+0x9b2): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/ccnLKN1q.o
potion.cpp:(.text+0x9c9): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/ccnLKN1q.o
potion.cpp:(.text+0x9d0): relocation truncated to fit: R_X86_64_PC32 against symbol `b' defined in .bss section in /tmp/ccnLKN1q.o
potion.cpp:(.text+0x9d7): additional relocation overflows omitted from the output
/usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.a(ios_init.o): in function `std::ios_base::Init::Init()':
(.text._ZNSt8ios_base4InitC2Ev+0x1c): failed to convert GOTPCREL relocation against '_ZNSt8ios_base4Init11_S_refcountE'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x1c6): failed to convert GOTPCREL relocation against '_ZSt4cout'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x260): failed to convert GOTPCREL relocation against '_ZSt3cin'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x2e2): failed to convert GOTPCREL relocation against '_ZSt4cerr'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x353): failed to convert GOTPCREL relocation against '_ZSt4clog'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x541): failed to convert GOTPCREL relocation against '_ZSt5wcout'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x5e5): failed to convert GOTPCREL relocation against '_ZSt4wcin'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x670): failed to convert GOTPCREL relocation against '_ZSt5wcerr'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x6e9): failed to convert GOTPCREL relocation against '_ZSt5wclog'; relink with --no-relax
/usr/bin/ld: final link failed
collect2: error: ld returned 1 exit status