Submission #888269

# Submission time Handle Problem Language Result Execution time Memory
888269 2023-12-16T18:59:31 Z drAKu Money (IZhO17_money) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

mt19937 rng(228);
const int N = 1e6 + 1;
int a[N], ans[N];
const int G = (1 << 20);
int t[2 * G];
int get(int ql, int qr) {
    int ans = 0;
    for (ql += G, qr += G; ql <= qr; ql >>= 1, qr >>= 1) {
        if (ql & 1) ans ^= t[ql++];
        if (~qr & 1) ans ^= t[qr--];
    }
    return ans;
}
void upd(int ql, int val) {
    for (ql += G, t[ql] ^= val, ql >>= 1; ql; ql >>= 1) t[ql] = t[ql << 1] ^ t[ql << 1 | 1];
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 1; i < n; i++) {
        if (a[i-1] > a[i]) continue;
        if (a[i-1] == a[i] || a[i] == a[i-1] + 1) {
            ans[i] = 1;
            if (ans[i-1] == 1 && a[i-1] + 1 <= a[i] - 1) {
                t = rng();
                upd(a[i-2] + 1, t);
                upd(a[i] - 1, t);
            }
            continue;
        }
        int good = get(a[i-1], a[i]);
        if (good == 0) {
            ans[i] = 1;
            int t = rng();
            upd(a[i-1] + 1, t);
            upd(a[i] - 1, t);
            if (ans[i-1] == 1) {
                t = rng();
                upd(a[i-2] + 1, t);
                upd(a[i] - 1, t);
            }
        }
    }
    cout << n - accumulate(ans, ans + N, 0) << "\n";
}

Compilation message

money.cpp: In function 'int main()':
money.cpp:35:19: error: incompatible types in assignment of 'std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::result_type' {aka 'long unsigned int'} to 'int [2097152]'
   35 |                 t = rng();
      |                 ~~^~~~~~~
money.cpp:36:33: error: invalid conversion from 'int*' to 'int' [-fpermissive]
   36 |                 upd(a[i-2] + 1, t);
      |                                 ^
      |                                 |
      |                                 int*
money.cpp:20:22: note:   initializing argument 2 of 'void upd(int, int)'
   20 | void upd(int ql, int val) {
      |                  ~~~~^~~
money.cpp:37:31: error: invalid conversion from 'int*' to 'int' [-fpermissive]
   37 |                 upd(a[i] - 1, t);
      |                               ^
      |                               |
      |                               int*
money.cpp:20:22: note:   initializing argument 2 of 'void upd(int, int)'
   20 | void upd(int ql, int val) {
      |                  ~~~~^~~