Submission #968645

# Submission time Handle Problem Language Result Execution time Memory
968645 2024-04-23T19:24:39 Z VMaksimoski008 Vudu (COCI15_vudu) C++14
42 / 140
483 ms 65536 KB
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;

struct BIT {
    int n;
    vector<ll> tree;

    void config(int _n) {
        n = _n + 10;
        tree.resize(_n+60);
    }

    void update(int p, int v) {
        for(p++; p<n; p+=p&-p) tree[p] += v;
    }

    ll query(int p) {
        ll ans = 0;
        for(p++; p>0; p-=p&-p) ans += tree[p];
        return ans;
    }
};


int32_t main() {
    int n, p;
    ll ans = 0;
    cin >> n;

    vector<ll> v(n+1);
    for(int i=1; i<=n; i++) cin >> v[i];

    cin >> p;
    ll sum = 0;
    for(int i=1; i<=n; i++) {
        sum += v[i];
        v[i] = sum - i * p;
    }

    set<ll> s;
    for(ll &x : v) s.insert(x);
    vector<int> comp(all(s));
    for(ll &x : v) x = lower_bound(all(comp), x) - comp.begin();

    BIT bit; bit.config(n);
    bit.update(v[0], 1);

    for(int i=1; i<=n; i++) {
        ans += bit.query(v[i]);
        bit.update(v[i], 1);
    }

    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 860 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Incorrect 483 ms 65536 KB Output isn't correct
5 Incorrect 264 ms 42064 KB Output isn't correct
6 Incorrect 417 ms 65496 KB Output isn't correct
7 Incorrect 426 ms 65536 KB Output isn't correct
8 Incorrect 381 ms 59344 KB Output isn't correct
9 Runtime error 457 ms 65536 KB Execution killed with signal 9
10 Incorrect 414 ms 65536 KB Output isn't correct