#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){
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++;
assert(q<=10000);
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
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
179 ms |
9716 KB |
Output is correct |
2 |
Correct |
174 ms |
9724 KB |
Output is correct |
3 |
Correct |
177 ms |
9708 KB |
Output is correct |
4 |
Correct |
193 ms |
9684 KB |
Output is correct |
5 |
Correct |
175 ms |
9740 KB |
Output is correct |
6 |
Correct |
176 ms |
9660 KB |
Output is correct |
7 |
Correct |
177 ms |
9712 KB |
Output is correct |
8 |
Correct |
174 ms |
9720 KB |
Output is correct |
9 |
Correct |
195 ms |
9764 KB |
Output is correct |
10 |
Correct |
176 ms |
9720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
178 ms |
9720 KB |
Output is correct |
2 |
Correct |
178 ms |
9720 KB |
Output is correct |
3 |
Correct |
202 ms |
9696 KB |
Output is correct |
4 |
Correct |
186 ms |
9672 KB |
Output is correct |
5 |
Correct |
178 ms |
9740 KB |
Output is correct |
6 |
Correct |
179 ms |
9704 KB |
Output is correct |
7 |
Correct |
185 ms |
9656 KB |
Output is correct |
8 |
Correct |
181 ms |
9812 KB |
Output is correct |
9 |
Correct |
179 ms |
9708 KB |
Output is correct |
10 |
Correct |
182 ms |
9748 KB |
Output is correct |
11 |
Runtime error |
195 ms |
19560 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
12 |
Halted |
0 ms |
0 KB |
- |