Submission #706584

# Submission time Handle Problem Language Result Execution time Memory
706584 2023-03-07T05:53:08 Z Shreyan_Paliwal Money (IZhO17_money) C++17
0 / 100
1 ms 304 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e6;

int n;
int a[maxn + 5];

int bit[maxn + 1];
void upd(int k, int v) {
    for ( ; k <= n; k += (k & -k))
        bit[k] += v;
}
int qry(int k) {
    int ret = 0;
    for (; k; k -= (k & -k))
        ret += bit[k];
    return ret;
}

int main() {
    // freopen("main.in", "r", stdin);

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


    // figure out nondecreasing sequences
    int l = 0;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (i == n - 1 || a[i + 1] < a[i]) {
            // [l, i]
            for (int j = l + 1; j <= i; j++) {
                // cout << l << ' ' << i << ' ' << j << endl;
                // cout << qry(j) << ' ' << qry(j-1) << endl;
                if (qry(a[j]) - qry(a[j - 1]))
                    ans++;
            }
            for (int j = l; j <= i; j++) {
                upd(a[j], 1);
            }
            ans++;
            l = i + 1;
        }
    }

    cout << ans << endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -