#include <iostream>
#include "prize.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <bits/stdc++.h>
#define initrand mt19937 mt_rand(time(0));
#define rand mt_rand()
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> oset;
//#define int long long
#define INF 10000000000000000
#define MOD 1000000007
initrand;
/*vector<int> ask(int x){
cout<<"QUERY AT "<<x<<endl;
vector<int> tr = {0, 0};
cin>>tr[0]>>tr[1];
return tr;
}*/
int get(int l, int r){
return (((rand%(r-l+1))) + l);
}
signed find_best(signed n){
oset v;
for(int i =1 ;i<=n;i++) v.insert(i);
bool found = false;
map<int, int> first;
map<int, int> last;
int ans = -1;
int q = 0;
while(!found){
if(q>=10000){
found = true;
int tq = get(0, v.size() - 1);
ans = *v.find_by_order(tq) - 1;
continue;
}
int tq = get(0, v.size() - 1);
signed ta = *v.find_by_order(tq); //we will ask this
vector<int> qq = ask(ta-1);
q++;
if(qq[0] == qq[1] && qq[1]==0){
ans = ta;
found = true;
continue;
}
int ll = ta;
if(first[qq[0]] != 0) ll = min(ll, first[qq[0]]);
else first[qq[0]] = ta;
int rr = ta + 1;
rr = max(rr, last[qq[1]]);
int rrr = v.order_of_key(rr) - 1;
int lll = v.order_of_key(ll);
for(int temp = rrr;temp>=lll;temp--) v.erase(v.find_by_order(temp));
first[qq[0]] = min(first[qq[0]], ta);
last[qq[1]] = max(last[qq[1]], ta);
/*cout<<"Remaining array: "<<endl;
for(int j: v){
cout<<j<<" ";
}
cout<<endl;*/
}
return (ans-1);
}
/*signed main(){
signed n;
cin>>n;
int ans = find_best(n);
cout<<"Final answer: "<<ans<<endl;
}
11 12
0 1 3
0 2 4
2 3 5
3 4 4
4 5 6
0 6 3
6 7 2
6 8 5
8 9 6
8 10 7
*/
/*
3 3
0 1 1
1 2 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
177 ms |
9720 KB |
Output is correct |
2 |
Correct |
169 ms |
9728 KB |
Output is correct |
3 |
Correct |
173 ms |
9720 KB |
Output is correct |
4 |
Correct |
175 ms |
9712 KB |
Output is correct |
5 |
Correct |
168 ms |
9720 KB |
Output is correct |
6 |
Correct |
169 ms |
9800 KB |
Output is correct |
7 |
Correct |
174 ms |
9748 KB |
Output is correct |
8 |
Correct |
171 ms |
9720 KB |
Output is correct |
9 |
Correct |
173 ms |
9724 KB |
Output is correct |
10 |
Correct |
169 ms |
9720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
175 ms |
9828 KB |
Output is correct |
2 |
Correct |
172 ms |
9668 KB |
Output is correct |
3 |
Correct |
167 ms |
9720 KB |
Output is correct |
4 |
Correct |
171 ms |
9848 KB |
Output is correct |
5 |
Correct |
169 ms |
9848 KB |
Output is correct |
6 |
Correct |
177 ms |
9652 KB |
Output is correct |
7 |
Correct |
172 ms |
9708 KB |
Output is correct |
8 |
Correct |
171 ms |
9720 KB |
Output is correct |
9 |
Correct |
169 ms |
9704 KB |
Output is correct |
10 |
Correct |
178 ms |
9756 KB |
Output is correct |
11 |
Runtime error |
190 ms |
19436 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
12 |
Halted |
0 ms |
0 KB |
- |