답안 #414653

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
414653 2021-05-30T23:35:33 Z fadi57 Deda (COCI17_deda) C++14
60 / 140
11 ms 388 KB
#include<bits/stdc++.h>
using namespace std;
const int mx=1e3;
typedef long long ll;
int inf=1e9+10;
const int mod=1e9+7;
int n,m,k,p,l,q;
int seg[4*mx];

void build(int node,int st,int en){

    if(st==en){
        seg[node]=inf;
        return;
    }
    int mid=(st+en)/2;

    build(node*2,st,mid); build(node*2+1,mid+1,en);

    seg[node]=inf;
    return;









 }
void update(int node,int st,int en,int idx,int value){

            if(st==en){

                seg[node]=value;
                return;
            }

          int mid=(st+en)/2;
          if(idx<=mid){

            update(node*2,st,mid,idx,value);
          }else{
           update(node*2+1,mid+1,en,idx,value);


           }


seg[node]=min(seg[node*2],seg[node*2+1]);
return ;

 }
int query(int node,int st,int en,int l,int x){



if(st==en){

    if(seg[node]<=x){return st;}else{return -1;}
}

int mid=(st+en)/2;


  if(l<=mid&&seg[node*2]<=x){
    int z=query(node*2,st,mid,l,x);
    if(z!=-1){return z;}
  }
  if(l<=en&&seg[node*2+1]<=x){
   int z=query(node*2+1,mid+1,en,l,x);
    if(z!=-1){return z;}

  }
  return -1;



   }





int main(){
    cin>>n>>q;
      build(1,0,n-1);
     // cout<<seg[1]<<endl;
    for(int i=0;i<q;i++){




        char c;cin>>c;
        if(c=='M'){

           int x,a;cin>>x>>a;
           a--;
           update(1,0,n-1,a,x);
          // cout<<seg[1]<<endl;

           } else{

            int y,b;cin>>y>>b;
            b--;

int ans=query(1,0,n-1,b,y);
if(ans!=-1){ans++;}
cout<<ans<<endl;
           }


    }




 }
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 220 KB Output is correct
2 Correct 2 ms 220 KB Output is correct
3 Correct 11 ms 388 KB Output is correct
4 Runtime error 2 ms 348 KB Execution killed with signal 11
5 Runtime error 1 ms 348 KB Execution killed with signal 11
6 Runtime error 1 ms 348 KB Execution killed with signal 11
7 Runtime error 1 ms 348 KB Execution killed with signal 11