#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() << 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 j = 0; j < min(3000, (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);
}
else{
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;
}
if(a[0] + a[1] < cnt && !ask(mid, mid)){
update(mid, 1);
break;
}
a[0] -= ask(1, mid - 1);
a[1] -= ask(mid + 1, n);
if(a[1] > 0){
l = mid + 1;
}
else{
r = mid - 1;
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
5804 KB |
Output is correct |
2 |
Correct |
6 ms |
5760 KB |
Output is correct |
3 |
Correct |
30 ms |
5812 KB |
Output is correct |
4 |
Correct |
28 ms |
5788 KB |
Output is correct |
5 |
Correct |
15 ms |
5884 KB |
Output is correct |
6 |
Correct |
25 ms |
5964 KB |
Output is correct |
7 |
Correct |
21 ms |
5880 KB |
Output is correct |
8 |
Correct |
34 ms |
5764 KB |
Output is correct |
9 |
Correct |
24 ms |
5848 KB |
Output is correct |
10 |
Correct |
36 ms |
5804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
5848 KB |
Output is correct |
2 |
Correct |
31 ms |
5816 KB |
Output is correct |
3 |
Correct |
15 ms |
5880 KB |
Output is correct |
4 |
Correct |
19 ms |
5872 KB |
Output is correct |
5 |
Correct |
16 ms |
6000 KB |
Output is correct |
6 |
Correct |
23 ms |
5828 KB |
Output is correct |
7 |
Correct |
29 ms |
5844 KB |
Output is correct |
8 |
Correct |
17 ms |
5796 KB |
Output is correct |
9 |
Correct |
32 ms |
5860 KB |
Output is correct |
10 |
Correct |
30 ms |
5840 KB |
Output is correct |
11 |
Correct |
17 ms |
6004 KB |
Output is correct |
12 |
Correct |
36 ms |
6180 KB |
Output is correct |
13 |
Correct |
26 ms |
5848 KB |
Output is correct |
14 |
Correct |
16 ms |
5168 KB |
Output is correct |
15 |
Partially correct |
48 ms |
6844 KB |
Partially correct - number of queries: 6318 |
16 |
Correct |
37 ms |
6120 KB |
Output is correct |
17 |
Execution timed out |
3062 ms |
6548 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |