Submission #1085570

# Submission time Handle Problem Language Result Execution time Memory
1085570 2024-09-08T12:33:13 Z vjudge1 Simple game (IZhO17_game) C++17
0 / 100
1 ms 348 KB
#include "bits/stdc++.h"
#define ll long long

using namespace std;

const int sz = 1e5 + 5;

int fw[sz], a[sz];
int n;

void add(int v, int k) {
    for (; v <= n; v += v & -v)
        fw[v] += k;
}

int qry(int hi) {
    int r = 0;
    for (; 0 < hi; hi -= hi & -hi)
        r += fw[hi];
    return r;
}

void relax(int v, int k) {
    int r = (v - 2 + n) % n;
    r ++;
    if (a[r] < a[v])
        add(a[r] + 1, k);
    else if (a[r] > a[v])
        add(a[v] + 1, k);
}

int main() {
    int m; cin >> n >> m;
    for (int i = 1; i <= n; i ++)
        cin >> a[i];
    for (int i = 1; i <= n; i ++)
        relax(i, 1);
    while (m --) {
        int t; cin >> t;
        if (1 == t) {
            int p, v; cin >> p >> v;
            int l = a[p];
            for (int i : {0, 1}) {
                if (1 == p and 0 == i)
                    continue;
                relax(p + i, -1);
                a[p] = v;
                relax(p + i, 1);
                a[p] = l;
            }
            a[p] = v;
        } else {
            int x; cin >> x;
            cout << qry(x) << '\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1 ms 348 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1 ms 348 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1 ms 348 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -