#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int n, k;
int a[N];
vector<long long> srtd ;
unordered_map<long long, int > mp ;
int bit[N] ;
int tree[4*N] ;
int read_int()
{
char r;
bool start = false, neg = false;
int ret = 0;
while (true)
{
r = getchar();
if ((r - '0' < 0 || r - '0' > 9) && r != '-' && !start)
{
continue;
}
if ((r - '0' < 0 || r - '0' > 9) && r != '-' && start)
{
break;
}
if (start)
ret *= 10;
start = true;
if (r == '-')
neg = true;
else
ret += r - '0';
}
if (!neg)
return ret;
else
return -ret;
}
void update(int node , int L , int R , int ix , int v){
if(L == R){
tree[node]+=v ;
return ;
}
int mid = (L + R) >> 1 ;
if(ix <=mid){
update(node*2+1 , L , mid , ix , v) ;
}
else{
update(node*2+2 , mid+1 , R, ix , v) ;
}
tree[node] = tree[node*2+1] + tree[node*2+2] ;
}
int query(int node , int L , int R , int l , int r){
if(l > R || r < L ) return 0 ;
if(L>=l && R<=r)
return tree[node] ;
int mid = (L+R) >> 1;
int s1 = query(node*2+1 , L , mid , l , r) ;
int s2 = query(node*2+2 , mid+1 , R , l ,r) ;
return s1 + s2 ;
}
int t =1 ;
int com(long long x){
int ret = mp[x] ;
if(ret)return ret ;
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);
n = read_int() ;
for (int i = 0; i < n; i++)
{
a[i] = read_int() ;
}
k = read_int();
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;
update(0 ,1 , N , com(0) , 1) ;
for (int i = 0; i < n; i++)
{
pre += a[i];
int aux = com(pre) ;
ans+= query(0 , 1 , N , aux , 1) ;
update(0 ,1 ,N , aux , 1) ;
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
896 KB |
Output isn't correct |
2 |
Incorrect |
7 ms |
768 KB |
Output isn't correct |
3 |
Incorrect |
7 ms |
768 KB |
Output isn't correct |
4 |
Execution timed out |
1094 ms |
64412 KB |
Time limit exceeded |
5 |
Incorrect |
625 ms |
35920 KB |
Output isn't correct |
6 |
Execution timed out |
1020 ms |
51280 KB |
Time limit exceeded |
7 |
Execution timed out |
1086 ms |
53216 KB |
Time limit exceeded |
8 |
Incorrect |
935 ms |
47056 KB |
Output isn't correct |
9 |
Execution timed out |
1084 ms |
65540 KB |
Time limit exceeded |
10 |
Execution timed out |
1032 ms |
51920 KB |
Time limit exceeded |