#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int n, k;
int a[N];
vector<int> srtd ;
map<long long, int > mp ;
long long bit[N] ;
void add(int x){
for(;x < N ;x += x&-x ){
bit[x] ++ ;
}
}
long long get(long long x){
if(x < 0 ) return 0;
long long ret =0 ;
for(;x;x-=x&-x){
ret+=bit[x] ;
}
return ret ;
}
int t =1 ;
long long com(long long x){
if(mp[x]){
return mp[x] ;
}
mp[x] = t++ ;
return t-1 ;
}
void init(){
srtd.push_back(0) ;
sort(srtd.begin() , srtd.end()) ;
for(int i = 0 ; i < (int) srtd.size() ;i++){
com(srtd[i]) ;
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("in.in", "r", stdin);
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
cin >> k;
long long sum = 0 ;
for (int i = 0; i < n; i++)
{
a[i] -= k;
sum+= a[i] ;
srtd.push_back(sum) ;
}
init() ;
long long ans = 0;
long long pre = 0;
add(com(0)) ;
for (int i = 0; i < n; i++)
{
pre += a[i];
ans+= get(com(pre)) ;
add(com(pre)) ;
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
896 KB |
Output is correct |
2 |
Correct |
8 ms |
768 KB |
Output is correct |
3 |
Correct |
9 ms |
768 KB |
Output is correct |
4 |
Runtime error |
603 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
5 |
Runtime error |
672 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
6 |
Runtime error |
549 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
7 |
Runtime error |
602 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
8 |
Runtime error |
577 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
9 |
Runtime error |
612 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
10 |
Runtime error |
591 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |