Submission #972252

# Submission time Handle Problem Language Result Execution time Memory
972252 2024-04-30T10:02:51 Z RaresFelix The Potion of Great Power (CEOI20_potion) C++17
0 / 100
129 ms 32076 KB
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
 
using namespace std;
 
using ii = pair<int, int>;
using vi = vector<int>;
 
int n;
int *H0, *A0, *B0;

int rad = 30;

struct SetRollback {
    vector<int> T, V;

    vector<vi> Snap;

    set<int> S;

    void update(int t, int v) {
        if(T.size() % rad == 0) {
            vi W;
            for(auto it : S) W.push_back(it);
            Snap.push_back(W);
        }

        T.push_back(t);
        V.push_back(v);

        if(S.count(v)) S.erase(v);
        else S.insert(v);

    }

    vi val(int t) {
        if(T.empty()) return vi();
        int st = 0, dr = int(T.size()) - 1, mij;
        while(st < dr) {
            mij = (st + dr + 1) / 2;
            if(T[mij] <= t) st = mij;
            else dr = mij - 1;
        }

        vi E = Snap[st / rad];
        set<int> SV;
        for(auto it : E) SV.insert(it);
        for(int i = st / rad * rad; i <= st; ++i) {
            int v = V[i];
            if(SV.count(v)) SV.erase(v);
            else SV.insert(v);
        }

        vi A;
        for(auto it : SV) A.push_back(it);
        return A;
    }
};

vector<SetRollback> V;
 
void init(int N, int D, int H[]) {
    n = N;
    H0 = H;
    V.resize(n);
}
 
 
void curseChanges(int U, int A[], int B[]) {
    A0 = A; B0 = B;
    for(int i = 0; i < n; ++i) {
        int a = A[i], b = B[i];
        V[a].update(i + 1, b);
        V[b].update(i + 1, a);
    }
}
 
const int INF = 1e9;
 
int question(int x, int y, int v) {
    vi X = V[x].val(v);
    vi Y = V[x].val(v);
    vi VA, VB;
    for(auto it : X) VA.push_back(H0[it]);
    for(auto it : Y) VB.push_back(H0[it]);

    int p1 = 0, p2 = 0;
    int re = INF;
    while(p1 < VA.size() && p2 < VB.size()) {
        re = min(re, abs(VB[p2] - VA[p1]));
        if(VA[p1] < VB[p2]) ++p1;
        else ++p2;
    }
    return re;
}

Compilation message

potion.cpp: In function 'int question(int, int, int)':
potion.cpp:90:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |     while(p1 < VA.size() && p2 < VB.size()) {
      |           ~~~^~~~~~~~~~~
potion.cpp:90:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |     while(p1 < VA.size() && p2 < VB.size()) {
      |                             ~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 760 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 129 ms 31828 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 122 ms 32076 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 4028 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -