Submission #60056

#TimeUsernameProblemLanguageResultExecution timeMemory
60056Adhyyan1252Vudu (COCI15_vudu)C++11
140 / 140
644 ms32020 KiB
#include<bits/stdc++.h> // 6 47 typedef long long ll; #define NMAX 1000005 #define SMAX 2300000 using namespace std; int bit[NMAX]; int n; void add(int indx){ for(int i = indx; i <= n; i += (i&-i)){ bit[i] += 1; } } ll query(int indx){ ll ans = 0; for(int i = indx; i > 0; i -= (i&-i)){ ans += bit[i]; } return ans; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cin>>n; ll a[n]; for(int i = 0; i < n; i++){ cin>>a[i]; } ll p; cin>>p; vector<pair<ll, int> > vi; ll zero = 0; for(int i = n-1; i >= 0; i--){ a[i] -= p; zero -= a[i]; ll cur = zero + a[i]; //cout<<i<<" PUSH: "<<cur<<endl; vi.push_back({cur, i}); } sort(vi.begin(), vi.end()); vector<int> indx(n); for(int i = 0; i < n; i++){ indx[vi[i].second] = i; } ll ans = 0; zero = 0; for(int i = n-1; i >= 0; i--){ add(indx[i]+1); zero -= a[i]; pair<ll, int> temp = {zero, 0}; int index = lower_bound(vi.begin(), vi.end(), temp) - vi.begin(); ans += query(n) - query(index); } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...