Submission #862211

# Submission time Handle Problem Language Result Execution time Memory
862211 2023-10-17T17:28:19 Z RobBobBob Deda (COCI17_deda) C++14
140 / 140
82 ms 6988 KB
#include <bits/stdc++.h>

using namespace std;

const int inf = 1024*1024*1024;

struct aint
{
    int nxtp2(int n)
    {
        int p=1;
        while(p<n)p*=2;
        return p;
    }
    int offset;
    int *data;
    aint(int n)
    {
        offset=nxtp2(n);
        data=new int[offset*2];
        for(int i=0;i<offset;i++)
        {
            data[offset+i]=inf;
        }
        init(0,offset-1,1);
    }
    void init(int st,int dr,int node)
    {
        if(st==dr)return;
        else
        {
            int mid=(st+dr)/2;
            init(st,mid,node*2);
            init(mid+1,dr,node*2+1);
            data[node]=min(data[node*2],data[node*2+1]);
        }
    }
    void update(int poz,int val)
    {
        data[offset+poz]=val;
        for(poz=(poz+offset)/2;poz>0;poz/=2)
        data[poz]=min(data[poz*2],data[poz*2+1]);
    }
    int _cb(int l,int x,int &minn,int st,int dr,int node)
    {
        //cerr<<st<<' '<<dr<<'\n';
        if(dr<l)return dr;
        if(l<=st&&min(minn,data[node])>x)
        {
            minn=min(data[node],minn);
            return dr;
        }
        if(st==dr)return st-1;
        int mid=(st+dr)/2;
        int res = _cb(l,x,minn,st,mid,node*2);
        if(res<mid)return res;
        return _cb(l,x,minn,mid+1,dr,node*2+1);
    }
    int cb(int l,int x)
    {
        int minn=inf;
        return _cb(l,x,minn,0,offset-1,1);
    }
    void debug()
    {
        cerr<<data[1]<<'\n';
        cerr<<data[2]<<' '<<data[3]<<'\n';
        cerr<<data[4]<<' '<<data[5]<<' '<<data[6]<<' '<<data[7]<<'\n';
    }
};

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,q;cin>>n>>q;
    aint root = aint(n);
    for(int i=0;i<q;i++)
    {
        //root.debug();
        char c;int a,b;
        cin>>c;cin>>a>>b;
        if(c=='M')
        {
            root.update(b-1,a);
        }
        else
        {
            int res = root.cb(b-1,a);
            if(res+1==root.offset)cout<<"-1\n";
            else cout<<res+2<<'\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 520 KB Output is correct
4 Correct 82 ms 6988 KB Output is correct
5 Correct 69 ms 5456 KB Output is correct
6 Correct 78 ms 6744 KB Output is correct
7 Correct 81 ms 6740 KB Output is correct