Submission #781921

#TimeUsernameProblemLanguageResultExecution timeMemory
781921TheSahibThe Big Prize (IOI17_prize)C++14
20 / 100
3017 ms6140 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(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() << 15) + 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) { srand(time(0)); vector<int> order(n); iota(order.begin(), order.end(), 1); random_shuffle(order.begin(), order.end()); if(n <= 5000){ for (int i:order) { vector<int> a = query(i); if(a[0] + a[1] == 0){ return i - 1; } } } vector<int> a; int cnt = 0; for (int i = 1; i <= 1000; i++) { a = query(i); if(a[0] + a[1] == 0) return i - 1; if(a[0] + a[1] < cnt){ update(i, 1); } cnt = max(cnt, a[0] + a[1]); } while(true){ int l = 1, r = n; while(l <= r){ int mid = (l + r) / 2; a = query(mid); if(a[0] + a[1] == 0){ return mid - 1; } a[0] -= ask(1, mid - 1); a[1] -= ask(mid + 1, n); if(a[0] + a[1] < cnt){ update(mid, 1); cnt--; break; } if(a[1] > 0){ l = mid + 1; } else{ r = mid - 1; } } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...