답안 #1044923

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1044923 2024-08-05T14:37:58 Z vjudge1 가로등 (APIO19_street_lamps) C++17
60 / 100
153 ms 22776 KB
#pragma GCC optimize("unroll-loops,Ofast,O3")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define spc << " " <<
#define endl "\n"
#define all(x) x.begin(), x.end()
#define int long long
#define ii pair<long long,int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define mid (l+r)/2
#define inf 1e15
#define MOD 1000000007
#define MX 300005
using namespace std;


int n,q;
struct segtree{
    vi tree;
    segtree(){
        tree.resize(2*MX,0);
    }
    void update(int v, int l, int r, int pos, int val){
        if(l>r) return;
        if(l==r){
            tree[v]=val;
            return;
        }
        if(pos<=mid){
            update(v+1, l, mid, pos, val);
        }
        else{
            update(v+2*(mid-l+1), mid+1, r, pos, val);
        }
        tree[v]=max(tree[v+1], tree[v+2*(mid-l+1)]);
    }
    int query(int v, int l, int r, int ql, int qr){
        if(l>qr || r<ql) return 0;
        if(l>=ql && r<=qr) return tree[v];
        return max(query(v+1, l, mid, ql, qr), query(v+2*(mid-l+1), mid+1, r, ql, qr));
    }
};

void solve(){
    cin >> n >> q;
    string s; cin >> s;
    segtree seg;
    if(n>100 || q>100){
        int tot[n+1], last[n+1], cur[n+1];
        int tim[n+1];
        for(int i=1; i<=n; i++){
            tot[i]=last[i]=tim[i]=0;
            cur[i]=s[i-1]-'0';
            if(s[i-1]=='0'){
                tim[i]=inf;
                seg.update(1, 1, n, i, inf);
            }
        }
        for(int i=1; i<=q; i++){
            cin >> s;
            if(s[0]=='t'){
                int a; cin >> a;
                if(cur[a]==0){
                    last[a]=i;
                }
                else{
                    tot[a]+=i-last[a];
                }
                cur[a]=1-cur[a];
                seg.update(1, 1, n, a, i);
            }
            else{
                int l,r; cin >> l >> r;
                int ans=tot[l];
                if(cur[l]) ans+=i-last[l];
                if(l==r-1)cout << ans << endl;
                else{
                    ans=seg.query(1, 1, n, l, r-1);
                    if(ans==inf) cout << 0 << endl;
                    else cout << i-ans << endl;
                }
            }
        }
        return;
    }
    int arr[q+1][n+1];
    for(int i=1; i<=n; i++){
        if(s[i-1]=='0') arr[1][i]=0;
        else arr[1][i]=1;
    }
    
    for(int i=1; i<=q; i++){
        string h; cin >> h;
        if(i<q) for(int j=1; j<=n; j++) arr[i+1][j]=arr[i][j];
        if(h[0]=='t'){
            int a; cin >> a;
            arr[i+1][a]=1-arr[i+1][a];
        }
        else{
            int l,r; cin >> l >> r;
            int ans=0;
            for(int j=1; j<=i; j++){
                int ok=1;
                for(int f=l; f<r; f++){
                    if(!arr[j][f]){
                        ok=0;
                        break;
                    }
                }
                if(ok){
                    ans++;
                }
            }
            cout << ans << endl;
        }
    }
}
 
 
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    #ifdef Local
    freopen("in","r",stdin);
    freopen("out","w",stdout);
    #endif
 
    /*freopen("nondec.in","r",stdin);
    freopen("nondec.out","w",stdout);*/
 
    int t=1;
    //cin >> t;
    while(t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 5212 KB Output is correct
5 Correct 1 ms 5212 KB Output is correct
6 Correct 1 ms 5212 KB Output is correct
7 Correct 1 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 5980 KB Output is correct
2 Correct 42 ms 5972 KB Output is correct
3 Correct 51 ms 6224 KB Output is correct
4 Correct 83 ms 15632 KB Output is correct
5 Correct 78 ms 15880 KB Output is correct
6 Correct 78 ms 15588 KB Output is correct
7 Correct 78 ms 15332 KB Output is correct
8 Correct 58 ms 16724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 3 ms 4956 KB Output is correct
5 Correct 86 ms 17104 KB Output is correct
6 Correct 108 ms 17492 KB Output is correct
7 Correct 121 ms 17896 KB Output is correct
8 Correct 139 ms 22752 KB Output is correct
9 Correct 50 ms 8792 KB Output is correct
10 Correct 50 ms 9040 KB Output is correct
11 Correct 51 ms 9304 KB Output is correct
12 Correct 153 ms 21476 KB Output is correct
13 Correct 134 ms 22776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Incorrect 1 ms 4956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 5212 KB Output is correct
5 Correct 1 ms 5212 KB Output is correct
6 Correct 1 ms 5212 KB Output is correct
7 Correct 1 ms 5212 KB Output is correct
8 Correct 37 ms 5980 KB Output is correct
9 Correct 42 ms 5972 KB Output is correct
10 Correct 51 ms 6224 KB Output is correct
11 Correct 83 ms 15632 KB Output is correct
12 Correct 78 ms 15880 KB Output is correct
13 Correct 78 ms 15588 KB Output is correct
14 Correct 78 ms 15332 KB Output is correct
15 Correct 58 ms 16724 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 86 ms 17104 KB Output is correct
21 Correct 108 ms 17492 KB Output is correct
22 Correct 121 ms 17896 KB Output is correct
23 Correct 139 ms 22752 KB Output is correct
24 Correct 50 ms 8792 KB Output is correct
25 Correct 50 ms 9040 KB Output is correct
26 Correct 51 ms 9304 KB Output is correct
27 Correct 153 ms 21476 KB Output is correct
28 Correct 134 ms 22776 KB Output is correct
29 Correct 2 ms 4956 KB Output is correct
30 Incorrect 1 ms 4956 KB Output isn't correct
31 Halted 0 ms 0 KB -