답안 #941096

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
941096 2024-03-08T07:04:34 Z atom Simple game (IZhO17_game) C++17
컴파일 오류
0 ms 0 KB
#include "bits/stdc++.h"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;

#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif

struct Fenwick {
    int n;
    vector <int> f;
    
    Fenwick (int _n): n(_n), f(_n + 5) {};
    int qry(int x) {
        int ans = 0;
        for (; x; x -= x & -x)
            ans += f[x];
        return ans;
    }
    void add(int x, int val) {
        for (; x <= n; x += x & -x)
            f[x] += val;
    }
};

const int N = 1e6 + 5;
signed main() {
    cin.tie(0) -> sync_with_stdio(0);

    int n, q;
    cin >> n >> q;
    vector <int> h(n + 5);
    vector <vector <int>> queries(q + 5);

    for (int i = 1; i <= n; ++i) cin >> h[i];

    bool sub2 = 1;
    for (int i = 1; i <= q; ++i) {
        int cmd; cin >> cmd;
        if (cmd == 1) {
            int x, y; cin >> x >> y;
            queries[i] = {cmd, x, y};
            sub2 = 0;
        }
        else {
            int x; cin >> x;
            queries[i] = {cmd, x};
        }
    }

    sub1
    if (n <= 1000 && q <= 1000) {
        vector <int> cnt(N, 0);
        for (int i = 1; i <= n; ++i) cnt[h[i]]++;
        for (int i = 1; i <= q; ++i) {
            if (queries[i][0] == 1) {
                cnt[h[queries[i][1]]]--;
                h[queries[i][1]] = queries[i][2];
                cnt[h[queries[i][1]]]++;
            }
            else {
                int ans = 0;
                int H = queries[i][1];
                for (int j = 2; j <= n; ++j)
                    if ((h[j - 1] < H && H < h[j]) || (h[j - 1] > H && H > h[j]))
                        ++ans;
                cout << ans << "\n";
            }
        }
    }
    // else 
    if (sub2) {
        // Fenwick
        vector <int> cnt(N);
        vector <int> prf(N);
        for (int i = 1; i <= n; ++i)
            cnt[h[i]]++;
        for (int i = 2; i <= n; ++i) {
            int l = h[i - 1], r = h[i];
            if (l > r) swap(l, r);
            l++, r--;
            if (l <= r) {
                prf[l]++;
                prf[r + 1]--;
            }
        }
        for (int i = 1; i < N; ++i) prf[i] += prf[i - 1];
        for (int i = 1; i <= q; ++i) {
            cout << (cnt[queries[i][1]] + prf[queries[i][1]]) << "\n";
        }
    }
    else {

    }
}


Compilation message

game.cpp: In function 'int main()':
game.cpp:54:5: error: 'sub1' was not declared in this scope; did you mean 'sub2'?
   54 |     sub1
      |     ^~~~
      |     sub2