Submission #875444

#TimeUsernameProblemLanguageResultExecution timeMemory
875444imarnVudu (COCI15_vudu)C++14
140 / 140
160 ms21124 KiB
#include<bits/stdc++.h> #define ld long double #define pii pair<int,int> #define pll pair<ll,ll> #define all(x) x.begin(),x.end() #define pb push_back #define sz(x) (int)x.size() #define f first #define s second #define vi vector<int> #define vpii vector<pii> #define ll long long using namespace std; const int N=1e6+5; ll a[N]{0}; ll cnt=0; void dac(int l,int r){ if(l>=r)return; int m=(l+r)>>1; dac(l,m);dac(m+1,r); int sz1=m-l+1,sz2=r-m; ll le[sz1],re[sz2]; for(int i=0;i<sz1;i++)le[i]=a[i+l]; for(int i=0;i<sz2;i++)re[i]=a[m+1+i]; int li=0,ri=0,mi=l; while(li<sz1&&ri<sz2){ if(le[li]<=re[ri])cnt+=sz2-ri,a[mi++]=le[li++]; else a[mi++]=re[ri++]; }while(li<sz1)a[mi++]=le[li++]; while(ri<sz2)a[mi++]=re[ri++]; } int main(){ ios_base::sync_with_stdio(false);cin.tie(0); int n;cin>>n; for(int i=1;i<=n;i++)cin>>a[i]; ll p;cin>>p; for(int i=1;i<=n;i++)a[i]+=a[i-1]-p; dac(0,n);cout<<cnt; }
#Verdict Execution timeMemoryGrader output
Fetching results...