Submission #968033

#TimeUsernameProblemLanguageResultExecution timeMemory
968033jadai007Vudu (COCI15_vudu)C++14
126 / 140
260 ms34512 KiB
#include<bits/stdc++.h> using namespace std; int n, fw[1000100]; long long qs[1000100], k; vector<long long> v; long long ans; void update(int idx, int val){ for(; idx <= n; idx+=(idx&-idx)) fw[idx]+=val; } long long query(int idx){ long long sum = 0; for(; idx; idx-=(idx&-idx)) sum+=fw[idx]; return sum; } signed main(){ cin.tie(nullptr)->sync_with_stdio(false); cin >> n; for(int i = 1; i<=n; ++i) cin >> qs[i]; cin >> k; for(int i = 1; i<=n; ++i) qs[i]+=qs[i - 1]; for(int i = 1; i<=n; ++i) v.push_back(qs[i] - i*k); sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end())); for(int i = 0; i<=n; ++i){ int id = lower_bound(v.begin(), v.end(), qs[i] - i*k) - v.begin(); ans+=query(id+1); update(id+1, 1); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...