Submission #568921

# Submission time Handle Problem Language Result Execution time Memory
568921 2022-05-26T10:55:28 Z birthdaycake Street Lamps (APIO19_street_lamps) C++17
60 / 100
512 ms 21472 KB
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define mod 1000000007
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);
using namespace std;
 
 
 
int pref[300001],sub[300001],ans[300001],l[300001],seg[3000001];
int N,Left,Right,Value;
 
void Update(){
    int ind = N + Left - 1;
    seg[ind] = Value;
    while(ind /= 2) seg[ind] = max(seg[ind * 2], seg[ind * 2 + 1]);
}
 
 
int Query(int l = 1, int r = N, int ind = 1){
    if(l > Right || r < Left) return 0;
    if(l >= Left && r <= Right) return seg[ind];
    int mid = (l + r) / 2;
    return max(Query(l, mid, ind * 2), Query(mid + 1, r, ind * 2 + 1));
}
signed main() {
 
    int n,q; cin >> n >> q;
    string a; cin >> a;
    if(n <= 100 && q <= 100){
        for(int i = 0; i < n; i++){
            if(a[i] == '1') pref[i]++;
            if(i) pref[i] += pref[i - 1];
            sub[i] = pref[i];
        }
        vector<pair<string,pair<int,int>>>qw(q);
        for(int i = 0; i < q; i++){
            cin >> qw[i].first >> qw[i].second.first;
            if(qw[i].first != "toggle") cin >> qw[i].second.second;
            else qw[i].second.second = 0;
            int a = qw[i].second.first - 1, b = qw[i].second.second - 1;
            if(qw[i].first == "query"){
                int ans = 0;
                for(int j = 0; j <= i; j++){
                    if(qw[j].first == "query"){
                        if(sub[b - 1] - (a == 0 ? 0 : sub[a - 1]) == (b - a)) ans++;
                    }else{
                        if(sub[b - 1] - (a == 0 ? 0 : sub[a - 1]) == (b - a)) ans++;
                        int c = qw[j].second.first - 1;
                        if(sub[c] - (c == 0 ? 0 : sub[c - 1]) == 1){
                            for(int k = c; k < n; k++) sub[k]--;
                        }else{
                            for(int k = c; k < n; k++) sub[k]++;
                        }
                    }
                }
                cout << ans << endl;
                for(int j = 0; j < n; j++){
                    sub[j] = pref[j];
                }
            }
            
            
        }
        return 0;
    }
    int f = 0;
    vector<pair<string,pair<int,int>>>qw(q);
    for(int i = 0; i < q; i++){
        cin >> qw[i].first >> qw[i].second.first;
        if(qw[i].first == "query"){
            cin >> qw[i].second.second;
            if(qw[i].second.second - qw[i].second.first > 1) f = 1;
        }else{
            qw[i].second.second = 0;
        }
    }
    if(f){
        N = exp2(ceil(log2(n)));
        for(int i = 0; i < n; i++){
            if(a[i] == '0'){
                Value = 1e18;
                Left = i + 1;
                Update();
            }else{
                
            }
        }
        for(int i = 0; i < q; i++){
            if(qw[i].first == "query"){
                Left = qw[i].second.first; Right = qw[i].second.second - 1;
                int ans = Query();
                if(ans == 1e18){
                    cout << 0 << endl;
                }else{
                    cout << i - ans + 1 << endl;
                }
            }else{
                Value = i + 1;
                Left = qw[i].second.first;
                Update();
            }
        }
    }else{
        for(int i = 0; i < q; i++){
            string t; t = qw[i].first;
            if(t == "toggle"){
                int x = qw[i].second.first;
                x--;
                if(a[x] == '0'){
                    a[x] = '1';
                    l[x] = i + 1;
                }else{
                    ans[x] += (i - l[x] + 1);
                    a[x] = '0';
                }
                
            }else{
                int x = qw[i].second.first;
                x--;
                if(a[x] == '1'){
                    ans[x] += (i - l[x] + 1);
                    l[x] = i + 1;
                }
                cout << ans[x] << endl;
            }
        }
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 171 ms 15452 KB Output is correct
2 Correct 198 ms 15304 KB Output is correct
3 Correct 264 ms 15428 KB Output is correct
4 Correct 235 ms 20200 KB Output is correct
5 Correct 296 ms 20460 KB Output is correct
6 Correct 242 ms 20060 KB Output is correct
7 Correct 270 ms 15324 KB Output is correct
8 Correct 327 ms 21472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 227 ms 19932 KB Output is correct
6 Correct 308 ms 20176 KB Output is correct
7 Correct 339 ms 20376 KB Output is correct
8 Correct 451 ms 17116 KB Output is correct
9 Correct 194 ms 12964 KB Output is correct
10 Correct 225 ms 14072 KB Output is correct
11 Correct 199 ms 13972 KB Output is correct
12 Correct 512 ms 20444 KB Output is correct
13 Correct 399 ms 17128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Incorrect 2 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 171 ms 15452 KB Output is correct
9 Correct 198 ms 15304 KB Output is correct
10 Correct 264 ms 15428 KB Output is correct
11 Correct 235 ms 20200 KB Output is correct
12 Correct 296 ms 20460 KB Output is correct
13 Correct 242 ms 20060 KB Output is correct
14 Correct 270 ms 15324 KB Output is correct
15 Correct 327 ms 21472 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 227 ms 19932 KB Output is correct
21 Correct 308 ms 20176 KB Output is correct
22 Correct 339 ms 20376 KB Output is correct
23 Correct 451 ms 17116 KB Output is correct
24 Correct 194 ms 12964 KB Output is correct
25 Correct 225 ms 14072 KB Output is correct
26 Correct 199 ms 13972 KB Output is correct
27 Correct 512 ms 20444 KB Output is correct
28 Correct 399 ms 17128 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Incorrect 2 ms 340 KB Output isn't correct
31 Halted 0 ms 0 KB -