#include <bits/stdc++.h>
#define ll long long
#define mid (l+r)/2
using namespace std;
map < ll , int > mp;
const int N=1e6+55;
short tree[N*4];
ll sum[N];
ll a[N];
int n;
void update(int node , int l , int r , int ind)
{
if(l==r&&l==ind)
{
tree[node]++;
return ;
}
if(ind<=mid)
update(node*2,l,mid,ind);
else
update(node*2+1,mid+1,r,ind);
tree[node]=tree[node*2]+tree[node*2+1];
}
int query(int node , int l , int r , int x , int y)
{
if(x<=l&&r<=y)
return tree[node];
if(l>y||r<x)
return 0;
return query(node*2,l,mid,x,y)+query(node*2+1,mid+1,r,x,y);
}
int main()
{
ios::sync_with_stdio(false);
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
int p;
cin>>p;
for(int i=n-1;i>=0;i--)
{
sum[i]=a[i]-p;
if(i!=n-1)
sum[i]+=sum[i+1];
a[i]=sum[i];
}
sort(a,a+n);
int cnt=1;
for(int i=0;i<n;i++)
{
if(mp[a[i]]==0)
mp[a[i]]=cnt++;
}
ll ans=0;
for(int i=n-1;i>=0;i--)
{
if(sum[i]>=0)
ans++;
ans+=query(1,0,1e6,0,mp[sum[i]]);
update(1,0,1e6,mp[sum[i]]);
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1016 KB |
Output is correct |
2 |
Correct |
6 ms |
888 KB |
Output is correct |
3 |
Correct |
7 ms |
888 KB |
Output is correct |
4 |
Runtime error |
638 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
5 |
Incorrect |
977 ms |
45496 KB |
Output isn't correct |
6 |
Runtime error |
622 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
7 |
Runtime error |
640 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
8 |
Execution timed out |
1072 ms |
64184 KB |
Time limit exceeded |
9 |
Runtime error |
646 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
10 |
Runtime error |
635 ms |
66560 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |