제출 #493307

#제출 시각아이디문제언어결과실행 시간메모리
493307rainboyAutobahn (COI21_autobahn)C11
100 / 100
159 ms17452 KiB
#include <stdio.h> #define N 100000 long long min(long long a, long long b) { return a < b ? a : b; } long long max(long long a, long long b) { return a > b ? a : b; } unsigned int X = 12345; int rand_() { return (X *= 3) >> 1; } int *zz; void sort(int *ii, int l, int r) { while (l < r) { int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp; while (j < k) if (zz[ii[j]] == zz[i_]) j++; else if (zz[ii[j]] < zz[i_]) { tmp = ii[i], ii[i] = ii[j], ii[j] = tmp; i++, j++; } else { k--; tmp = ii[j], ii[j] = ii[k], ii[k] = tmp; } sort(ii, l, i); l = k; } } void accumulate(int *xx, int *dd, int n) { static int xx_[N * 2], dd_[N * 2], ii[N * 2]; int i; for (i = 0; i < n; i++) ii[i] = i; zz = xx, sort(ii, 0, n); for (i = 1; i < n; i++) dd[ii[i]] += dd[ii[i - 1]]; for (i = 0; i < n; i++) xx_[i] = xx[ii[i]], dd_[i] = dd[ii[i]]; for (i = 0; i < n; i++) xx[i] = xx_[i], dd[i] = dd_[i]; } int main() { static int ll[N], rr[N], cc[N], xx1[N * 2], dd1[N * 2], xx2[N * 2], dd2[N * 2], xx3[N * 8], dd3[N * 8], ii[N * 8]; int n, n1, n2, n3, k, len, i, i1, i2; long long ans, y, d; scanf("%d%d%d", &n, &k, &len); for (i = 0; i < n; i++) scanf("%d%d%d", &ll[i], &cc[i], &rr[i]); n1 = 0, n2 = 0; for (i = 0; i < n; i++) { xx1[n1] = ll[i], dd1[n1] = 1, n1++, xx1[n1] = rr[i] + 1, dd1[n1] = -1, n1++; if (ll[i] + cc[i] <= rr[i]) xx2[n2] = ll[i] + cc[i], dd2[n2] = 1, n2++, xx2[n2] = rr[i] + 1, dd2[n2] = -1, n2++; } accumulate(xx1, dd1, n1); accumulate(xx2, dd2, n2); i1 = 0, i2 = 0, n3 = 0; while (i1 + 1 < n1 && i2 + 1 < n2) { int l = max(xx1[i1], xx2[i2]), r = min(xx1[i1 + 1], xx2[i2 + 1]); if (l < r && dd1[i1] >= k && dd2[i2] > 0) { xx3[n3] = l - len, dd3[n3] = dd2[i2], n3++, xx3[n3] = l, dd3[n3] = -dd2[i2], n3++; xx3[n3] = r - len, dd3[n3] = -dd2[i2], n3++, xx3[n3] = r, dd3[n3] = dd2[i2], n3++; } if (xx1[i1 + 1] < xx2[i2 + 1]) i1++; else i2++; } for (i = 0; i < n3; i++) ii[i] = i; zz = xx3, sort(ii, 0, n3); ans = 0, y = 0, d = 0; for (i = 0; i + 1 < n3; i++) { d += dd3[ii[i]]; y += (long long) (xx3[ii[i + 1]] - xx3[ii[i]]) * d; ans = max(ans, y); } printf("%lld\n", ans); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

autobahn.c: In function 'main':
autobahn.c:55:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |  scanf("%d%d%d", &n, &k, &len);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
autobahn.c:57:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |   scanf("%d%d%d", &ll[i], &cc[i], &rr[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...