#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k,arr[1000010], ans, qs[1000010];
vector<int> vc;
map<int, int> fw;
void update(int idx, int val){
for(int i = idx; i<=1e6; i+=(i&-i)) fw[i]+=val;
}
int query(int idx){
int sum = 0;
for(int i = idx; i>0; i-=(i&-i)) sum+=fw[i];
return sum;
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n;
for(int i = 1; i<=n; ++i) cin >> arr[i];
for(int i = 1; i<=n; ++i) qs[i] = qs[i - 1] + arr[i];
cin >> k;
for(int i = 0; i<=n; ++i) vc.push_back(qs[i] - k*i);
sort(vc.begin(), vc.end());
vc.erase(unique(vc.begin(), vc.end()));
for(int i = 0; i<=n; ++i){
int idx = lower_bound(vc.begin(), vc.end(), qs[i] - k*i) - vc.begin();
ans+=query(idx+1);
update(idx+1, 1);
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2904 KB |
Output is correct |
2 |
Correct |
5 ms |
2908 KB |
Output is correct |
3 |
Correct |
5 ms |
2908 KB |
Output is correct |
4 |
Execution timed out |
1012 ms |
65536 KB |
Time limit exceeded |
5 |
Correct |
830 ms |
52728 KB |
Output is correct |
6 |
Runtime error |
131 ms |
46908 KB |
Execution killed with signal 11 |
7 |
Runtime error |
940 ms |
65536 KB |
Execution killed with signal 9 |
8 |
Execution timed out |
1024 ms |
65536 KB |
Time limit exceeded |
9 |
Runtime error |
1000 ms |
65536 KB |
Execution killed with signal 9 |
10 |
Execution timed out |
1051 ms |
65536 KB |
Time limit exceeded |