제출 #240124

#제출 시각아이디문제언어결과실행 시간메모리
240124wiwiho가로등 (APIO19_street_lamps)C++14
20 / 100
319 ms48496 KiB
//#define NDEBUG

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) ((a + b - 1) / b)
#define tomax(a, b) (a = max(a, b))
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

//#define TEST

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

int main(){
    StarBurstStream

    int n, q;
    cin >> n >> q;

    string s;
    cin >> s;

    vector<int> o(n, q);
    for(int i = 0; i < n; i++){
        if(s[i] == '1') o[i] = -1;
    }

    vector<pair<int, pii>> qry;

    for(int i = 0; i < q; i++){
        string t;
        cin >> t;

        if(t == "toggle"){
            int x;
            cin >> x;
            x--;
            o[x] = i;
        }
        else{
            int a, b;
            cin >> a >> b;
            a--; b -= 2;
            qry.eb(mp(i, mp(a, b)));
        }
    }

    vector<vector<int>> st(n, vector<int>(20));
    for(int i = 0; i < n ;i++) st[i][0] = o[i];
    for(int i = 1; i < 20; i++){
        for(int j = 0; j + (1 << i) - 1 < n; j++){
            st[j][i] = max(st[j][i - 1], st[j + (1 << (i - 1))][i - 1]);
        }
    }

    for(auto i : qry){
        int l = i.S.F, r = i.S.S;
        int lg = __lg(r - l + 1);
        int tmp = max(st[l][lg], st[r - (1 << lg) + 1][lg]);
        cout << max(0, i.F - tmp) << "\n";
    }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...