Submission #638442

# Submission time Handle Problem Language Result Execution time Memory
638442 2022-09-06T03:09:21 Z jiahng The Potion of Great Power (CEOI20_potion) C++14
17 / 100
3000 ms 45232 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 = 1000;
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 (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);        
    }
}

vi get_set(int x, int v){ // O((D+sqrtn)logD)
    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;
    vi actl_ans;
    aFOR(i, ans) actl_ans.pb(H[i]);
    sort(all(actl_ans));
    return actl_ans;
}
int question(int x, int y, int v) {
    //get_set(x, 9);
    //cout << '\n';
    vi xst = get_set(x, v);
    vi yst = get_set(y, v);
    int ans = INF;
    aFOR(i, xst){
        auto it = lbd(yst, 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 Correct 17 ms 32336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 32464 KB Output is correct
2 Correct 18 ms 32416 KB Output is correct
3 Correct 17 ms 32464 KB Output is correct
4 Correct 38 ms 36368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 178 ms 44120 KB Output is correct
2 Correct 184 ms 44128 KB Output is correct
3 Execution timed out 3012 ms 41608 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 172 ms 44128 KB Output is correct
2 Execution timed out 3070 ms 45232 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 58 ms 33096 KB Output is correct
2 Correct 265 ms 33100 KB Output is correct
3 Correct 2529 ms 33204 KB Output is correct
4 Execution timed out 3096 ms 33104 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 32336 KB Output is correct
2 Correct 17 ms 32464 KB Output is correct
3 Correct 18 ms 32416 KB Output is correct
4 Correct 17 ms 32464 KB Output is correct
5 Correct 38 ms 36368 KB Output is correct
6 Correct 178 ms 44120 KB Output is correct
7 Correct 184 ms 44128 KB Output is correct
8 Execution timed out 3012 ms 41608 KB Time limit exceeded
9 Halted 0 ms 0 KB -