제출 #638442

#제출 시각아이디문제언어결과실행 시간메모리
638442jiahngThe Potion of Great Power (CEOI20_potion)C++14
17 / 100
3096 ms45232 KiB
#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 = 1000; 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 (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); } } vi get_set(int x, int v){ // O((D+sqrtn)logD) 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; vi actl_ans; aFOR(i, ans) actl_ans.pb(H[i]); sort(all(actl_ans)); return actl_ans; } int question(int x, int y, int v) { //get_set(x, 9); //cout << '\n'; vi xst = get_set(x, v); vi yst = get_set(y, v); int ans = INF; aFOR(i, xst){ auto it = lbd(yst, i); if (it != yst.end()) ans = min(ans, *it - i); if (it != yst.begin()) ans = min(ans, abs(*(--it) - i)); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...