제출 #1117220

#제출 시각아이디문제언어결과실행 시간메모리
1117220hoangnoobproDeda (COCI17_deda)C++17
140 / 140
591 ms5828 KiB
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define nmax 400007
#define fi first
#define se second
#define ll long long
ll t=1,n,m=0,i=0,j=0,d=0,x=0,k=0,y=0,z,a[nmax],st[nmax*4],l,r,mid,kq;
char ch;
void build(ll id,ll l,ll r)
{
    if(l==r)
    {
        st[id]=1e17;
        return;
    }
    ll mid=(l+r)/2;
    build(id*2,l,mid);
    build(id*2+1,mid+1,r);
    st[id]=1e17;
}
void update(ll id,ll l,ll r,ll vt,ll gt)
{
    if(r<vt||l>vt)return;
    if(l==r)
    {
        st[id]=gt;
        return;
    }
    ll mid=(l+r)/2;
    update(id*2,l,mid,vt,gt);
    update(id*2+1,mid+1,r,vt,gt);
    st[id]=min(st[id*2],st[id*2+1]);
}
void get(ll id,ll l,ll r,ll u,ll v)
{
    if(r<u||l>v)return;
    if(u<=l&&r<=v)
    {
        d=min(d,st[id]);
        return;
    }
    ll mid=(l+r)/2;
    get(id*2,l,mid,u,v);
    get(id*2+1,mid+1,r,u,v);
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>t;
    build(1,1,n);
    while(t--)
    {
        cin>>ch>>x>>y;
        if(ch=='M')
        {
            update(1,1,n,y,x);
            continue;
        }
        l=y;
        r=n;
        kq=-1;
        while(l<=r)
        {
            mid=(l+r)/2;
            d=1e17;
            get(1,1,n,y,mid);
            if(d<=x)
            {
                kq=mid;
                r=mid-1;
            }
            else l=mid+1;
        }
        cout<<kq<<"\n";
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...