제출 #512900

#제출 시각아이디문제언어결과실행 시간메모리
512900kevinxiehk커다란 상품 (IOI17_prize)C++17
20 / 100
203 ms13184 KiB
#include "prize.h" #include "bits/stdc++.h" using namespace std; int ddd = 1; int fen[200005][10]; int corr[10]; int n; unordered_map<int, int> aaa; void add(int id, int x, int k) { id++; while(id <= n) { fen[id][k] += x; id += (id & (-id)); } } int sum(int id, int k) { int ans = 0; id++; while(id > 0) { ans += fen[id][k]; id -= (id & (-id)); } return ans; } int getbefore(int id, int k) { int t = 0; for(int i = 1; i < ddd; i++) { if(corr[i] < k) t += sum(id, i); } return t; } void add_val(int a, int k) { if(aaa[k] == 0) {corr[ddd] = k; aaa[k] = ddd++;} add(a, 1, aaa[k]); } bool vi[200005]; vector<int> store[200005]; int now = 0; int dx = 0; int sign = 1; vector<int> aa(int t) { cerr << t << '\n'; if(vi[t]) { return store[t]; // int k = 0; // while((t - k < 0 ||vi[t - k]) && (t + k >= n || vi[t + k])) k++; // if(t - k >= 0 && !vi[t - k]) now = t = t - k; // else now = t = t + k; } now++; assert(now <= 10000); // vi[t] = true; return store[t] = ask(t); } int ans = -1; int ll = 0, rr = n - 1; void solve(int l, int r) { cerr << l << ' ' << r << '\n'; if(l > r) return; int m = (l + r) / 2; vector<int> res = aa(m); if(res[0] + res[1] == 0) {ans = m; return;} if(!vi[m]) add_val(m, res[0] + res[1]); vi[m] = true; if(res[1] == 0) rr = m - 1; // if(l == r) { // ll = m + 1; // return; // } if(res[0] == getbefore(m, res[0] + res[1]) || l == r) { ll = m + 1; solve(m + 1, r); return; } else { solve(l, m - 1); } } int find_best(int N) { n = N; rr = n - 1; // int t = 100; while(ans == -1) { cerr << "e\n"; solve(ll, rr); // cerr << now << '\n'; // vector<int> res = aa(now); // if(res[0] + res[1] == 0) return now; // if(!vi[now]) add_val(now, res[0] + res[1]); // vi[now] = true; // if(res[0] <= getbefore(now, res[0] + res[1])) { // sign = 1; // dx *= 2; // if(dx == 0) dx++; // } // else { // sign = -1; // dx /= 2; // if(dx == 0) dx++; // } // if(sign == 1) dx = min(dx, n - 1 - now); // else dx = min(dx, now); // now += dx * sign; } return ans; // for(int i = 0; i < n; i++) { // vector<int> res = ask(i); // if(res[0] + res[1] == 0) // return i; // } // return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...