#include <bits/stdc++.h>
using namespace std;
const int nx=1e6+5;
long long n, p, qs[nx], res;
vector<long long> v;
struct fenwick
{
int d[nx];
void add(int idx)
{
for (int i=idx; i<=n; i+=(i&-i)) d[i]++;
}
int query(int idx)
{
int res=0;
for (int i=idx; i>0; i-=(i&-i)) res+=d[i];
return res;
}
} f;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++) cin>>qs[i], qs[i]+=qs[i-1];
cin>>p;
for (int i=0; i<n; i++) v.push_back(qs[i]-i*p);
sort(v.begin(), v.end());
for (int i=1; i<=n; i++)
{
f.add(lower_bound(v.begin(), v.end(), qs[i-1]-(i-1)*p)-v.begin()+1);
res+=f.query(lower_bound(v.begin(), v.end(), qs[i]-(i)*p)-v.begin()+1);
}
cout<<res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
4 |
Incorrect |
324 ms |
27116 KB |
Output isn't correct |
5 |
Incorrect |
165 ms |
16176 KB |
Output isn't correct |
6 |
Incorrect |
267 ms |
25064 KB |
Output isn't correct |
7 |
Incorrect |
274 ms |
26332 KB |
Output isn't correct |
8 |
Incorrect |
234 ms |
17588 KB |
Output isn't correct |
9 |
Incorrect |
310 ms |
28088 KB |
Output isn't correct |
10 |
Incorrect |
267 ms |
24552 KB |
Output isn't correct |