#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define sz(x) ((int)((x).size()))
#define le(vec) vec[vec.size()-1]
#define all(x) (x).begin(), (x).end()
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;
const int INF=1e9, MOD=1e9+7, mod=998244353;
const ll LINF=1e18;
const int MxN=2e5+10;
int n, d, u, h[MxN], a[MxN], b[MxN];
const int C=4000; //size of block
set<int> ad[52][MxN]; //adjacency list for each block
void init(int N, int D, int H[]) {
n=N; d=D; FOR(i, 0, n) h[i]=H[i];
FOR(i, 0, 52) FOR(j, 0, MxN) ad[i][j].clear();
}
void curseChanges(int U, int A[], int B[]) {
u=U; FOR(i, 0, u) a[i]=A[i], b[i]=B[i];
FOR(i, 0, u)
{
int blk=i/C; ++blk;
if(ad[blk][a[i]].count(b[i])) ad[blk][a[i]].erase(b[i]);
else ad[blk][a[i]].insert(b[i]);
if(ad[blk][b[i]].count(a[i])) ad[blk][b[i]].erase(a[i]);
else ad[blk][b[i]].insert(a[i]);
}
}
int question(int x, int y, int v) {
if(v==0) return INF;
--v;
set<int> ar, br; //adjacency for x, y
int blk=v/C;
for(auto it : ad[blk][x]){
ar.insert(it);
}
for(auto it : ad[blk][y]){
br.insert(it);
}
int blk_end=blk*C;
FOR(i, blk_end, v+1)
{
if(a[i]==x){
if(ar.count(b[i])) ar.erase(b[i]);
else ar.insert(b[i]);
}
if(b[i]==x){
if(ar.count(a[i])) ar.erase(a[i]);
else ar.insert(a[i]);
}
if(a[i]==y){
if(br.count(b[i])) br.erase(b[i]);
else br.insert(b[i]);
}
if(b[i]==y){
if(br.count(a[i])) br.erase(a[i]);
else br.insert(a[i]);
}
}
vi arr, brr;
for(auto it : ar) arr.pb(h[it]);
for(auto it : br) brr.pb(h[it]);
sort(all(arr)); sort(all(brr));
if(sz(arr)==0 || sz(brr)==0) return INF;
int ret=INF;
for(int i=0, j=0; i<sz(arr); i++){
while(j+1<sz(brr) && abs(arr[i]-brr[j])>abs(arr[i]-brr[j+1])) j++;
ret=min(ret, abs(arr[i]-brr[j]));
}
return ret;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
113 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
103 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
109 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
97 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
97 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
113 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |