Submission #642903

# Submission time Handle Problem Language Result Execution time Memory
642903 2022-09-20T18:33:16 Z Vladth11 The Potion of Great Power (CEOI20_potion) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "

using namespace std;
typedef long long ll;
typedef pair <int, int> pii;

const int NMAX = 100001;
const int VMAX = NMAX * 100;
const int INF = 2e9;
const int MOD = 1000000007;
const int BLOCK = 447;
const int base = 117;
const int nr_of_bits = 24;
const int inv2 = 500000004;

int a[NMAX], n;
int u;
int cc = 0;
int l[VMAX];
int r[VMAX];
vector <int> v[VMAX];
int ok;
int root[NMAX];
vector <int> parcurgere[2];

void update(int node, int st, int dr, int a, int b, int val){
    if(a <= st && dr <= b){
        v[node].push_back(val);
        return;
    }
    int mid = (st + dr) / 2;
    if(a <= mid){
        if(l[node] == 0){
            l[node] = ++cc;
        }
        update(l[node], st, mid, a, b, val);
    }
    if(b > mid){
        if(r[node] == 0){
            r[node] = ++cc;
        }
        update(r[node], mid + 1, dr, a, b, val);
    }
}

void query(int node, int st, int dr, int aa){
    if(node == 0)
        return;
    for(auto x : v[node]){
        parcurgere[ok].push_back(a[x]);
    }
    int mid = (st + dr) / 2;
    if(aa <= mid)
        query(l[node], st, mid, aa);
    else
        query(r[node], mid + 1, dr, aa);
}

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

map <pii, int> mp;

void curseChanges(int U, int A[], int B[]) {
    u = U;
    for(int i = 0; i < U; i++){
        if(A[i] > B[i])
            swap(A[i], B[i]);
        pii x = {A[i], B[i]};
        if(mp[x] == 0)
            mp[x] = i + 1;
        else{
            update(root[x.first], 0, U, mp[x], i, x.second);
            update(root[x.second], 0, U, mp[x], i, x.first);
            mp[x] = 0;
        }
    }
    for(auto y : mp){
        pii x = y.first;
        if(mp[x] != 0){
            update(root[x.first], 0, U, mp[x], U, x.second);
            update(root[x.second], 0, U, mp[x], U, x.first);
        }
    }
}

int question(int x, int y, int v) {
    int minim = 1e9;
    ok = 0;
    parcurgere[ok].clear();
    query(root[x], 0, u, v);
    if(!parcurgere[ok].size()) return minim;
    ok = 1;
    parcurgere[ok].clear();
    query(root[y], 0, u, v);
    if(!parcurgere[ok].size()) return minim;
    sort(parcurgere[0].begin(), parcurgere[0].end());
    sort(parcurgere[1].begin(), parcurgere[1].end());
    int i = 0, j = 0;
    while(i < parcurgere[0].size() && j < parcurgere[1].size()){
        minim = min(minim, abs(parcurgere[0][i] - parcurgere[1][j]));
        if(parcurgere[0][i] < parcurgere[1][j])
            i++;
        else
            j++;
    }
    return minim;
}

int main() {
    int N, D, U, Q;
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cin >> N >> D >> U >> Q;

    int *F = new int[N];
    for (int i=0; i<N; i++)
        std::cin >> F[i];
    init(N, D, F);

    int *A = new int[U], *B = new int[U];
    for (int i=0; i<U; i++) {
        std::cin >> A[i] >> B[i];
    }
    curseChanges(U, A, B);

    bool correct = true;
    for (int i=0; i<Q; i++) {
        int X,Y,V,CorrectAnswer;
        std::cin >> X >> Y >> V;
        cout << question(X,Y,V) << endl;
    }

    return 0;
}

Compilation message

potion.cpp: In function 'int question(int, int, int)':
potion.cpp:108:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |     while(i < parcurgere[0].size() && j < parcurgere[1].size()){
      |           ~~^~~~~~~~~~~~~~~~~~~~~~
potion.cpp:108:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |     while(i < parcurgere[0].size() && j < parcurgere[1].size()){
      |                                       ~~^~~~~~~~~~~~~~~~~~~~~~
potion.cpp: In function 'int main()':
potion.cpp:137:19: warning: unused variable 'CorrectAnswer' [-Wunused-variable]
  137 |         int X,Y,V,CorrectAnswer;
      |                   ^~~~~~~~~~~~~
potion.cpp:135:10: warning: unused variable 'correct' [-Wunused-variable]
  135 |     bool correct = true;
      |          ^~~~~~~
/usr/bin/ld: /tmp/ccRzhrwy.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccDlc3Vx.o:potion.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status