답안 #968649

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968649 2024-04-23T19:31:41 Z VMaksimoski008 Vudu (COCI15_vudu) C++14
126 / 140
714 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<int> tree;

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

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

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


int main() {
    int n, p, i;
    cin >> n;

    ll v[n+1], ans = 0; v[0] = 0;
    for(i=1; i<=n; i++) cin >> v[i];

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

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

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

    cout << ans << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 856 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 714 ms 65536 KB Output is correct
5 Correct 347 ms 36756 KB Output is correct
6 Correct 686 ms 57172 KB Output is correct
7 Correct 580 ms 59732 KB Output is correct
8 Correct 527 ms 51616 KB Output is correct
9 Runtime error 600 ms 65536 KB Execution killed with signal 9
10 Correct 563 ms 58104 KB Output is correct