#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN 1000005
ll a[MAXN];
int bit[MAXN];
void update(int idx,int val)
{
while(idx < MAXN)
{
bit[idx]+=val;
idx+=idx&(-idx);
}
}
int get(int idx)
{
int s=0;
while(idx > 0)
{
s+=bit[idx];
idx-=idx&(-idx);
}
return s;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
}
vector <ll> v;
ll p;
cin >> p;
for(int i = 1; i <= n; i++)a[i]-=p;
for(int i = 1; i <= n; i++)
{
a[i]+=a[i-1];
v.push_back(a[i]);
}
v.push_back(0LL);
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
ll ans = 0LL;
for(int i = 0; i <= n; i++)
{
a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin()+1;
if(i>0)update(a[i-1],1);
ans += get(a[i]);
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
760 KB |
Output is correct |
2 |
Correct |
4 ms |
760 KB |
Output is correct |
3 |
Correct |
4 ms |
760 KB |
Output is correct |
4 |
Correct |
423 ms |
29016 KB |
Output is correct |
5 |
Correct |
227 ms |
29016 KB |
Output is correct |
6 |
Correct |
356 ms |
40752 KB |
Output is correct |
7 |
Correct |
397 ms |
49948 KB |
Output is correct |
8 |
Correct |
323 ms |
55116 KB |
Output is correct |
9 |
Correct |
426 ms |
65536 KB |
Output is correct |
10 |
Correct |
363 ms |
65536 KB |
Output is correct |