Submission #490092

#TimeUsernameProblemLanguageResultExecution timeMemory
490092rainboySvjetlost (COI18_svjetlost)C++17
100 / 100
545 ms31100 KiB
#include <math.h> #include <stdio.h> #define N 100000 #define M (N * 8) #define N_ (1 << 21) /* N_ = pow2(ceil(log2(M * 2))) */ double max(double a, double b) { return a > b ? a : b; } unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } int xx[N], yy[N], n; long long cross(int x1, int y1, int x2, int y2) { return (long long) x1 * y2 - (long long) x2 * y1; } int xx_[M * 2], yy_[M * 2], hh[M * 2], ii[M * 2], m; void add(int i, int j) { int h = m++; xx_[h << 1 | 0] = xx[i] - xx[j], yy_[h << 1 | 0] = yy[i] - yy[j]; xx_[h << 1 | 1] = xx[j] - xx[i], yy_[h << 1 | 1] = yy[j] - yy[i]; } int compare(int h1, int h2) { int sgn1, sgn2; long long c; sgn1 = xx_[h1] < 0 || xx_[h1] == 0 && yy_[h1] < 0 ? -1 : 1; sgn2 = xx_[h2] < 0 || xx_[h2] == 0 && yy_[h2] < 0 ? -1 : 1; if (sgn1 != sgn2) return sgn1 - sgn2; c = cross(xx_[h1], yy_[h1], xx_[h2], yy_[h2]); return c == 0 ? 0 : c < 0 ? -1 : 1; } void sort(int *hh, int l, int r) { while (l < r) { int i = l, j = l, k = r, h = hh[l + rand_() % (r - l)], tmp; while (j < k) { int c = compare(hh[j], h); if (c == 0) j++; else if (c < 0) { tmp = hh[i], hh[i] = hh[j], hh[j] = tmp; i++, j++; } else { k--; tmp = hh[j], hh[j] = hh[k], hh[k] = tmp; } } sort(hh, l, i); l = k; } } double sum[N_ * 2], pref[N_ * 2]; int n_; void pul(int i) { int l = i << 1, r = l | 1; sum[i] = sum[l] + sum[r]; pref[i] = max(pref[l], sum[l] + pref[r]); } void update_(int i, double x) { i += n_; pref[i] = sum[i] += x; while (i > 1) pul(i >>= 1); } void update(int h, int w) { int h0 = h << 1, h1 = h0 | 1; double d = hypot(xx_[h0], yy_[h0]); update_(ii[h0], d * w), update_(ii[h1], -d * w); if (ii[h0] > ii[h1]) update_(0, d * w); } int main() { static int uu[N], vv[N]; int q, h, i; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d%d", &xx[i], &yy[i]); for (i = 0; i < n; i++) uu[i] = (i - 1 + n) % n, vv[i] = (i + 1) % n; for (i = 0; i < n; i++) add(i, vv[i]); scanf("%d", &q); for (h = 0; h < q; h++) { int u, v; scanf("%d", &i), i--; u = uu[i], v = vv[i]; add(u, i), add(i, v), add(u, v); vv[u] = v, uu[v] = u; } for (h = 0; h < m * 2; h++) hh[h] = h; sort(hh, 0, m * 2); for (h = 0, n_ = 0; h < m * 2; h++) ii[hh[h]] = h + 1 == m * 2 || compare(hh[h + 1], hh[h]) != 0 ? n_++ : n_; while ((n_ & n_ - 1) != 0) n_++; for (h = 0; h < n; h++) update(h, 1); printf("%f\n", pref[1]); for (h = 0; h < q; h++) { update(n + h * 3 + 0, -1), update(n + h * 3 + 1, -1), update(n + h * 3 + 2, 1); printf("%f\n", pref[1]); } return 0; }

Compilation message (stderr)

svjetlost.cpp: In function 'int compare(int, int)':
svjetlost.cpp:35:37: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   35 |  sgn1 = xx_[h1] < 0 || xx_[h1] == 0 && yy_[h1] < 0 ? -1 : 1;
      |                        ~~~~~~~~~~~~~^~~~~~~~~~~~~~
svjetlost.cpp:36:37: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   36 |  sgn2 = xx_[h2] < 0 || xx_[h2] == 0 && yy_[h2] < 0 ? -1 : 1;
      |                        ~~~~~~~~~~~~~^~~~~~~~~~~~~~
svjetlost.cpp: In function 'int main()':
svjetlost.cpp:115:18: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
  115 |  while ((n_ & n_ - 1) != 0)
      |               ~~~^~~
svjetlost.cpp:94:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
svjetlost.cpp:96:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |   scanf("%d%d", &xx[i], &yy[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
svjetlost.cpp:101:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |  scanf("%d", &q);
      |  ~~~~~^~~~~~~~~~
svjetlost.cpp:105:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |   scanf("%d", &i), i--;
      |   ~~~~~^~~~~~~~~~
#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...