#include<bits/stdc++.h>
using namespace std;
int n, fw[1000001];
long long qs[1000001], k;
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;
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()));
for(int i = 1; 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 |
Incorrect |
4 ms |
8916 KB |
Output isn't correct |
2 |
Incorrect |
3 ms |
8792 KB |
Output isn't correct |
3 |
Incorrect |
3 ms |
8796 KB |
Output isn't correct |
4 |
Incorrect |
255 ms |
25012 KB |
Output isn't correct |
5 |
Incorrect |
139 ms |
21444 KB |
Output isn't correct |
6 |
Runtime error |
134 ms |
39092 KB |
Execution killed with signal 11 |
7 |
Incorrect |
217 ms |
23472 KB |
Output isn't correct |
8 |
Incorrect |
192 ms |
23348 KB |
Output isn't correct |
9 |
Incorrect |
250 ms |
25932 KB |
Output isn't correct |
10 |
Incorrect |
224 ms |
23988 KB |
Output isn't correct |