Submission #671681

#TimeUsernameProblemLanguageResultExecution timeMemory
6716811binJousting tournament (IOI12_tournament)C++14
32 / 100
52 ms5280 KiB
#include <bits/stdc++.h> using namespace std; #define all(v) v.begin(), v.end() typedef long long ll; const int b = 1 << 17; int n, c, R, k[b], s[b], e[b], seg[b << 1], l, r, seg2[b << 1], p[b]; void upd(int ix){ ix += b; while(ix){ seg[ix]--; ix /= 2; } } int go(int k){ int ix = 1; while(ix < b){ ix <<= 1; if(seg[ix] < k) k -= seg[ix++]; } return ix - b; } int Max(int l, int r){ int ret = 0; l += b; r += b; while(l <= r){ if(l & 1) ret = max(ret, seg2[l++]); if(!(r & 1)) ret = max(ret,seg2[r--]); l /= 2; r /= 2; } return ret; } int GetBestPosition(int n, int c, int R, int k[], int s[], int e[]){ for(int i = 1; i <= n + 1; i++) seg[b + i] = 1, seg2[b + i] = k[i]; for(int i = b - 1; i; i--) { seg[i] = seg[i * 2] + seg[i * 2 + 1]; seg2[i] = max(seg2[i * 2], seg2[i * 2 + 1]); } for(int i = 0; i < c; i++){ l = go(++s[i]); r = go(++e[i] + 1) - 1; /*for(int i = 1; i <= n; i++) cout << seg[b + i] << ' '; cout << '\n'; cout << l << ' ' << r << '\n';*/ if(Max(l, r - 1) < R) p[l]++, p[r + 1]--; for(int j = 0; j < e[i] - s[i]; j++) upd(go(s[i] + 1)); } int idx, ret = -1; for(int i = 1; i <= n; i++){ p[i] += p[i - 1]; if(p[i] > ret) ret = p[i], idx = i; } return idx - 1; } /* int main(void){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> c >> r; for(int i = 1; i < n; i++) cin >> k[i]; for(int i = 0; i < c; i++) cin >> s[i] >> e[i]; cout << GetBestPosition(n, c, r, k, s, e); return 0; }*/

Compilation message (stderr)

tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:57:18: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   57 |     return idx - 1;
      |                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...