Submission #644875

# Submission time Handle Problem Language Result Execution time Memory
644875 2022-09-25T12:09:34 Z idas The Potion of Great Power (CEOI20_potion) C++11
0 / 100
401 ms 262144 KB
#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;
int n, d, u, h[MxN], a[2*MxN], b[2*MxN];

const int C=4000; //size of block
set<int> ad[51][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;
}
# Verdict Execution time Memory Grader output
1 Runtime error 372 ms 262144 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 379 ms 262144 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 378 ms 262144 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 395 ms 262144 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 401 ms 262144 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 372 ms 262144 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -