Submission #243162

#TimeUsernameProblemLanguageResultExecution timeMemory
243162VEGAnnSvjetlost (COI18_svjetlost)C++14
69 / 100
1483 ms52436 KiB
#include <bits/stdc++.h> #define sz(x) ((int)x.size()) #define all(x) x.begin(),x.end() #define PB push_back using namespace std; typedef long double ld; const int N = 400100; const ld E = 1e-9; const ld pi = 3.1415926535897; vector<ld> vc; int n, pr[N], nt[N], x[N], y[N], nm[N], q; ld st[4 * N], psh[4 * N]; ld sqr(ld xx) { return xx * xx;} ld dist(ld x1, ld y1, ld x2, ld y2){ return sqrt(sqr(x1 - x2) + sqr(y1 - y2)); } void add(int i, int j){ ld nw_x = x[j] - x[i]; ld nw_y = y[j] - y[i]; ld ang = atan2(nw_y, nw_x); if (ang < 0) ang += pi + pi; vc.PB(ang); ang += pi; if (ang >= pi + pi) ang -= pi + pi; vc.PB(ang); } void push(int v){ if (psh[v] != 0){ st[v] += psh[v]; if (v + v + 1 < 4 * N){ psh[v + v] += psh[v]; psh[v + v + 1] += psh[v]; } psh[v] = 0; } } void update(int v, int tl, int tr, int l, int r, ld val){ push(v); if (l > r) return; if (tl == l && tr == r) { psh[v] += val; push(v); return; } int md = (tl + tr) >> 1; update(v + v, tl, md, l, min(r, md), val); update(v + v + 1, md + 1, tr, max(md + 1, l), r, val); st[v] = max(st[v + v], st[v + v + 1]); } void add_seg(int i, int j, ld val){ ld nw_x = x[j] - x[i]; ld nw_y = y[j] - y[i]; ld ang = atan2(nw_y, nw_x); if (ang < 0) ang += pi + pi; int lf = lower_bound(all(vc), ang - E) - vc.begin(); ang += pi; if (ang >= pi + pi) ang -= pi + pi; int rt = lower_bound(all(vc), ang - E) - vc.begin() - 1; if (vc[rt] + E > ang) { rt--; if (rt < 0) rt = sz(vc) - 1; } if (rt < 0) rt = sz(vc) - 1; // cerr << lf << " " << rt << '\n'; if (lf <= rt){ update(1, 0, sz(vc) - 1, lf, rt, val); } else { update(1, 0, sz(vc) - 1, lf, sz(vc) - 1, val); update(1, 0, sz(vc) - 1, 0, rt, val); } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #ifdef _LOCAL freopen("in.txt","r",stdin); #endif // _LOCAL cin >> n; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; pr[i] = (i - 1 + n) % n; nt[i] = (i + 1) % n; } for (int i = 0; i < n; i++) add(i, nt[i]); cin >> q; for (int i = 0; i < q; i++){ cin >> nm[i]; nm[i]--; int id = nm[i]; pr[nt[id]] = pr[id]; nt[pr[id]] = nt[id]; add(pr[id], nt[id]); } vc.PB(0); vc.PB(pi + pi); sort(all(vc)); // int cnt = 1; // // for (int i = 1; i < sz(vc); i++) // if (abs(vc[i] - vc[i - 1]) > E) // vc[cnt++] = vc[i]; // // vc.resize(cnt); for (int i = 0; i < n; i++){ pr[i] = (i - 1 + n) % n; nt[i] = (i + 1) % n; add_seg(i, nt[i], dist(x[i], y[i], x[nt[i]], y[nt[i]])); } cout << fixed << setprecision(10) << st[1] << '\n'; for (int i = 0; i < q; i++){ int id = nm[i]; add_seg(pr[id], id, -dist(x[pr[id]], y[pr[id]], x[id], y[id])); add_seg(id, nt[id], -dist(x[id], y[id], x[nt[id]], y[nt[id]])); pr[nt[id]] = pr[id]; nt[pr[id]] = nt[id]; add_seg(pr[id], nt[id], dist(x[pr[id]], y[pr[id]], x[nt[id]], y[nt[id]])); cout << fixed << setprecision(10) << st[1] << '\n'; } return 0; }
#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...