Submission #94545

#TimeUsernameProblemLanguageResultExecution timeMemory
94545theknife2001Vudu (COCI15_vudu)C++17
140 / 140
334 ms45356 KiB
#include <bits/stdc++.h> #define ll long long #define mid (l+r)/2 #define ii pair < ll , int > #define se second #define fi first using namespace std; const int N=1e6+55; vector < ii > vec; int tree[N]; ll sum[N]; ll a[N]; int n; bool cmp (ii A, ii B) { if (A.first != B.first) return A.first < B.first; return A.second > B.second; } int query(int x) { if(x<=0) return 0; return query(x-(x&(-x)))+tree[x]; } void update(int x) { if(x>n) return ; tree[x]++; update(x+(x&(-x))); } int main() { ios::sync_with_stdio(false); cin>>n; for(int i=0;i<n;i++) cin>>a[i]; int p; cin>>p; for(int i=n-1;i>=0;i--) { sum[i]=a[i]-p; if(i!=n-1) sum[i]+=sum[i+1]; a[i]=sum[i]; } for(int i=0;i<n;i++) { vec.push_back({a[i],i+1}); } sort(vec.begin(),vec.end(),cmp); int cnt=1; ll ans=0; for(int i=0;i<n;i++) { // cout<<vec[i].fi<<' '<<vec[i].se<<endl; if(vec[i].fi>=0) ans++; ans+=(i)-query(vec[i].se); // cout<<ans<<endl; update(vec[i].se); } cout<<ans<<endl; return 0; }

Compilation message (stderr)

vudu.cpp: In function 'int main()':
vudu.cpp:57:9: warning: unused variable 'cnt' [-Wunused-variable]
     int cnt=1;
         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...