#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
vector<int> mem[200000];
vector<int> Ask(int i){
if (mem[i].size()) return mem[i];
return mem[i]=ask(i);
}
int find_best(int n) {
for (int i=0; i<n; ++i) mem[i].clear();
// if (n<=5000){
// for (int i=0; i<n; ++i){
// auto tmp=Ask(i);
// if (tmp[0]+tmp[1]==0) return i;
// }
// return -1;
// }
int cnt=0;
{
auto tmp=Ask(1);
cnt=tmp[0]+tmp[1];
}
ordered_set<int> id;
vector<int> st;
for (int i=1; i<n; ++i) st.push_back(i);
auto solve=[&](auto &&self, vector<int> pos, int cc){
if (!cc || pos.empty()) return;
int mid=((int)pos.size()-1)/2;
vector<int> posl, posr;
for (int j:pos){
if (j<pos[mid]) posl.push_back(j);
if (j>pos[mid]) posr.push_back(j);
}
auto tmp=Ask(pos[mid]);
if (tmp[0]+tmp[1]>cnt){
cnt=tmp[0]+tmp[1];
st.clear();
for (int i=0; i<n; ++i) if (mem[i].size()){
if (mem[i][0]+mem[i][1]<cnt) id.insert(i);
}else st.push_back(i);
self(self, st, cnt-(int)id.size());
}if (tmp[0]+tmp[1]!=cnt){
id.insert(pos[mid]);
pos.erase(pos.begin()+mid);
self(self, pos, cc-1);
}else{
int cl=tmp[0]-id.order_of_key(pos[mid]);
int cr=cc-cl;
self(self, posl, cl);
self(self, posr, cr);
}
};
solve(solve, st, cnt-(int)id.size());
for (int i:id){
auto tmp=Ask(i);
if (tmp[0]+tmp[1]==0) return i;
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8908 KB |
Output is correct |
2 |
Correct |
5 ms |
8908 KB |
Output is correct |
3 |
Correct |
4 ms |
8908 KB |
Output is correct |
4 |
Correct |
4 ms |
8908 KB |
Output is correct |
5 |
Correct |
4 ms |
8652 KB |
Output is correct |
6 |
Incorrect |
5 ms |
8908 KB |
Integer -1 violates the range [0, 199999] |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8908 KB |
Output is correct |
2 |
Correct |
5 ms |
8908 KB |
Output is correct |
3 |
Correct |
5 ms |
8908 KB |
Output is correct |
4 |
Correct |
4 ms |
8908 KB |
Output is correct |
5 |
Correct |
4 ms |
8652 KB |
Output is correct |
6 |
Incorrect |
5 ms |
8908 KB |
Integer -1 violates the range [0, 199999] |
7 |
Halted |
0 ms |
0 KB |
- |