답안 #734717

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
734717 2023-05-03T00:42:23 Z grossly_overconfident 가로등 (APIO19_street_lamps) C++17
20 / 100
249 ms 14508 KB
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
//#define int long long
vector<int> t;


int traverse(int v, int tl, int tr, int l, int r){
    //cout << tl << " " << tr << " " << l << " " << r << endl;
    if (tl == l && tr == r){
        return t[v];
    }
    int tm = (tl + tr) / 2;
    if (r <= tm){
        return traverse(v * 2, tl, tm, l, r);
    }
    if (l >= tm + 1){
        return traverse(v * 2 + 1, tm + 1, tr, l, r);
    }
    return max(traverse(v * 2, tl, tm, l, tm), traverse(v * 2 + 1, tm + 1, tr, tm + 1, r));
}

void update(int v, int tl, int tr, int val, int pos){
    if (tl == tr){
        t[v] = val;
        return;
    }
    int tm = (tl + tr) / 2;
    if (pos <= tm){
        update(v * 2, tl, tm, val, pos);
    }
    if (pos > tm){
        update(v * 2 + 1, tm + 1, tr, val, pos);
    }
    t[v] = max(t[v * 2], t[v * 2 + 1]);
}

signed main(){
    
    cin.tie(0);
    iostream::sync_with_stdio(0);

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

    t.resize(n * 4);

    string lamps;
    cin >> lamps;
    
    for (int i = 0; i < n; ++i){
        if (lamps[i] == '1'){
            update(1, 0, n - 1, 0, i);
        }
        else{
            update(1, 0, n - 1, 400000, i);
        }
    }
    
    vector<int> l(n);
    for (int i = 0; i < n; ++i){
        if (lamps[i] == '0'){
            l[i] = 400000;
        }
    }

    for (int i = 0; i < q; ++i){
        string s; int a, b;
        cin >> s;
        if (s == "toggle"){
            cin >> a;
            update(1, 0, n - 1, i + 1, a - 1);
        }
        else{
            cin >> a >> b;
            int out = traverse(1, 0, n - 1, a - 1, b - 2);
            //cout << "debug: " << out << endl;
            if (out == 400000){
                cout << 0 << endl;
            }
            else{
                cout << i - out + 1 << endl;
            }
        }
    }


    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 79 ms 3908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 142 ms 10812 KB Output is correct
6 Correct 194 ms 11604 KB Output is correct
7 Correct 242 ms 12208 KB Output is correct
8 Correct 235 ms 14496 KB Output is correct
9 Correct 80 ms 3928 KB Output is correct
10 Correct 86 ms 4172 KB Output is correct
11 Correct 94 ms 4456 KB Output is correct
12 Correct 249 ms 13072 KB Output is correct
13 Correct 236 ms 14508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -