Submission #456373

# Submission time Handle Problem Language Result Execution time Memory
456373 2021-08-06T14:39:17 Z Sarah_Mokhtar Vudu (COCI15_vudu) C++14
126 / 140
640 ms 45584 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define read freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define LESSGO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll N=1e6+10,M=505,OO=1e16,mod=1e9+7;
ll n,k,a[N],ans,sum;
int tree[N<<2],val[N],idx;
vector<pair<ll,int>>prefixes;
void compress(){
    sort(prefixes.begin(),prefixes.end());
    ll prev=-1;
    for(auto i:prefixes){
        if(i.first!=prev) ++idx;
        val[i.second]=idx;
        prev=i.first;
    }
}
void update(int node,int st,int en,int idx,int val){
    if(st==en){
        tree[node]+=val;
        return;
    }
    int mid=(st+en)>>1;
    if(idx<=mid) update(2*node,st,mid,idx,val);
    else update(2*node+1,mid+1,en,idx,val);
    tree[node]=tree[2*node]+tree[2*node+1];
}
int get(int node,int st,int en,int l,int r){
    if(en<l||st>r) return 0;
    if(st>=l&&en<=r) return tree[node];
    int mid=(st+en)>>1;
    return get(2*node,st,mid,l,r)+get(2*node+1,mid+1,en,l,r);
}
int main(){
    LESSGO;
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    cin>>k;
    for(int i=0;i<n;++i){
        a[i]-=k;
        sum+=a[i];
        prefixes.push_back({sum,i});
    }
    compress();
    sum=0;
    for(int i=0;i<n;++i){
        sum+=a[i];
        ans+=get(1,0,n-1,0,val[i]);
        update(1,0,n-1,val[i],1);
        if(sum>=0) ++ans;
        
    }
    cout<<ans<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 716 KB Output is correct
2 Correct 3 ms 588 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
4 Correct 640 ms 44336 KB Output is correct
5 Correct 349 ms 23568 KB Output is correct
6 Incorrect 568 ms 40412 KB Output isn't correct
7 Correct 602 ms 41576 KB Output is correct
8 Correct 504 ms 37268 KB Output is correct
9 Correct 627 ms 45584 KB Output is correct
10 Correct 559 ms 40716 KB Output is correct