#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 1e6 + 69;
const ll inf = 1e9 + 7;
typedef pair<int,int> LL;
vector<ll> v;
ll n,a[N],b[N],P,bit[N];
ll Find(ll x){
return lower_bound(v.begin(),v.end(),x) - v.begin() + 1;
}
void compress(){
sort(v.begin(),v.end()); v.resize(unique(v.begin(),v.end()) - v.begin());
for (ll i = 1;i <= n;i++) b[i] = Find(b[i]);
}
void upd(ll p,ll val){
for (ll i = p;i < N;i += i & -i) bit[i] += val;
}
ll Get(ll p){
ll res = 0;
for (ll i = p;i > 0;i -= i & -i) res += bit[i];
return res;
}
ll Ask(ll l,ll r){
return Get(r) - Get(l - 1);
}
/// dit me bai de vcl
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define task "tst"
if (fopen(task".INP","r")){
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
cin>>n; v.push_back(0);
for (ll i = 1;i <= n;i++) cin>>a[i],b[i] = b[i - 1] + a[i];
cin>>P;
for (ll i = 1;i <= n;i++){
b[i] -= i*P; v.push_back(b[i]);
//cout<<b[i]<<" ";
}
//exit(0);
compress(); ll now = 0,ans = 0;
for (ll i = 1;i <= n;i++) upd(b[i],1);
for (ll i = 1;i <= n;i++){
ll id = Find(now);
ans += Ask(id,N - 1); upd(b[i],-1); now += a[i] - P;
//cout<<id; exit(0);
}
cout<<ans;
}
Compilation message
vudu.cpp: In function 'int main()':
vudu.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
41 | freopen(task".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
748 KB |
Output is correct |
2 |
Correct |
3 ms |
620 KB |
Output is correct |
3 |
Correct |
3 ms |
620 KB |
Output is correct |
4 |
Correct |
583 ms |
31056 KB |
Output is correct |
5 |
Correct |
276 ms |
17872 KB |
Output is correct |
6 |
Correct |
455 ms |
27600 KB |
Output is correct |
7 |
Correct |
441 ms |
28668 KB |
Output is correct |
8 |
Correct |
409 ms |
25000 KB |
Output is correct |
9 |
Correct |
511 ms |
32080 KB |
Output is correct |
10 |
Correct |
469 ms |
28032 KB |
Output is correct |