제출 #219229

#제출 시각아이디문제언어결과실행 시간메모리
219229gabrc52Vudu (COCI15_vudu)C++14
140 / 140
504 ms43360 KiB
#include <iostream> #include <cassert> #include <algorithm> using namespace std; typedef long long ll; const int MAXN=1e6; int N; int arr[MAXN]; int P; ll ac[MAXN]; ll sum[MAXN]; ll dif[MAXN]; ll sorted[MAXN]; ll than; ll ans; ll ft[MAXN]; void inc(int i) { for (; i < N; i |= i+1) ++ft[i]; } int get(int i) { int r = 0; for (; i >= 0; i = (i&(i+1)) - 1) r += ft[i]; return r; } void remove(ll val) { int lb = lower_bound(sorted,sorted+N,val) - sorted; inc(lb); } int countLowerOrEqual(ll val) { int ub = upper_bound(sorted,sorted+N,val) - sorted; return ub - get(ub-1); return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>N; for (int i=0; i<N; i++) { cin>>arr[i]; } cin>>P; ac[0] = arr[0]; for (int i=1; i<N; i++) { ac[i] = arr[i] + ac[i-1]; } sum[0] = P; sorted[0] = dif[0] = sum[0] - ac[0]; for (int i=1; i<=N; i++) { sum[i] = sum[i-1] + P; sorted[i] = dif[i] = sum[i] - ac[i]; } sort(sorted, sorted+N); than = 0; ans += countLowerOrEqual(0); for (int i=1; i<N; i++) { remove(dif[i-1]); than += P - arr[i-1]; ans += countLowerOrEqual(than); } cout<<ans<<'\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...