#include <bits/stdc++.h>
using namespace std;
#define MAXN 1000005
typedef long long ll;
ll a[MAXN];
int tree[4*MAXN];
vector <ll> v;
void update(int node,int left,int right,int idx,int val)
{
if(left==right)
{
tree[node]+=val;
return ;
}
int mid=left+right>>1;
if(idx <= mid)update(node*2,left,mid,idx,val);
if(idx > mid)update(node*2+1,mid+1,right,idx,val);
tree[node]=tree[node*2]+tree[node*2+1];
}
int query(int node,int left,int right,int l,int r)
{
if(left >= l && right <= r)return tree[node];
int mid = left+right>>1;
int ans=0;
if(l <= mid)ans+=query(node*2,left,mid,l,r);
if(r > mid)ans+=query(node*2+1,mid+1,right,l,r);
return ans;
}
set <ll> st;
int main()
{
ios_base::sync_with_stdio(false);
int n;
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
}
ll p;
cin >> p;
for(int i = 1; i <= n; i++)
{
a[i]-=p;
}
//v.push_back(0LL);
st.insert(0LL);
for(int i = 1; i <= n; i++)
{
a[i]+=a[i-1];
st.insert(a[i]);//v.push_back(a[i]);
}
for(auto x:st)v.push_back(x);
//sort(v.begin(),v.end());
ll ans=0;
for(int i = 0; i <= n; i++)
{
a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin();
if(i!=0)update(1,0,v.size()-1,a[i-1],1);
ans += 1LL*query(1,0,v.size()-1,0,a[i]);
}
cout << ans;
return 0;
}
Compilation message
vudu.cpp: In function 'void update(int, int, int, int, int)':
vudu.cpp:17:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=left+right>>1;
~~~~^~~~~~
vudu.cpp: In function 'int query(int, int, int, int, int)':
vudu.cpp:25:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = left+right>>1;
~~~~^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1144 KB |
Output is correct |
2 |
Correct |
7 ms |
1144 KB |
Output is correct |
3 |
Correct |
6 ms |
1184 KB |
Output is correct |
4 |
Runtime error |
882 ms |
65536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Correct |
596 ms |
65536 KB |
Output is correct |
6 |
Runtime error |
1022 ms |
65536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Runtime error |
728 ms |
65536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
8 |
Runtime error |
889 ms |
65536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
9 |
Execution timed out |
1050 ms |
65536 KB |
Time limit exceeded |
10 |
Execution timed out |
1065 ms |
65536 KB |
Time limit exceeded |