제출 #1230344

#제출 시각아이디문제언어결과실행 시간메모리
1230344ansoriThe Potion of Great Power (CEOI20_potion)C++17
100 / 100
1945 ms39008 KiB
#include<bits/stdc++.h> #define fi first #define se second using namespace std; const int BL = 50, UU = 2e5 , NN = 1e5; vector<int> a , b , h; vector<pair<int , int>> f[NN]; vector<vector<int>> k[NN]; set<int> gg[NN]; int n , d; void init(int N, int D, int H[]) { h = vector<int> (N , 0); n = N , d = D; for(int i = 0;i < n; ++ i) h[i] = H[i]; } void curseChanges(int U, int A[], int B[]) { for(int i = 0;i < U; ++ i){ if(A[i] > B[i]) swap(A[i] , B[i]); a.push_back(A[i]); b.push_back(B[i]); if(gg[a[i]].find(b[i]) == gg[a[i]].end()){ gg[a[i]].insert(b[i]); gg[b[i]].insert(a[i]); } else{ gg[a[i]].erase(b[i]); gg[b[i]].erase(a[i]); } f[a[i]].push_back({b[i] , i}); if(int(f[a[i]].size()) % BL == 0){ vector<int> pf; for(auto to : gg[a[i]]) pf.push_back(to); pf.push_back(i); k[a[i]].push_back(pf); } f[b[i]].push_back({a[i] , i}); if(int(f[b[i]].size()) % BL == 0){ vector<int> pf; for(auto to : gg[b[i]]) pf.push_back(to); pf.push_back(i); k[b[i]].push_back(pf); } } } bool us[NN]; int question(int x, int y, int v) { v --; int j = 0 , px = 0 , py = 0; vector<int> vx , vy , hx , hy; while(j < k[x].size() and v >= k[x][j].back()) j ++; if(j > 0){ for(int i = 0;i < k[x][j - 1].size() - 1; ++ i){ us[k[x][j - 1][i]] = 1; vx.push_back(k[x][j - 1][i]); } px = j * BL; } while(px < f[x].size() and v >= f[x][px].se){ int z = f[x][px].fi; us[z] ^= 1; vx.push_back(z); px ++; } for(auto to : vx){ if(us[to]) hx.push_back(h[to]); us[to] = 0; } j = 0; while(j < k[y].size() and v >= k[y][j].back()) j ++; if(j > 0){ for(int i = 0;i < k[y][j - 1].size() - 1; ++ i){ us[k[y][j - 1][i]] = 1; vy.push_back(k[y][j - 1][i]); } py = j * BL; } while(py < f[y].size() and v >= f[y][py].se){ int z = f[y][py].fi; us[z] ^= 1; vy.push_back(z); py ++; } for(auto to : vy){ if(us[to]) hy.push_back(h[to]); us[to] = 0; } if(hx.size() == 0 or hy.size() == 0) return 1000000000; sort(hx.begin() , hx.end()); sort(hy.begin() , hy.end()); int answ = 1e9 , s = hy.size(); j = 0; for(auto to : hx){ //cout << to << ' '; while(j < s and hy[j] <= to) j ++; answ = min({answ , abs(to - hy[max(0 , j - 1)]) , abs(to - hy[min(s - 1 , j)])}); } return answ; }
#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...