This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "prize.h"
#include <iostream>
#include <vector>
#include <cmath>
#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second
#define pb push_back
#define MAXN 200010
using namespace std;
int n, l[MAXN], r[MAXN], maxx, sq=490;
vector<int> all;
/*bool check(int i, int k)
{
vector<int> p=ask(i);
int le=p[0], ri=p[1];
if ((le+ri)<maxx) return true;
if (le>k) return true;
return false;
}*/
bool vis[MAXN];
void askk(int i)
{
if (!vis[i]) { vector<int> p=ask(i); l[i]=p[0]; r[i]=p[1]; vis[i]=true; }
}
void solve(int left, int right)
{
int mid=left+(right-left)/2;
askk(mid); askk(left); askk(right);
if (left>right) return;
if (left==right) { if ((l[mid]+r[mid])<maxx) all.pb(mid); return; }
if (left==(right-1))
{
if ((l[mid]+r[mid])<maxx) all.pb(mid);
mid++;
askk(mid);
if ((l[mid]+r[mid])<maxx) all.pb(mid);
return;
}
if ((l[mid]+r[mid])<maxx) { all.pb(mid); solve(left, mid-1); solve(mid+1, right); }
else
{
if (l[mid]-l[left]) solve(left, mid-1);
if (l[right]-l[mid]) solve(mid+1, right);
}
}
int find_best(int N) {
n=N;
sq=min(2*sq, n-1);//2*sqrt(n);
for (int i=0; i<=sq; i++)
{
askk(i);
if (l[i]+r[i]==0) return i;
maxx=max(maxx, l[i]+r[i]);
}
int left=0, right=n-1;
solve(left, right);
int ret=0;
for (int i=0; i<all.size(); i++) { /*askk(all[i]);*/ if ((l[all[i]]+r[all[i]])==0) ret=all[i]; }
return ret;
}
///1, 2, 5, 26, 677
/*
8
3 2 3 1 3 3 2 3
*/
Compilation message (stderr)
prize.cpp: In function 'int find_best(int)':
prize.cpp:71:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for (int i=0; i<all.size(); i++) { /*askk(all[i]);*/ if ((l[all[i]]+r[all[i]])==0) ret=all[i]; }
| ~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |