답안 #934206

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
934206 2024-02-27T01:25:18 Z irmuun 가로등 (APIO19_street_lamps) C++17
20 / 100
199 ms 22608 KB
#include<bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

struct segtree{
    ll n;
    vector<ll>d;
    vector<ll>u;
    segtree(ll n):n(n){
        d.resize(4*n);
        build(1,1,n);
    }
    void build(ll node,ll l,ll r){
        if(l==r){
            d[node]=0;
            return;
        }
        ll mid=(l+r)/2;
        build(node*2,l,mid);
        build(node*2+1,mid+1,r);
        d[node]=max(d[node*2],d[node*2+1]);
    }
    ll query(ll node,ll l,ll r,ll L,ll R){
        if(l > R || r < L || L > R){
            return 0;
        }
        if(L <= l && r <= R){
            return d[node];
        }
        ll mid=(l+r)/2;
        return max(query(node*2,l,mid,L,R),query(node*2+1,mid+1,r,L,R));
    }
    void update(ll node,ll l,ll r,ll k,ll val){
        if(l>k || r<k)return;
        if(l==r){
            d[node]=val;
            return;
        }
        ll mid=(l+r)/2;
        update(node*2,l,mid,k,val);
        update(node*2+1,mid+1,r,k,val);
        d[node]=max(d[node*2],d[node*2+1]);
    }
};

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n,q;
    cin>>n>>q;
    char s[n+5],cur[n+5];
    for(ll i=1;i<=n;i++){
        cin>>s[i];
    }
    vector<pair<ll,ll>>que(q+1);
    for(ll i=1;i<=q;i++){
        string t;
        cin>>t;
        if(t=="toggle"){
            ll j;
            cin>>j;
            que[i]={j,-1};
        }
        else{
            ll a,b;
            cin>>a>>b;
            que[i]={a,b};
        }
    }
    segtree sg(n);
    for(ll i=1;i<=n;i++){
        if(s[i]=='1'){
            sg.update(1,1,n,i,0);
        }
        else{
            sg.update(1,1,n,i,1e18);
        }
    }
    for(ll i=1;i<=q;i++){
        if(que[i].ss==-1){
            ll j=que[i].ff;
            sg.update(1,1,n,j,i);
        }
        else{
            ll a=que[i].ff,b=que[i].ss;
            ll x=sg.query(1,1,n,a,b-1);
            cout<<max(i-x,0ll)<<"\n";
        }
    }
}

Compilation message

street_lamps.cpp: In function 'int main()':
street_lamps.cpp:57:17: warning: unused variable 'cur' [-Wunused-variable]
   57 |     char s[n+5],cur[n+5];
      |                 ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 68 ms 5668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 124 ms 18408 KB Output is correct
6 Correct 146 ms 19640 KB Output is correct
7 Correct 180 ms 20572 KB Output is correct
8 Correct 197 ms 22608 KB Output is correct
9 Correct 65 ms 7760 KB Output is correct
10 Correct 75 ms 8440 KB Output is correct
11 Correct 73 ms 8532 KB Output is correct
12 Correct 195 ms 21296 KB Output is correct
13 Correct 199 ms 22608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -