Submission #638439

# Submission time Handle Problem Language Result Execution time Memory
638439 2022-09-06T03:05:19 Z jiahng The Potion of Great Power (CEOI20_potion) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
//#define int ll
typedef pair<int32_t, int32_t> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 200010
#define INF (ll)1e9
#define MOD 1000000007
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;

int H[maxn], N, D;
unordered_set <int> st[maxn][2];
vpi updates[maxn];
int last[maxn];

const int sqrtn = 500;
vpi sets[maxn];
void init(int N, int D, int H[]) {
    ::N = N; ::D = D;
    FOR(i,0,N-1) ::H[i] = H[i];
    FOR(i,0,N-1){
        sets[i].pb(pi(pi(-1,-1)));
    }
    mem(last, -1);
}

void update(int x,int v, int t, int tt){
    if (x == 3 && t == 9) cout << "AAAA" << last[x] << ' ' << updates[x].size() << '\n';
    if (updates[x].size() - last[x] == sqrtn){
        if (last[x] != -1 && updates[x][last[x]] != pi(-1,-1)) aFOR(j, st[updates[x][last[x]].f][updates[x][last[x]].s]) st[t][tt].insert(j);
        FOR(i, last[x] + 1, updates[x].size() - 1){
            int y = -updates[x][i].s; // index of person
            assert(y >= 0);
            if (st[t][tt].find(y) == st[t][tt].end()) st[t][tt].insert(y);
            else st[t][tt].erase(y);
        }
        if (st[t][tt].find(v) == st[t][tt].end()) st[t][tt].insert(v);
        else st[t][tt].erase(v);
        updates[x].pb(pi(t, tt));
        sets[x].pb(pi(t, updates[x].size() - 1));
        last[x] = updates[x].size() - 1;
    }else updates[x].pb(pi(t, -v));
}

void curseChanges(int U, int A[], int B[]) {
    FOR(i,0,U-1){
        update(A[i], B[i], i+1, 0);
        update(B[i], A[i], i+1, 1);        
    }
}

set <int> get_set(int x, int v){
    int idx = (--ubd(sets[x], pi(v, INF)))->s;
    set <int> ans;
    if (idx != -1){
        pi t = updates[x][idx];
        assert(t.s == 0 || t.s == 1);
        //cout << "t " << t.f << '\n';
        if (t.f != -1) aFOR(i, st[t.f][t.s]) ans.insert(i);
    }

    for (int i = idx + 1; i < (int)updates[x].size() && updates[x][i].f <= v; i++){
        int z = -updates[x][i].s;
        assert(z >= 0);
        if (ans.find(z) == ans.end()) ans.insert(z);
        else ans.erase(z);
    }
    /*
    cout << "SET " << x << ' ' << v << '\n';
    aFOR(i, ans) cout << i << ' ';
    cout << "\n";
    */
    //return ans;
    set <int> actl_ans;
    aFOR(i, ans) actl_ans.insert(H[i]);
    return actl_ans;
}
int question(int x, int y, int v) {
    //get_set(x, 9);
    //cout << '\n';
    set <int> xst = get_set(x, v);
    set <int> yst = get_set(y, v);
    int ans = INF;
    aFOR(i, xst){
        auto it = yst.lower_bound(i);
        if (it != yst.end()) ans = min(ans, *it - i);
        if (it != yst.begin()) ans = min(ans, abs(*(--it) - i));
    }
    return ans;
}
#include <bits/stdc++.h>
void init(int N, int D, int F[]);
void curseChanges(int U, int A[], int B[]);
int question(int X, int Y, int V);

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;
    std::cin >> X >> Y >> V;
    int YourAnswer = question(X,Y,V);
    cout << YourAnswer << '\n';
  }

  if (correct) {
    std::cout << "Correct." << std::endl;
  } else std::cout << "Incorrect." << std::endl;
  return 0;
}

Compilation message

/usr/bin/ld: /tmp/cc9YGT7J.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccT7Ta8M.o:potion.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status