#include <bits/stdc++.h>
#include "locmin.h"


long long inf = 1e18;
std::pair <int, int> find_locmin_point(int N, int M) {
    if(N == 1)
    {
        std::map<std::pair<int,int>,int> mapa;
        if(M == 1)return {1,1};
        int tl = 1;
        int tr = M;
        long long rez = inf;
        while(tl <= tr)
        {
            int mid = tl+tr>>1;
            long long left = inf;
            long long right = inf;
            long long v;
            if(mapa.count({1,mid}))v = mapa[{1,mid}];
            else v = value(1,mid), mapa[{1,mid}] = v;

            if(mid>1)
            {
                if(mapa.count({1,mid-1}))left = mapa[{1,mid-1}];
                else left = value(1,mid-1), mapa[{1,mid-1}] = left;
            }
            if(mid<M)
            {
                if(mapa.count({1,mid+1}))right = mapa[{1,mid+1}];
                else right = value(1,mid+1), mapa[{1,mid+1}] = right;
            }
            if(v < left && v < right)
            {
                rez = mid;
                break;
            }
            else if(v >= left)tr = mid-1;
            else tl = mid+1;
        }
        if(rez == inf)rez = tl+tr>>1;
        return {1,rez};
    }
}
