답안 #972270

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
972270 2024-04-30T10:15:45 Z RaresFelix The Potion of Great Power (CEOI20_potion) C++17
0 / 100
3000 ms 45032 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 = 20;

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 < U; ++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[y].val(v);
    vi VA, VB;
    for(auto it : X) VA.push_back(H0[it]);
    for(auto it : Y) VB.push_back(H0[it]);
    sort(VA.begin(), VA.end());
    sort(VB.begin(), VB.end());

    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:92:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |     while(p1 < VA.size() && p2 < VB.size()) {
      |           ~~~^~~~~~~~~~~
potion.cpp:92:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |     while(p1 < VA.size() && p2 < VB.size()) {
      |                             ~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 764 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 339 ms 44900 KB Output is correct
2 Correct 315 ms 45032 KB Output is correct
3 Correct 233 ms 19204 KB Output is correct
4 Correct 2064 ms 26476 KB Output is correct
5 Correct 613 ms 30172 KB Output is correct
6 Execution timed out 3025 ms 44432 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 276 ms 44420 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 3500 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 764 KB Incorrect
3 Halted 0 ms 0 KB -