Submission #527052

# Submission time Handle Problem Language Result Execution time Memory
527052 2022-02-16T21:16:55 Z Lobo Street Lamps (APIO19_street_lamps) C++17
60 / 100
296 ms 32328 KB
#include<bits/stdc++.h>
using namespace std;

const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

#define maxn 330000

int n, q;
int s1[110][110];
int s2[maxn], ans2[maxn], cur2[maxn];
int tr[maxn];
pair<string,pair<int,int>> qr[maxn];

void att(int no, int l, int r, int pos, int val) {
    if(l > pos || r < pos) return;
    else if(l == r) {
        tr[no] = val;
    }
    else {
        int f1 = 2*no;
        int f2 = 2*no+1;
        int mid = (l+r)/2;

        att(f1,l,mid,pos,val);
        att(f2,mid+1,r,pos,val);
        tr[no] = max(tr[f1],tr[f2]);
    }
}

int qrr(int no, int l, int r, int L, int R) {
    if(l > R || r < L) return 0;
    else if(l >= L && r <= R) {
        return tr[no];
    }
    else {
        int f1 = 2*no;
        int f2 = 2*no+1;
        int mid = (l+r)/2;

        return max(qrr(f1,l,mid,L,R),qrr(f2,mid+1,r,L,R));
    }
}

void solve() {
    string est;
    cin >> n >> q >> est;

    bool oksub2 = true;
    for(int i = 1; i <= q; i++) {
        string sss; cin >> sss;
        if(sss == "toggle") {
            int pos; cin >> pos;
            qr[i] = mp(sss,mp(pos,0));
        }
        else {
            int l, r;
            cin >> l >> r;
            qr[i] = mp(sss,mp(l,r));
            if(r != l+1) oksub2 = false;
        }

    }

    if(n <= 100 && q <= 100) {
        for(int i = 1; i <= n; i++) {
            s1[i][0] = est[i-1]-'0';
        }

        for(int i = 1; i <= q; i++) {
            for(int j = 1; j <= n; j++) {
                s1[j][i] = s1[j][i-1];
            }

            string sss; sss = qr[i].fr;
            if(sss == "toggle") {
                int pos; pos = qr[i].sc.fr;
                s1[pos][i]^= 1;
                continue;
            }

            int l,r; 
            l = qr[i].sc.fr;
            r = qr[i].sc.sc;
            r--;
            int ans = 0;
            for(int j = 0; j < i; j++) {
                int ok = 1;
                for(int k = l; k <= r; k++) {
                    if(s1[k][j] == 0) ok = 0;
                }
                ans+= ok;
            }

            cout << ans << endl;
        }
    }
    else if(oksub2) {
        for(int i = 1; i <= n; i++) {
            s2[i] = est[i-1]-'0';
            cur2[i] = 0;
            ans2[i] = 0;
        }

        for(int i = 1; i <= q; i++) {
            string sss; sss = qr[i].fr;
            int pos; pos = qr[i].sc.fr;
            ans2[pos]+= (i-cur2[pos])*s2[pos];
            cur2[pos] = i;

            if(sss == "toggle") {
                ans2[pos]+= (i-cur2[pos])*s2[pos];
                cur2[pos] = i;
                s2[pos]^= 1;
                continue;
            }

            pos = qr[i].sc.sc; pos--;

            cout << ans2[pos] << endl;
        }
    }
    else {
        for(int i = 1; i <= n; i++) {
            if(est[i-1]-'0' == 1) {
                att(1,1,n,i,0);
            }
            else {
                att(1,1,n,i,inf);
            }
        }

        for(int i = 1; i <= q; i++) {
            string sss; sss = qr[i].fr;

            if(sss == "toggle") {
                int pos; pos = qr[i].sc.fr;
                att(1,1,n,pos,i);
                continue;
            }

            int l, r;
            l = qr[i].sc.fr;
            r = qr[i].sc.sc; r--;

            cout << max(0LL,i-qrr(1,1,n,l,r)) << endl;
        }
    }


}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);

    // freopen("in.in", "r", stdin);
    //freopen("out.out", "w", stdout);

    int tt = 1;
    // cin >> tt;
    while(tt--) solve();

}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 15820 KB Output is correct
2 Correct 8 ms 15820 KB Output is correct
3 Correct 9 ms 15748 KB Output is correct
4 Correct 10 ms 15908 KB Output is correct
5 Correct 8 ms 15820 KB Output is correct
6 Correct 9 ms 15820 KB Output is correct
7 Correct 9 ms 15844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 16708 KB Output is correct
2 Correct 79 ms 16708 KB Output is correct
3 Correct 82 ms 16828 KB Output is correct
4 Correct 135 ms 23912 KB Output is correct
5 Correct 106 ms 24296 KB Output is correct
6 Correct 91 ms 23936 KB Output is correct
7 Correct 118 ms 23796 KB Output is correct
8 Correct 128 ms 25204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 15720 KB Output is correct
2 Correct 8 ms 15820 KB Output is correct
3 Correct 8 ms 15784 KB Output is correct
4 Correct 8 ms 15832 KB Output is correct
5 Correct 196 ms 24436 KB Output is correct
6 Correct 211 ms 24492 KB Output is correct
7 Correct 240 ms 29964 KB Output is correct
8 Correct 296 ms 32328 KB Output is correct
9 Correct 91 ms 19516 KB Output is correct
10 Correct 98 ms 19756 KB Output is correct
11 Correct 132 ms 19964 KB Output is correct
12 Correct 267 ms 30944 KB Output is correct
13 Correct 278 ms 32328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 15820 KB Output is correct
2 Incorrect 8 ms 15820 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 15820 KB Output is correct
2 Correct 8 ms 15820 KB Output is correct
3 Correct 9 ms 15748 KB Output is correct
4 Correct 10 ms 15908 KB Output is correct
5 Correct 8 ms 15820 KB Output is correct
6 Correct 9 ms 15820 KB Output is correct
7 Correct 9 ms 15844 KB Output is correct
8 Correct 77 ms 16708 KB Output is correct
9 Correct 79 ms 16708 KB Output is correct
10 Correct 82 ms 16828 KB Output is correct
11 Correct 135 ms 23912 KB Output is correct
12 Correct 106 ms 24296 KB Output is correct
13 Correct 91 ms 23936 KB Output is correct
14 Correct 118 ms 23796 KB Output is correct
15 Correct 128 ms 25204 KB Output is correct
16 Correct 11 ms 15720 KB Output is correct
17 Correct 8 ms 15820 KB Output is correct
18 Correct 8 ms 15784 KB Output is correct
19 Correct 8 ms 15832 KB Output is correct
20 Correct 196 ms 24436 KB Output is correct
21 Correct 211 ms 24492 KB Output is correct
22 Correct 240 ms 29964 KB Output is correct
23 Correct 296 ms 32328 KB Output is correct
24 Correct 91 ms 19516 KB Output is correct
25 Correct 98 ms 19756 KB Output is correct
26 Correct 132 ms 19964 KB Output is correct
27 Correct 267 ms 30944 KB Output is correct
28 Correct 278 ms 32328 KB Output is correct
29 Correct 9 ms 15820 KB Output is correct
30 Incorrect 8 ms 15820 KB Output isn't correct
31 Halted 0 ms 0 KB -