Submission #1351040

#TimeUsernameProblemLanguageResultExecution timeMemory
1351040bozhoThe Big Prize (IOI17_prize)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "prize.h"
#define endl '\n'
using namespace std;

const int MAX = (2e5) + 5;

vector<int> a[MAX];
bool d[MAX];

int find_best(int n)
{
    random_device rd;
    mt19937 rng(rd());
    uniform_int_distribution<int> dist(0, n - 1);
    int bx = 0, x = 0, id;
    for (int i = 0; i < 40; i++)
    {
        id = dist(rng);
        if (!d[id])
        {
            a[id] = ask(id);
            d[id] = 1;
            if (a[id][0] + a[id][1] == 0)
                return id;
            bx = max(bx, a[id][0] + a[id][1]);
        }
    }
    set<int> s;
    s.insert(n);
    for (int i = 0; i < n; i++)
    {
        if (!d[i])
        {
            a[i] = ask(i);
            d[i] = 1;
        }
        x = a[i][0] + a[i][1];
        if (x == 0)
            return i;
        if (x == bx)
        {
            int l = i, r = s.upper_bound(i), mid;
            while (r - l > 1)
            {
                mid = l + (r - l) / 2;
                if (!d[mid])
                {
                    a[mid] = ask(mid);
                    d[i] = 1;
                }
                if (a[mid][0] + a[mid][1] == 0)
                    return mid;
                if (a[mid][0] + a[mid][1] < bx)
                    s.insert(a[mid][0] + a[mid][1]);
                if (a[i][0] == a[mid][0] && a[i][1] == a[mid][1])
                    l = mid;
                else
                    r = mid;
            }
            i = l;
        }
    }
}

Compilation message (stderr)

prize.cpp: In function 'int find_best(int)':
prize.cpp:43:41: error: cannot convert 'std::set<int>::iterator' {aka 'std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator'} to 'int' in initialization
   43 |             int l = i, r = s.upper_bound(i), mid;
      |                            ~~~~~~~~~~~~~^~~
      |                                         |
      |                                         std::set<int>::iterator {aka std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::const_iterator}
prize.cpp:64:1: warning: control reaches end of non-void function [-Wreturn-type]
   64 | }
      | ^