/*
Editor: Abdelrahman Hossam
Nickname: Blobo2_Blobo2
IOI next year isA :)
*/
/*#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")*/
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define endl "\n"
#define all(v) v.begin(),v.end()
#define gen(arr,n,nxt) generate(arr,arr+n,nxt)
#define Blobo2_el_7akim_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty ios_base::sync_with_stdio(false);cin.tie(0);
const int mo=1e9+7,INF=1e18;
int nxt(){int x;cin>>x;return x;}
int tree[4000001],n,p,arr[1000001];
void update(int pos,int val,int idx=1,int ss=0,int se=n-1){
if(ss==se){
tree[idx]+=val;
return;
}
int mid=(ss+se)>>1;
if(pos<=mid)update(pos,val,idx<<1,ss,mid);
else update(pos,val,idx<<1|1,mid+1,se);
tree[idx] = tree[idx<<1]+tree[idx<<1|1];
}
int sum(int l,int r,int idx=1,int ss=0,int se=n-1){
if(l>se||r<ss)
return 0;
if(l<=ss&&se<=r)
return tree[idx];
int mid=(ss+se)>>1;
return sum(l,r,idx<<1,ss,mid)+
sum(l,r,idx<<1|1,mid+1,se);
}
signed main(){
Blobo2_el_7akim_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty
n=nxt();
gen(arr,n,nxt);
p=nxt();
for(int i=0;i<n;i++)arr[i]-=p;
int c=0,idx=1;
map<int,int>mp;
set<int>st;
for(int i=0;i<n;i++){
c+=arr[i];
st.insert(c);
}
for(auto x:st)
mp[x]=idx++;
int cnt=0,ans=0;
for(int i=0;i<n;i++){
cnt+=arr[i];
ans+=sum(1,mp[cnt]);
update(mp[cnt],1);
if(cnt>=0)ans++;
}
cout<<ans;
return 0;
}
Compilation message
vudu.cpp:19:24: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
19 | const int mo=1e9+7,INF=1e18;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1100 KB |
Output is correct |
2 |
Correct |
6 ms |
928 KB |
Output is correct |
3 |
Correct |
6 ms |
900 KB |
Output is correct |
4 |
Runtime error |
962 ms |
65540 KB |
Execution killed with signal 9 |
5 |
Execution timed out |
1072 ms |
65536 KB |
Time limit exceeded |
6 |
Runtime error |
904 ms |
65540 KB |
Execution killed with signal 9 |
7 |
Runtime error |
943 ms |
65540 KB |
Execution killed with signal 9 |
8 |
Runtime error |
814 ms |
65540 KB |
Execution killed with signal 9 |
9 |
Execution timed out |
1008 ms |
65540 KB |
Time limit exceeded |
10 |
Runtime error |
906 ms |
65540 KB |
Execution killed with signal 9 |