#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=1e5+10, MxU=2e5+10;
int n, d, u, h[MxN], a[MxU], b[MxU];
void init(int N, int D, int H[]) {
n=N; d=D; FOR(i, 0, n) h[i]=H[i];
}
const int C=50;
vector<pii> ad[MxN];
vector<set<int>> con[MxN]; // con[i][j] - all adj for each N, Blk
set<int> cur[MxN]; //temporary adj set to get groups
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)
{
ad[a[i]].pb({i,b[i]});
ad[b[i]].pb({i,a[i]});
}
FOR(i, 0, n)
{
FOR(j, 0, sz(ad[i]))
{
int x=ad[i][j].s;
if(j%C==0){
con[i].pb(cur[i]);
cur[i].clear();
}
if(cur[i].count(x)) cur[i].erase(x);
else cur[i].insert(x);
}
}
}
int question(int x, int y, int v) {
if(sz(ad[x])==0||sz(ad[y])==0) return INF;
auto it=upper_bound(all(ad[x]), pii({v-1,INF}));
it=prev(it);
int idx=it-ad[x].begin(); //idx of where last relevant pair is (how many changes x went through -1)
int blk=idx/C;
set<int> arx;
for(auto xx : con[x][blk]) arx.insert(xx);
FOR(i, blk*C, idx+1)
{
int val=ad[x][i].s;
if(arx.count(val)) arx.erase(val);
else arx.insert(val);
}
if(sz(arx)==0) return INF;
it=upper_bound(all(ad[y]), pii({v-1,INF}));
it=prev(it);
idx=it-ad[y].begin();
blk=idx/C;
set<int> ary;
for(auto xx : con[y][blk]) ary.insert(xx);
FOR(i, blk*C, idx+1)
{
int val=ad[y][i].s;
if(ary.count(val)) ary.erase(val);
else ary.insert(val);
}
if(sz(ary)==0) return INF;
vi arr, brr;
for(auto iter : arx) arr.pb(h[iter]);
for(auto iter : ary) brr.pb(h[iter]);
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;
}
/*
6 5 11 4
2 42 1000 54 68 234
0 1
2 0
3 4
3 5
3 5
1 3
5 3
0 5
3 0
1 3
3 5
0 3 4 26
3 0 8 0
0 5 5 1000000000
3 0 11 14
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9808 KB |
Output is correct |
2 |
Correct |
6 ms |
9936 KB |
Output is correct |
3 |
Correct |
6 ms |
9936 KB |
Output is correct |
4 |
Correct |
18 ms |
10792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
224 ms |
44572 KB |
Output is correct |
2 |
Correct |
235 ms |
44508 KB |
Output is correct |
3 |
Incorrect |
116 ms |
21096 KB |
Incorrect |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
126 ms |
44584 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
11772 KB |
Output is correct |
2 |
Incorrect |
17 ms |
10400 KB |
Incorrect |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9680 KB |
Output is correct |
2 |
Correct |
7 ms |
9808 KB |
Output is correct |
3 |
Correct |
6 ms |
9936 KB |
Output is correct |
4 |
Correct |
6 ms |
9936 KB |
Output is correct |
5 |
Correct |
18 ms |
10792 KB |
Output is correct |
6 |
Correct |
224 ms |
44572 KB |
Output is correct |
7 |
Correct |
235 ms |
44508 KB |
Output is correct |
8 |
Incorrect |
116 ms |
21096 KB |
Incorrect |
9 |
Halted |
0 ms |
0 KB |
- |