답안 #758109

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
758109 2023-06-14T07:33:23 Z vjudge1 Simple game (IZhO17_game) C++17
100 / 100
346 ms 32984 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int mxN = 1e6 + 7;
const int SZ = exp2(ceil(log2(mxN)));

int arr[mxN], seg[2 * SZ], lazy[2 * SZ];

void push(int ind, int l, int r) {
    seg[ind] += (r - l + 1) * lazy[ind];
    if (l != r) {
        lazy[2 * ind] += lazy[ind];
        lazy[2 * ind + 1] += lazy[ind];
    }
    lazy[ind] = 0;
}

void update(int lo, int hi, int val, int ind = 1, int l = 1, int r = SZ) {
    push(ind, l, r);
    if (hi < l || lo > r) {
        return;
    }

    if (lo <= l && r <= hi) {
        lazy[ind] += val;
        push(ind, l, r);
        return;
    }

    int mid = (l + r) / 2;
    update(lo, hi, val, 2 * ind, l, mid);
    update(lo, hi, val, 2 * ind + 1, mid + 1, r);

    seg[ind] = seg[2 * ind] + seg[2 * ind] + 1;
}

int query(int pos, int ind = 1, int l = 1, int r = SZ) {
    push(ind, l, r);
    if (l == r) {
        return seg[ind];
    }

    int mid = (l + r) / 2;
    if (pos <= mid) {
        return query(pos, 2 * ind, l, mid);
    }
    else {
        return query(pos, 2 * ind + 1, mid + 1, r);
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, m;
    cin >> n >> m;

    for (int i = 0; i < n; ++i) {
        cin >> arr[i];

        if (i) {
            update(min(arr[i - 1], arr[i]), max(arr[i - 1], arr[i]), 1);
        }
    }

    while (m--) {
        int t;
        cin >> t;
        
        if (t == 1) {
            int pos, val;
            cin >> pos >> val;
            --pos;
            
            if (pos) {
                update(min(arr[pos - 1], arr[pos]), max(arr[pos - 1], arr[pos]), -1);
            }
            if (pos < n - 1) {
                update(min(arr[pos + 1], arr[pos]), max(arr[pos + 1], arr[pos]), -1);
            }
            arr[pos] = val;
            if (pos) {
                update(min(arr[pos - 1], arr[pos]), max(arr[pos - 1], arr[pos]), 1);
            }
            if (pos < n - 1) {
                update(min(arr[pos + 1], arr[pos]), max(arr[pos + 1], arr[pos]), 1);
            }
        }
        else {
            int h;
            cin >> h;
            
            cout << query(h) << "\n";
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 13 ms 24016 KB Output is correct
3 Correct 13 ms 23176 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 13 ms 23764 KB Output is correct
6 Correct 13 ms 23888 KB Output is correct
7 Correct 8 ms 18644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 13 ms 24016 KB Output is correct
3 Correct 13 ms 23176 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 13 ms 23764 KB Output is correct
6 Correct 13 ms 23888 KB Output is correct
7 Correct 8 ms 18644 KB Output is correct
8 Correct 99 ms 1648 KB Output is correct
9 Correct 160 ms 32968 KB Output is correct
10 Correct 177 ms 32984 KB Output is correct
11 Correct 109 ms 1400 KB Output is correct
12 Correct 103 ms 2668 KB Output is correct
13 Correct 95 ms 32964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 13 ms 24016 KB Output is correct
3 Correct 13 ms 23176 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 13 ms 23764 KB Output is correct
6 Correct 13 ms 23888 KB Output is correct
7 Correct 8 ms 18644 KB Output is correct
8 Correct 99 ms 1648 KB Output is correct
9 Correct 160 ms 32968 KB Output is correct
10 Correct 177 ms 32984 KB Output is correct
11 Correct 109 ms 1400 KB Output is correct
12 Correct 103 ms 2668 KB Output is correct
13 Correct 95 ms 32964 KB Output is correct
14 Correct 316 ms 32736 KB Output is correct
15 Correct 324 ms 32780 KB Output is correct
16 Correct 343 ms 32752 KB Output is correct
17 Correct 324 ms 32732 KB Output is correct
18 Correct 346 ms 32732 KB Output is correct