제출 #1316351

#제출 시각아이디문제언어결과실행 시간메모리
1316351aaaaaaaaSimple game (IZhO17_game)C++20
0 / 100
8 ms14904 KiB
#include <bits/stdc++.h>
using namespace std;
const int mxN = 1e6 + 10;
int seg[mxN * 4], lazy[mxN * 4];
void push(int node, int start, int end){
    if(lazy[node] == 0) return;
    seg[node] += lazy[node] * (end - start + 1);
    if(start ^ end){
        lazy[node * 2 + 1] += lazy[node];
        lazy[node * 2 + 2] += lazy[node];
    }
    lazy[node] = 0;
}
void update(int node, int start, int end, int l, int r, int x){
    push(node, start, end);
    if(start > r || end < l) return;
    if(start >= l && end <= r){
        lazy[node] = x;
        push(node, start, end);
        return;
    }
    int mid = start + (end - start) / 2;
    update(node * 2 + 1, start, mid, l, r, x);
    update(node * 2 + 2, mid + 1, end, l, r, x);
    seg[node] = seg[node * 2 + 1] + seg[node * 2 + 2];
}
int query(int node, int start, int end, int idx){
    push(node, start, end);
    if(start == end){
        return seg[node];
    }
    int mid = start + (end - start) / 2;
    if(idx <= mid) return query(node * 2 + 1, start, mid, idx);
    return query(node * 2 + 2, mid + 1, end, idx);
}
int query(int idx){
    return query(0, 1, mxN - 1, idx);
}
void update(int l, int r, int x){
    update(0, 1, mxN - 1, l, r, x);
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    int n, q;
    cin >> n >> q;
    vector<int> a(n + 1, 0);
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    for(int i = 1; i <= n - 1; ++i){
        update(min(a[i], a[i + 1]), max(a[i], a[i + 1]), 1);
    }
    while(q--){
        int t, l, r;
        cin >> t;
        if(t == 2){
            cin >> l;
            cout << query(l) << "\n";
        }else{
            cin >> l >> r;
            if(l == 1){
                update(min(a[l], a[l + 1]), max(a[l], a[l + 1]), -1);
                update(min(r, a[l + 1]), max(r, a[l + 1]), 1);
            }else if(l == n){
                update(min(a[l], a[l - 1]), max(a[l], a[l - 1]), -1);
                update(min(r, a[l - 1]), max(r, a[l - 1]), -1);
            }else{
                update(min(a[l], a[l + 1]), max(a[l], a[l + 1]), -1);
                update(min(a[l], a[l - 1]), max(a[l], a[l - 1]), -1);
                update(min(r, a[l + 1]), max(r, a[l + 1]), 1);
            }
            a[l] = r;
        }
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...