Submission #461347

#TimeUsernameProblemLanguageResultExecution timeMemory
461347Blobo2_Blobo2Vudu (COCI15_vudu)C++14
42 / 140
1022 ms42092 KiB
/* 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;} long long tree[4000005]; int arr[1000000],n,p; 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=0; vector<pair<int,int> >v; for(int i=0;i<n;i++){ c+=arr[i]; v.push_back({c,i}); } sort(all(v)); int mp[n+1]; for(int i=0;i<v.size();i++){ if(i==0) mp[v[i].second]=++idx; else if(v[i].first!=v[i-1].first) mp[v[i].second]=++idx; else mp[v[i].second]=idx; } long long cnt=0,ans=0; for(int i=0;i<n;i++){ cnt+=arr[i]; ans+=sum(1,mp[i]); update(mp[i],1); if(cnt>=0)ans++; } cout<<ans; return 0; }

Compilation message (stderr)

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;
      |                        ^~~~
vudu.cpp: In function 'int main()':
vudu.cpp:56:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...