Submission #91005

# Submission time Handle Problem Language Result Execution time Memory
91005 2018-12-25T14:50:43 Z popovicirobert Money (IZhO17_money) C++14
0 / 100
2 ms 636 KB
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44

using namespace std;

const int MAXN = (int) 1e6;

int arr[MAXN + 1];
int aib[MAXN + 1];

inline void update(int pos, int n) {
    for(int i = pos; i <= n; i += lsb(i)) {
        aib[i]++;
    }
}

inline int query(int pos) {
    int ans = 0;
    for(int i = pos; i > 0; i -= lsb(i)) {
        ans += aib[i];
    }
    return ans;
}

inline int sum(int l, int r) {
    return query(r) - query(l - 1);
}

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    for(i = 1; i <= n; i++) {
        cin >> arr[i];
    }
    int ans = 0;
    i = 1;
    while(i <= n) {
        int j = i + 1;
        update(arr[i], n);
        ans++;
        while(j <= n && arr[j] >= arr[j - 1] && sum(arr[j - 1] + 1, arr[j]) == 0) {
            update(arr[j], n);
            j++;
        }
        i = j;
    }
    cout << ans;
    //cin.close();
    //cout.close();
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 584 KB Output is correct
4 Incorrect 2 ms 636 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 584 KB Output is correct
4 Incorrect 2 ms 636 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 584 KB Output is correct
4 Incorrect 2 ms 636 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 584 KB Output is correct
4 Incorrect 2 ms 636 KB Output isn't correct
5 Halted 0 ms 0 KB -