#include<bits/stdc++.h>
using namespace std;
int n, fw[1000001];
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;
}
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n;
long long qs[n+1], k;
vector<long long> v;
memset(qs, 0, sizeof(qs));
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()), 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
255 ms |
28840 KB |
Output is correct |
5 |
Correct |
139 ms |
19400 KB |
Output is correct |
6 |
Correct |
237 ms |
25592 KB |
Output is correct |
7 |
Correct |
220 ms |
26456 KB |
Output is correct |
8 |
Correct |
197 ms |
24504 KB |
Output is correct |
9 |
Correct |
251 ms |
29992 KB |
Output is correct |
10 |
Correct |
220 ms |
25888 KB |
Output is correct |