Submission #612062

# Submission time Handle Problem Language Result Execution time Memory
612062 2022-07-29T10:31:24 Z 1bin The Potion of Great Power (CEOI20_potion) C++14
0 / 100
97 ms 26432 KB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define all(v) v.begin(), v.end()
const int NMAX = 1e5 + 5;
const int sqt = 50;
int n, d, u, q, h[NMAX], a, b, A[2 * NMAX], B[2 * NMAX];
vector<int> ix[NMAX], l, r;
vector<vector<pair<int, int>>> v[NMAX];

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

void chk(int x){
    int sz = ix[x].size();
    if(sz % sqt) return;
    set<pair<int, int>> s;
    if(--sz) for(auto& t : v[x].back()) s.emplace(t);
    for(int i = sz * sqt; i < sz * sqt + sqt; i++){
        int y = (A[ix[x][i]] == x) ? B[ix[x][i]] : A[ix[x][i]];
        if(s.find({h[y], y}) == s.end()) s.insert({h[y], y});
        else s.erase({h[y], y});
    }
    vector<pair<int, int>> tmp;
    for(auto t : s) tmp.emplace_back(t);
    v[x].emplace_back(tmp);
    return;
}

void curseChanges(int U, int A_[], int B_[]){
    u = U;
    for(int i = 0; i < u; i++) A[i] = A_[i], B[i] = B_[i];
    for(int i = 0; i < u; i++){
        a = A[i]; b = B[i];
        ix[a].emplace_back(i);
        ix[b].emplace_back(i);
        chk(a); chk(b);
    }
    return;
}

int question(int x, int y, int V){
    int ans = 1e9, xi, yi, xb, yb, hx, hy;
    int xsz = lower_bound(all(ix[x]), V) - ix[x].begin();
    int ysz = lower_bound(all(ix[y]), V) - ix[y].begin();
    xb = xsz / sqt; yb = ysz / sqt;
    if(xb >= 1) for(auto& t : v[x][xb - 1]) l.emplace_back(t.fi);
    if(yb >= 1) for(auto& t : v[y][yb - 1]) r.emplace_back(t.fi);
    for(int i = xb * sqt; i < xsz; i++) {
        int t = (A[ix[x][i]] == x) ? B[ix[x][i]] : A[ix[x][i]];
        l.emplace_back(h[t]);
    }
    for(int i = yb * sqt; i < ysz; i++) {
        int t = (A[ix[y][i]] == y) ? B[ix[y][i]] : A[ix[y][i]];
        l.emplace_back(h[t]);
    }
    xi = 0; yi = 0;
    while(xi < xsz && yi < ysz){
        ans = min(ans, abs(l[xi] - r[yi]));
        l[xi] < r[yi] ? xi++ : yi++;
    }
   l.clear(); r.clear();
    return ans;
}

Compilation message

potion.cpp: In function 'int question(int, int, int)':
potion.cpp:48:36: warning: unused variable 'hx' [-Wunused-variable]
   48 |     int ans = 1e9, xi, yi, xb, yb, hx, hy;
      |                                    ^~
potion.cpp:48:40: warning: unused variable 'hy' [-Wunused-variable]
   48 |     int ans = 1e9, xi, yi, xb, yb, hx, hy;
      |                                        ^~
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 9936 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 10120 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 85 ms 26388 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 97 ms 26432 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 16 ms 11036 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 9936 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -