제출 #1063476

#제출 시각아이디문제언어결과실행 시간메모리
1063476fv3The Big Prize (IOI17_prize)C++14
20 / 100
50 ms3544 KiB
#include "prize.h" #include <bits/stdc++.h> using namespace std; vector<int> st; int nt = 1; int get_range(int l, int r, int k, int x, int y) { if (x > r || y < l) return 0; if (x >= l && y <= r) return st[k]; int c = (x + y) / 2; return get_range(l, r, k*2, x, c) + get_range(l, r, k*2|1, c+1, y); } void add(int index) { st[nt + index] = 1; for (int i = (nt + index) / 2; i >= 1; i /= 2) st[i] = st[i*2] + st[i*2|1]; } vector<int> parent; int find(int index) { if (!parent[index]) return index; return parent[index] = find(parent[index]); } int find_best(int n) { parent = vector<int>(n); while (nt < n) nt <<= 1; st = vector<int>(2 * nt); stack<int> stck; int mx_cnt = 1; while (1) { int l = 0, r = n - 1; while (1) { int c = (l + r) / 2; int index = find(c); auto val = ask(index); int cnt = val[0] + val[1]; if (cnt == 0) return index; if (cnt > mx_cnt) { mx_cnt = cnt; while (!stck.empty()) { add(stck.top()); stck.pop(); } } if (cnt < mx_cnt) { parent[index] = index + 1; add(index); break; } if (val[0] == get_range(0, index, 1, 0, nt-1)) l = c + 1; else r = c - 1; stck.push(index); } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...