제출 #952983

#제출 시각아이디문제언어결과실행 시간메모리
952983Vladth11가로등 (APIO19_street_lamps)C++14
20 / 100
195 ms25936 KiB
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")

using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;

const ll NMAX = 300001;
const int INF = 1e9;
const ll nrbits = 20;
const ll MOD = 998244353;

int a[NMAX];
string s[NMAX];
int qa[NMAX];
int qb[NMAX];

int aint[NMAX * 4];

void update(int node, int st, int dr, int a, int b){
    if(st == dr){
        aint[node] = b;
        return;
    }
    int mid = (st + dr) / 2;
    if(a <= mid)
        update(node * 2, st, mid, a, b);
    else
        update(node * 2 + 1, mid + 1, dr, a, b);
    aint[node] = max(aint[node * 2], aint[node * 2 + 1]);
}

int query(int node, int st, int dr, int a, int b){
    if(a <= st && dr <= b)
        return aint[node];
    int mid = (st + dr) / 2;
    int sol = 0;
    if(a <= mid)
        sol = max(sol, query(node * 2, st, mid, a, b));
    if(b > mid)
        sol = max(sol, query(node * 2 + 1, mid + 1, dr, a, b));
    return sol;
}

signed main() {
#ifdef HOME
    ifstream cin(".in");
    ofstream cout(".out");
#endif // HOME
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, i, q;
    cin >> n >> q;
    for(int i = 0; i < NMAX * 4; i++)
        aint[i] = 2e9;
    for(i = 1; i <= n; i++){
        char c;
        cin >> c;
        a[i] = c - '0';
        if(a[i] == 1){
            update(1, 1, n, i, 0);
        }
    }
    for(i = 1; i <= q; i++){
        cin >> s[i];
        cin >> qa[i];
        if(s[i][0] == 'q'){
            cin >> qb[i];
            qb[i]--;
            cout << max(0, i - query(1, 1, n, qa[i], qb[i])) << "\n";
        }else{
            update(1, 1, n, qa[i], i);
        }
    }
    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...