#include<bits/stdc++.h>
using namespace std;
int n;
long long qs[1000100], k,arr[1000100];
vector<long long> v;
long long ans, fw[1000100];
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 >> arr[i];
cin >> k;
for(int i = 1; i<=n; ++i) qs[i] = qs[i - 1] + arr[i];
for(int i = 0; i<=n; ++i) v.push_back(qs[i] - i*k);
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()));
//update(1, 1);
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4696 KB |
Output is correct |
2 |
Correct |
3 ms |
4700 KB |
Output is correct |
3 |
Correct |
2 ms |
4700 KB |
Output is correct |
4 |
Correct |
250 ms |
31276 KB |
Output is correct |
5 |
Correct |
146 ms |
21908 KB |
Output is correct |
6 |
Runtime error |
134 ms |
50676 KB |
Execution killed with signal 11 |
7 |
Correct |
214 ms |
30264 KB |
Output is correct |
8 |
Correct |
194 ms |
30772 KB |
Output is correct |
9 |
Correct |
248 ms |
31844 KB |
Output is correct |
10 |
Correct |
229 ms |
30508 KB |
Output is correct |