제출 #1055139

#제출 시각아이디문제언어결과실행 시간메모리
1055139becaido마상시합 토너먼트 (IOI12_tournament)C++17
100 / 100
39 ms20776 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,popcnt,sse4,abm") #include <bits/stdc++.h> // #include "lib1275.h" using namespace std; const int N = 1e5 + 5; const int H = __lg(N); int n, m, x, sz, ans, mx; pair<int, int> seg[N << 1]; int a[N], l[N], r[N], pl[N], pr[N], id[N], to[H + 1][N << 1]; int bit[N]; inline void upd(int pos) { for (; pos <= n; pos += pos & -pos) bit[pos]--; } inline int que(int k) { int pos = 0, cnt = 0; for (int i = __lg(n); i >= 0; i--) { int nxt = pos + (1 << i); if (nxt <= n && cnt + bit[nxt] < k) cnt += bit[pos = nxt]; } return pos + 1; } int GetBestPosition(int _n, int _m, int _x, int _a[], int _l[], int _r[]) { n = _n, m = _m, x = _x + 1; for (int i = 1; i < n; i++) a[i] = _a[i - 1] + 1; for (int i = 1; i <= m; i++) l[i] = _l[i - 1] + 1, r[i] = _r[i - 1] + 1; for (int i = 1; i < n; i++) pl[i] = (a[i] > x ? i : pl[i - 1]); pr[n] = n; for (int i = n - 1; i >= 1; i--) pr[i] = (a[i] > x ? i : pr[i + 1]); sz = n; fill(bit + 1, bit + n + 1, 0); for (int i = 1; i <= n; i++) { bit[i]++; seg[id[i] = i] = {i, i}; to[0][i] = 0; if (i + (i & -i) <= n) bit[i + (i & -i)] += bit[i]; } for (int i = 1; i <= m; i++) { int L, R = que(r[i] + 1) - 1; to[0][++sz] = 0; seg[sz].second = R; for (int j = r[i]; j >= l[i]; j--) { L = que(j); to[0][id[L]] = sz; if (j > l[i]) upd(L); R = L - 1; } id[L] = sz; seg[sz].first = L; } for (int i = 1; i <= H; i++) for (int j = 1; j <= sz; j++) to[i][j] = to[i - 1][to[i - 1][j]]; ans = -1, mx = -1; for (int i = 1; i <= n; i++) { int L = pl[i - 1] + 1, R = pr[i], cnt = 0, pos = i; for (int j = H; j >= 0; j--) { int id = to[j][pos]; if (id && L <= seg[id].first && seg[id].second <= R) { cnt += 1 << j; pos = id; } } if (cnt > mx) { mx = cnt; ans = i - 1; } } return ans; }

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

tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:53:23: warning: 'L' may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |         seg[sz].first = L;
      |         ~~~~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...