Submission #48440

#TimeUsernameProblemLanguageResultExecution timeMemory
48440aleksamiVudu (COCI15_vudu)C++14
140 / 140
426 ms65536 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define MAXN 1000005 ll a[MAXN]; int bit[MAXN]; void update(int idx,int val) { while(idx < MAXN) { bit[idx]+=val; idx+=idx&(-idx); } } int get(int idx) { int s=0; while(idx > 0) { s+=bit[idx]; idx-=idx&(-idx); } return s; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; for(int i = 1; i <= n; i++) { cin >> a[i]; } vector <ll> v; ll p; cin >> p; for(int i = 1; i <= n; i++)a[i]-=p; for(int i = 1; i <= n; i++) { a[i]+=a[i-1]; v.push_back(a[i]); } v.push_back(0LL); sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); ll ans = 0LL; for(int i = 0; i <= n; i++) { a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin()+1; if(i>0)update(a[i-1],1); ans += get(a[i]); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...