답안 #602174

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
602174 2022-07-22T16:17:38 Z Theo830 The Potion of Great Power (CEOI20_potion) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define ull unsigned ll
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
int main(void){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,d,u,q;
    cin>>n>>d>>u>>q;
    ll h[n];
    f(i,0,n){
        cin>>h[i];
    }
    const ll m = 450;
    set<ll>exo[n][(u / m) + 5];
    set<ll>cur[n];
    vector<ii>ar;
    f(i,0,u){
        ll a,b;
        cin>>a>>b;
        ar.pb({a,b});
        if(!cur[a].count(b)){
            cur[a].insert(b);
            cur[b].insert(a);
        }
        else{
            cur[a].erase(b);
            cur[b].erase(a);
        }
        if((i + 1) % m == 0){
            f(j,0,n){
                exo[j][(i + 1) / m] = cur[j];
            }
        }
    }
    ///memory complexity: O(U^2 / m)
    ///time complexity: O(U log D + Q * ((D + m) log D))
    ///m = sqrt(U)
    ///memory complexity: O(U sqrt U)
    ///time complexity: O(U log D + Q * (D + sqrt U) log D)
    while(q--){
        ll x,y,v;
        cin>>x>>y>>v;
        ll ans = 1e9;
        ll cur = (v / m) * m;
        set<ll>ex[2];
        vector<ii>kame;
        ex[0] = exo[x][cur / m];
        ex[1] = exo[y][cur / m];
        while(cur != v){
            if(ar[cur].F == x){
                if(ex[0].count(ar[cur].S)){
                    ex[0].erase(ar[cur].S);
                }
                else{
                    ex[0].insert(ar[cur].S);
                }
            }
            if(ar[cur].S == x){
                if(ex[0].count(ar[cur].F)){
                    ex[0].erase(ar[cur].F);
                }
                else{
                    ex[0].insert(ar[cur].F);
                }
            }
            if(ar[cur].F == y){
                if(ex[1].count(ar[cur].S)){
                    ex[1].erase(ar[cur].S);
                }
                else{
                    ex[1].insert(ar[cur].S);
                }
            }
            if(ar[cur].S == y){
                if(ex[1].count(ar[cur].F)){
                    ex[1].erase(ar[cur].F);
                }
                else{
                    ex[1].insert(ar[cur].F);
                }
            }
            cur++;
        }
        f(i,0,2){
            for(auto x:ex[i]){
                kame.pb(ii(h[x],i));
            }
        }
        sort(all(kame));
        f(i,0,(ll)kame.size()-1){
            if(kame[i].S != kame[i+1].S){
                ans = min(ans,kame[i+1].F - kame[i].F);
            }
        }
        cout<<ans<<endl;
    }
}

Compilation message

/usr/bin/ld: /tmp/ccrujf4P.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cckCvKbT.o:potion.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccrujf4P.o: in function `main':
grader.cpp:(.text.startup+0xec): undefined reference to `init(int, int, int*)'
/usr/bin/ld: grader.cpp:(.text.startup+0x184): undefined reference to `curseChanges(int, int*, int*)'
/usr/bin/ld: grader.cpp:(.text.startup+0x1d9): undefined reference to `question(int, int, int)'
collect2: error: ld returned 1 exit status