Submission #968011

# Submission time Handle Problem Language Result Execution time Memory
968011 2024-04-23T06:54:39 Z jadai007 Vudu (COCI15_vudu) C++14
42 / 140
128 ms 46228 KB
#include<bits/stdc++.h>
 
using namespace std;
 
int n, arr[1000100] , fw[2200100], k;
long long qs[1000100];
vector<long long> v;
long long ans;
 
void update(int idx, int val){
    for(; idx <= n; idx+=(idx&-idx)) fw[idx]+=val;
}
 
long long query(int idx){
    long long sum = 0;
    for(; idx; idx-=(idx&-idx)) sum+=fw[idx];
    return sum;
}
 
signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n;
    for(int i = 1; i<=n; ++i) cin >> arr[i];
    cin >> k;
    for(int i = 1; i<=n; ++i) qs[i] = qs[i - 1] + arr[i];
    for(int i = 0; i<=n; ++i) v.push_back(qs[i] - i*k);
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()));
    //update(1, 1);
    for(int i = 0; i<=n; ++i){
        int id = lower_bound(v.begin(), v.end(), qs[i] - i*k) - v.begin();
        ans+=query(id+1);
        update(id+1, 1);
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4700 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 2 ms 4700 KB Output is correct
4 Runtime error 121 ms 46040 KB Execution killed with signal 11
5 Runtime error 87 ms 38852 KB Execution killed with signal 11
6 Runtime error 109 ms 44984 KB Execution killed with signal 11
7 Runtime error 113 ms 45248 KB Execution killed with signal 11
8 Runtime error 99 ms 44336 KB Execution killed with signal 11
9 Runtime error 128 ms 46228 KB Execution killed with signal 11
10 Runtime error 113 ms 45072 KB Execution killed with signal 11