Submission #644882

# Submission time Handle Problem Language Result Execution time Memory
644882 2022-09-25T12:17:23 Z idas The Potion of Great Power (CEOI20_potion) C++11
17 / 100
3000 ms 145092 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, MxU=2e5+10;
int n, d, u, h[MxN], a[MxU], b[MxU];

const int C=8000; //size of block
set<int> ad[26][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, 26) 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 Correct 64 ms 122312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 122540 KB Output is correct
2 Correct 68 ms 122460 KB Output is correct
3 Correct 69 ms 122488 KB Output is correct
4 Correct 82 ms 123336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 162 ms 145068 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 162 ms 145092 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 409 ms 123540 KB Output is correct
2 Correct 640 ms 122772 KB Output is correct
3 Execution timed out 3099 ms 122648 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 64 ms 122312 KB Output is correct
2 Correct 75 ms 122540 KB Output is correct
3 Correct 68 ms 122460 KB Output is correct
4 Correct 69 ms 122488 KB Output is correct
5 Correct 82 ms 123336 KB Output is correct
6 Incorrect 162 ms 145068 KB Incorrect
7 Halted 0 ms 0 KB -