Submission #972499

# Submission time Handle Problem Language Result Execution time Memory
972499 2024-04-30T14:01:02 Z RaresFelix The Potion of Great Power (CEOI20_potion) C++17
0 / 100
108 ms 37484 KB
#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;
const int MN = 100000;
int n;
int H0[MN];

vector<pair<int, int> > Op[MN];
vi SnapId[MN];
vector<vi> Mare; 

void init(int N, int D, int H[]) {
    n = N;
    for(int i = 0; i < n; ++i)
        H0[i] = H[i];
}

int rad = 69;

void curseChanges(int U, int A[], int B[]) {
    for(int i = 0; i < U; ++i) {
        Op[A[i]].push_back({i + 1, B[i]});
        Op[B[i]].push_back({i + 1, A[i]});
    }

    for(int i = 0; i < n; ++i) {
        set<int> S;
        SnapId[i].push_back(Mare.size());
        Mare.emplace_back();
        for(int j = 0; j < Op[i].size(); ++j) {
            if(j % rad == 0 && j) {
                SnapId[i].push_back(Mare.size());
                Mare.emplace_back();
                Mare.back().reserve(S.size());
                for(auto it : S) Mare.back().push_back(it);
            }
            auto [t, v] = Op[i][j];
            if(S.count(v)) S.erase(v);
            else S.insert(v);
        }
    }
}
const int INF = 1e9;

set<int> get(int x, int v) {
    int st = 0, dr = int(Op[x].size()) - 1, mij;
    while(st < dr) {
        mij = (st + dr + 1) / 2;
        if(Op[x][mij].first > v) dr = mij - 1; // e ok asa?
        else st = mij;
    }
    set<int> S;
    for(auto it : Mare[SnapId[x][st / rad]])
        S.insert(it);
    for(int i = st / rad * rad; i <= st; ++i) {
        auto [t, v] = Op[x][i];
        if(S.count(v)) S.erase(v);
        else S.insert(v);
    }
    return S;
}

int question(int x, int y, int v) {
    auto VecX = get(x, v), VecY = get(y, v);
    vi VA, VB;
    for(auto it : VecX) VA.push_back(H0[it]);
    for(auto it : VecY) VB.push_back(H0[it]);
    sort(VA.begin(), VA.end());
    sort(VB.begin(), VB.end());
    int pa = 0, pb = 0;
    int re = INF;
    while(pa < VA.size() && pb < VB.size()) {
        re = min(re, abs(VA[pa] - VB[pb]));
        if(VA[pa] < VB[pb]) ++pa;
        else ++pb;
    }
    return re;
}

Compilation message

potion.cpp: In function 'void curseChanges(int, int*, int*)':
potion.cpp:32:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for(int j = 0; j < Op[i].size(); ++j) {
      |                        ~~^~~~~~~~~~~~~~
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:74:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     while(pa < VA.size() && pb < VB.size()) {
      |           ~~~^~~~~~~~~~~
potion.cpp:74:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     while(pa < VA.size() && pb < VB.size()) {
      |                             ~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 10136 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 93 ms 37484 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 108 ms 18672 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 17 ms 12100 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Runtime error 7 ms 10136 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -