Submission #1298679

#TimeUsernameProblemLanguageResultExecution timeMemory
1298679tabVudu (COCI15_vudu)C++20
42 / 140
672 ms78668 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define intt long long
#define fi first
#define se second

const intt mxN = 1e5 + 5;
const intt LG = 20;
const intt inf = 1e18;  
const intt mod = 10007;

intt n, p;
vector<intt> a(mxN), pre(mxN);

void _() {
    cin >> n;
    a.resize(n);
    pre.resize(n);
    for(intt i = 0; i < n; i++) {
        cin >> a[i];
        pre[i] = a[i];
        if(i) pre[i] += pre[i-1];
    }
    cin >> p;
    ordered_multiset<intt> mst;
    mst.insert(pre[0]);
    intt ans = 0;
    for(intt i = 1; i < n; i++) {
        ans += mst.order_of_key((pre[i] - p * i) + 1);
        mst.insert(pre[i] - p * i);
    }
    for(intt i = 0; i < n; i++) {
        if(pre[i] / (i + 1) >= p) {
            ans++;
        }
    }
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    intt t = 1, buu = 1;
    // cin >> t;
    while(t--){
        // cout << "Case #" << buu++ << ": ";
        _();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...