Submission #638440

# Submission time Handle Problem Language Result Execution time Memory
638440 2022-09-06T03:05:40 Z jiahng The Potion of Great Power (CEOI20_potion) C++14
17 / 100
3000 ms 48624 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
//#define int ll
typedef pair<int32_t, int32_t> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 200010
#define INF (ll)1e9
#define MOD 1000000007
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;

int H[maxn], N, D;
unordered_set <int> st[maxn][2];
vpi updates[maxn];
int last[maxn];

const int sqrtn = 500;
vpi sets[maxn];
void init(int N, int D, int H[]) {
    ::N = N; ::D = D;
    FOR(i,0,N-1) ::H[i] = H[i];
    FOR(i,0,N-1){
        sets[i].pb(pi(pi(-1,-1)));
    }
    mem(last, -1);
}

void update(int x,int v, int t, int tt){
    if (x == 3 && t == 9) cout << "AAAA" << last[x] << ' ' << updates[x].size() << '\n';
    if (updates[x].size() - last[x] == sqrtn){
        if (last[x] != -1 && updates[x][last[x]] != pi(-1,-1)) aFOR(j, st[updates[x][last[x]].f][updates[x][last[x]].s]) st[t][tt].insert(j);
        FOR(i, last[x] + 1, updates[x].size() - 1){
            int y = -updates[x][i].s; // index of person
            assert(y >= 0);
            if (st[t][tt].find(y) == st[t][tt].end()) st[t][tt].insert(y);
            else st[t][tt].erase(y);
        }
        if (st[t][tt].find(v) == st[t][tt].end()) st[t][tt].insert(v);
        else st[t][tt].erase(v);
        updates[x].pb(pi(t, tt));
        sets[x].pb(pi(t, updates[x].size() - 1));
        last[x] = updates[x].size() - 1;
    }else updates[x].pb(pi(t, -v));
}

void curseChanges(int U, int A[], int B[]) {
    FOR(i,0,U-1){
        update(A[i], B[i], i+1, 0);
        update(B[i], A[i], i+1, 1);        
    }
}

set <int> get_set(int x, int v){
    int idx = (--ubd(sets[x], pi(v, INF)))->s;
    set <int> ans;
    if (idx != -1){
        pi t = updates[x][idx];
        assert(t.s == 0 || t.s == 1);
        //cout << "t " << t.f << '\n';
        if (t.f != -1) aFOR(i, st[t.f][t.s]) ans.insert(i);
    }

    for (int i = idx + 1; i < (int)updates[x].size() && updates[x][i].f <= v; i++){
        int z = -updates[x][i].s;
        assert(z >= 0);
        if (ans.find(z) == ans.end()) ans.insert(z);
        else ans.erase(z);
    }
    /*
    cout << "SET " << x << ' ' << v << '\n';
    aFOR(i, ans) cout << i << ' ';
    cout << "\n";
    */
    //return ans;
    set <int> actl_ans;
    aFOR(i, ans) actl_ans.insert(H[i]);
    return actl_ans;
}
int question(int x, int y, int v) {
    //get_set(x, 9);
    //cout << '\n';
    set <int> xst = get_set(x, v);
    set <int> yst = get_set(y, v);
    int ans = INF;
    aFOR(i, xst){
        auto it = yst.lower_bound(i);
        if (it != yst.end()) ans = min(ans, *it - i);
        if (it != yst.begin()) ans = min(ans, abs(*(--it) - i));
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 32336 KB Expected integer, but "AAAA-1" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 32432 KB Output is correct
2 Correct 18 ms 32440 KB Output is correct
3 Correct 18 ms 32496 KB Output is correct
4 Correct 32 ms 36296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 200 ms 44124 KB Output is correct
2 Correct 193 ms 44088 KB Output is correct
3 Correct 1772 ms 41988 KB Output is correct
4 Execution timed out 3085 ms 38600 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 175 ms 44188 KB Output is correct
2 Execution timed out 3061 ms 48624 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 67 ms 33228 KB Output is correct
2 Correct 317 ms 33124 KB Output is correct
3 Correct 1665 ms 33208 KB Output is correct
4 Execution timed out 3098 ms 33232 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 32336 KB Expected integer, but "AAAA-1" found
2 Halted 0 ms 0 KB -