제출 #1361680

#제출 시각아이디문제언어결과실행 시간메모리
1361680MunkhturErdenebatStreet Lamps (APIO19_street_lamps)C++20
20 / 100
407 ms13368 KiB
#include<bits/stdc++.h>
#include<string.h>
#include <algorithm>
#include <iterator>
#include <set>
#include <stdlib.h>
 #define ll long long
 #define fr first
 #define sc second
 #define pb push_back
 #define YES cout<<"YES"<<endl
 #define NO cout<<"NO"<<endl
 #define endl "\n"
using namespace std;
    ll a,b,c,d,e,f,m,i,j,n,h,g,mid,l,r,ka,dp[200005],q[200005],k[200105];
    map<ll,ll> mee,see;
    map<ll,ll> mii,maa;
    vector<ll> vas,ves;
    string x,y,z,te,to;
    pair<ll,ll> wefe,t[205005];
    stack<ll> munkh;
    multiset<ll> mul;
ll tree[300005*4];
void build(ll node, ll l, ll r){
    if(l==r){
        tree[node]=k[l];
    }
    else{
        ll m=(l+r-1)/2;
        build(node*2,l,m);
        build(node*2+1,m+1,r);
        tree[node]=max(tree[node*2],tree[node*2+1]);
    }
}
void update(ll node, ll l, ll r, ll m, ll n){
    if(l>m){
        return;
    }
    if(r<m){
        return;
    }
    if(l==r){
        tree[node]=n;
        return;
    }
    ll mid=(l+r-1)/2;
    update(node*2,l,mid,m,n);
    update(node*2+1,mid+1,r,m,n);
    tree[node]=max(tree[node*2],tree[node*2+1]);
}
ll query(ll node, ll l, ll r,ll m, ll n){
    if(r<m || l>n){
        return -1;
    }
    else{
        if(l>=m && r<=n){
            return tree[node];
        }
        ll mid=(l+r-1)/2;
        return max(query(node*2,l,mid,m,n),query(node*2+1,mid+1,r,m,n));
    }
}
int main(){
    cin>>a>>b;
    cin>>x;
    for(i=0 ; i<a ; i++){
        if(x[i]=='1'){
            k[i]=-1;
        }
        else{
            k[i]=1e6;
        }
    }
    build(1,0,a-1);
    for(i=0 ; i<b ; i++){
        cin>>y;
        if(y[0]=='q'){
            cin>>l>>r;
            if(i-query(1,0,a-1,l-1,r-2)<0){
            	cout<<0<<endl;
            	continue;
			}
            cout<<i-query(1,0,a-1,l-1,r-2)<<endl;
        }
        else{
            cin>>l;
            if(x[l-1]=='0'){
                x[l-1]='1';
                update(1,0,a-1,l-1,i);
            }
        }
    }
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…