Submission #974847

#TimeUsernameProblemLanguageResultExecution timeMemory
974847CookieThe Potion of Great Power (CEOI20_potion)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> #include<fstream> using namespace std; #define sz(a) (int)a.size() #define ALL(v) v.begin(), v.end() #define ALLR(v) v.rbegin(), v.rend() #define ll long long #define pb push_back #define forr(i, a, b) for(int i = a; i < b; i++) #define dorr(i, a, b) for(int i = a; i >= b; i--) #define ld long double #define vt vector #include<fstream> #define fi first #define se second #define pll pair<ll, ll> #define pii pair<int, int> #define mpp make_pair #define ull unsigned long long const ld PI = 3.14159265359, prec = 1e-9;; //using u128 = __uint128_t; //const int x[4] = {1, 0, -1, 0}; //const int y[4] = {0, -1, 0, 1}; const ll mod = 1e9 + 19972207, pr = 31; const int mxn = 2e5 + 5, mxq = 1e5 + 5, sq = 105, mxv = 64; //const int base = (1 <<18); const ll inf = 1e9, neg = -69420, inf2 = 1e14; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // have fun int n, D, u, q; vt<int>comp[mxn + 1]; vt<vt<int>>day[mxn + 1], height[mxn + 1]; int h[mxn + 1], qa[mxn + 1], qb[mxn + 1]; void find(vt<int>&v, vt<int>&he, int x){ int id = lower_bound(ALL(v), x) - v.begin(); int id2 = lower_bound(ALL(he), h[x]) - he.begin(); if(id == sz(v) || v[id] != x){ v.insert(v.begin() + id, x); he.insert(he.begin() + id2, h[x]); }else{ v.erase(v.begin() + id); he.erase(he.begin() + id2); } } int get(vt<int>&a, vt<int>&b){ //for(auto i: a)cout << i << " "; //cout << "\n"; //for(auto i: b)cout << i << " "; //cout << "\n"; if(sz(a) == 0 || sz(b) == 0)return(inf); int r = 0, ans = inf; for(int i = 0; i < sz(b); i++){ while(r < sz(a) && a[r] <= b[i]){ ans = min(ans, b[i] - a[r++]); } if(r != sz(a))ans = min(ans, a[r] - b[i]); } return(ans); } void lzupd(int a){ vt<int>nwd = day[a].back(), nwh = height[a].back(); for(int j = sz(comp[a]) - sq; j < sz(comp[a]); j++){ if(!j)continue; if(qa[comp[a][j]] == a){ find(nwd, nwh, qb[comp[a][j]]); }else if(qb[comp[a][j]] == a){ find(nwd, nwh, qa[comp[a][j]]); } } day[a].pb(nwd); height[a].pb(nwh); } vt<int>lzget(int x, int d){ int block = d / sq; vt<int>nwd = day[x][block], nwh = height[x][block]; for(int j = block * sq; j <= d; j++){ if(!j)continue; if(qa[comp[x][j]] == x){ find(nwd, nwh, qb[comp[x][j]]); }else if(qb[comp[x][j]] == x){ find(nwd, nwh, qa[comp[x][j]]); } } return(nwh); } void solve(){ cin >> n >> D >> u >> q; for(int i = 0; i < n; i++)cin >> h[i]; for(int i = 0; i < n; i++)comp[i].pb(0); vt<int>emp; for(int i = 0; i < n; i++){ day[i].pb(emp); height[i].pb(emp); } for(int i = 1; i <= u; i++){ int a, b; cin >> a >> b; qa[i] = a; qb[i] = b; comp[a].pb(i); comp[b].pb(i); if(sz(comp[a]) % sq == 0){ lzupd(a); }if(sz(comp[b]) % sq == 0){ lzupd(b); } } while(q--){ int x, y, u; cin >> x >> y >> u; int id = upper_bound(ALL(comp[x]), u) - comp[x].begin() - 1; int id2 = upper_bound(ALL(comp[y]), u) - comp[y].begin() - 1; vt<int>hx = lzget(x, id), hy = lzget(y, id2); //for(auto i: hx)cout << i << " "; //cout << "\n"; //for(auto j: hy)cout << j << ' '; cout << get(hx, hy) << endl; } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("TRILAND.inp", "r", stdin); //freopen("TRILAND.out", "w", stdout); int tt; tt = 1; while(tt--){ solve(); } return(0); }

Compilation message (stderr)

/usr/bin/ld: /tmp/cc5pwMwJ.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccnJl2iI.o:potion.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cc5pwMwJ.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