Submission #1296873

#TimeUsernameProblemLanguageResultExecution timeMemory
1296873wedonttalkanymoreMoney (IZhO17_money)C++20
0 / 100
4 ms6728 KiB
#include <bits/stdc++.h>
/*
    Checklist: 
    - Check statement: 
    - Check filename: 
    - Check test limit: 
    - Stresstest: 
*/
using namespace std;
using ll = long long;

#define int long long
#define pii pair<ll, ll>
#define fi first
#define se second

const ll N = 2e5 + 5, inf = 1e18, mod = 1e9 + 7, block = 320, lim = 19;

int n, a[N];

struct Fenwick {
    vector <int> bit;
    int sz;
    Fenwick(int _n) {
        bit.assign(4 * (_n + 5), 0);
        sz = _n;
    }
    void update(int i, int val) {
        while(i <= sz) {
            bit[i] += val;
            i += i & -i;
        }
    }
    int get(int i) {
        int res = 0;
        while(i > 0) {
            res += bit[i];
            i -= i & -i;
        }
        return res;
    }
    int get(int l, int r) {
        return get(r) - get(l - 1);
    }
} fw(N);

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    if (fopen(".inp", "r")) {
        freopen(".inp", "r", stdin);
        freopen(".out", "w", stdout);
    }
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    int cnt = 0;
    int l = 1;
    for (int i = 2; i <= n; i++) {
        // cout << i << '\n';
        if (a[i - 1] > a[i]) {
            // cout << "ok: " << '\n';
            while(l < i) {
                fw.update(a[l], 1);
                l++;
            }
            // i = l + 1;
            cnt++;
        }
        else if (fw.get(a[l] + 1, a[i] - 1)) {
            // cout << "ok: " << '\n';
            while(l < i) {
                fw.update(a[l], 1);
                l++;
            }
            // i = l + 1;
            cnt++;
        }
        // else i++;
        // cout << i << ' ' << l << ' ' << cnt << '\n';
    }
    cout << cnt + 1 << '\n';
    return 0;
}

Compilation message (stderr)

money.cpp: In function 'int main()':
money.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen(".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
money.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         freopen(".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...