Submission #100851

#TimeUsernameProblemLanguageResultExecution timeMemory
100851dalgerokVudu (COCI15_vudu)C++17
140 / 140
421 ms29736 KiB
#include<bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int n, p, t[N]; long long a[N], b[N]; inline int get(int pos){ int cur = 0; for(int i = pos; i >= 0; i &= i + 1, i--){ cur += t[i]; } return cur; } inline int upd(int pos){ for(int i = pos; i <= n; i |= i + 1){ t[i] += 1; } } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; } cin >> p; a[0] = -p; b[0] = -p; for(int i = 1; i <= n; i++){ a[i] -= p; a[i] += a[i - 1]; b[i] = a[i]; } sort(b, b + n + 1); long long ans = 0; upd(lower_bound(b, b + n + 1, -p) - b); for(int i = 1; i <= n; i++){ a[i] = lower_bound(b, b + n + 1, a[i]) - b; ans += get(a[i]); upd(a[i]); } cout << ans; }

Compilation message (stderr)

vudu.cpp: In function 'int upd(int)':
vudu.cpp:23:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...