Submission #762720

# Submission time Handle Problem Language Result Execution time Memory
762720 2023-06-21T17:00:49 Z ETheBest3 Vudu (COCI15_vudu) C++17
56 / 140
349 ms 65536 KB
#include<bits/stdc++.h>
#define endl "\n"
#define lli long long
using namespace std;
const lli MAXN=1000005;
lli N, a[MAXN], P, pref[MAXN], tree[MAXN], ss[MAXN], ans;
map<lli, lli> m;
void update(lli i, lli d){
    while(i<=N){
        tree[i]+=d;
        i+=i&(-i);
    }
    return;
}
lli query(lli i){
    lli otg=0;
    while(i>0){
        otg+=tree[i];
        i-=i&(-i);
    }
    return otg;
}
int main() {
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    cin>>N;
    for(lli i=1; i<=N; i++){
        cin>>a[i];
    }
    cin>>P;
    for(lli i=1; i<=N; i++){
        a[i]-=P;
        pref[i]=pref[i-1]+a[i];
        ss[i]=pref[i];
    }
    sort(ss, ss+N+1);
    lli k=1;
    for(lli i=0; i<N+1; i++){
        if(i!=0 and ss[i]==ss[i-1])continue;
        m[ss[i]]=k;
        k++;
    }
    update(m[0], 1);
    for(lli i=1; i<=N; i++){
        ans+=query(m[pref[i]]);
        update(m[pref[i]], 1);
    }
    cout<<ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 980 KB Output is correct
2 Correct 3 ms 892 KB Output is correct
3 Correct 3 ms 852 KB Output is correct
4 Runtime error 252 ms 65536 KB Execution killed with signal 9
5 Correct 349 ms 56884 KB Output is correct
6 Runtime error 249 ms 65536 KB Execution killed with signal 9
7 Runtime error 243 ms 65536 KB Execution killed with signal 9
8 Runtime error 230 ms 65536 KB Execution killed with signal 9
9 Runtime error 255 ms 65536 KB Execution killed with signal 9
10 Runtime error 230 ms 65536 KB Execution killed with signal 9