Submission #89963

#TimeUsernameProblemLanguageResultExecution timeMemory
89963vexVudu (COCI15_vudu)C++14
140 / 140
295 ms24072 KiB
#include <bits/stdc++.h> #define maxn 1000005 #define plli pair<long long,long long> using namespace std; long long n; plli a[maxn]; long long p; long long tree[maxn]={0}; long long manji(long long x) { x--; long long sol=0; while(x>0) { sol+=tree[x]; x-=x&-x; } return sol; } void update(long long x) { while(x<=n) { tree[x]++; x+=x&-x; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin>>n; a[0]={0,0}; for(int i=0;i<n;i++) { cin>>a[i+1].first; a[i+1].first+=a[i].first; a[i+1].second=i+1; } cin>>p; for(int i=0;i<=n;i++) { a[i].first-=p*a[i].second; } sort(a,a+n+1); long long sol=0; for(int i=0;i<=n;i++)a[i].second++; for(int i=0;i<=n;i++) { sol+=manji(a[i].second); update(a[i].second); } cout<<sol<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...