//#pragma GCC optimize("O3")
#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];
const int C=8000, SZ=26; //size of block
set<int> ad[SZ][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, SZ) 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;
unordered_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 |
Correct |
64 ms |
122312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
122444 KB |
Output is correct |
2 |
Correct |
67 ms |
122480 KB |
Output is correct |
3 |
Correct |
60 ms |
122440 KB |
Output is correct |
4 |
Correct |
72 ms |
123328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
164 ms |
145140 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
191 ms |
145168 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
345 ms |
123528 KB |
Output is correct |
2 |
Correct |
546 ms |
122744 KB |
Output is correct |
3 |
Correct |
2083 ms |
122688 KB |
Output is correct |
4 |
Correct |
2556 ms |
123208 KB |
Output is correct |
5 |
Correct |
2401 ms |
123480 KB |
Output is correct |
6 |
Correct |
487 ms |
123500 KB |
Output is correct |
7 |
Execution timed out |
3031 ms |
122712 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
122312 KB |
Output is correct |
2 |
Correct |
58 ms |
122444 KB |
Output is correct |
3 |
Correct |
67 ms |
122480 KB |
Output is correct |
4 |
Correct |
60 ms |
122440 KB |
Output is correct |
5 |
Correct |
72 ms |
123328 KB |
Output is correct |
6 |
Incorrect |
164 ms |
145140 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |