Submission #781940

#TimeUsernameProblemLanguageResultExecution timeMemory
781940TheSahibThe Big Prize (IOI17_prize)C++14
92.88 / 100
90 ms16240 KiB
#include "prize.h" #include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 5; int tree[MAX]; void update(int pos, int val){ while(pos < MAX){ tree[pos] += val; pos += pos & (-pos); } } int ask(int l, int r){ if(r < l) return 0; if(l != 1) return ask(1, r) - ask(1, l - 1); int ans = 0; while(r > 0){ ans += tree[r]; r -= r & (-r); } return ans; } int intRand(){ return (rand() << 14) | rand(); } vector<int> mp[MAX]; vector<int> query(int i){ if(!mp[i].empty()) return mp[i]; return mp[i] = ask(i - 1); } int find_best(int n) { vector<int> order(n); srand(time(0)); iota(order.begin(), order.end(), 1); random_shuffle(order.begin(), order.end()); vector<int> a; int cnt = 0; set<int> st; for (int i = 0; i < n; i++) { st.insert(i + 1); } for (int j = 0; j < min(1000, (int)order.size()); ++j) { int i = order[j]; a = query(i); if(a[0] + a[1] == 0) return i - 1; if(a[0] + a[1] < cnt){ update(i, 1); st.erase(i); } else{ cnt = a[0] + a[1]; } } for(int j = 0; j <= cnt; ++j){ int l = 1, r = n; while(l <= r){ int x = (l + r) / 2; auto itr = st.lower_bound(x); if(itr == st.end() || *itr > r){ --itr; } int mid = *itr; a = query(mid); if(a[0] + a[1] == 0){ return mid - 1; } if(a[0] + a[1] < cnt && !ask(mid, mid)){ update(mid, 1); st.erase(mid); break; } a[0] -= ask(1, mid - 1); a[1] -= ask(mid + 1, n); if(a[1] > 0){ l = mid + 1; } else{ r = mid - 1; } } } }

Compilation message (stderr)

prize.cpp: In function 'int find_best(int)':
prize.cpp:41:24: warning: control reaches end of non-void function [-Wreturn-type]
   41 |     vector<int> order(n);
      |                        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...