Submission #318052

# Submission time Handle Problem Language Result Execution time Memory
318052 2020-10-31T10:42:51 Z Dymo Vudu (COCI15_vudu) C++14
140 / 140
960 ms 40388 KB
#include<bits/stdc++.h>

using namespace std;


#define pb    push_back
#define eb   emplace_back
#define ll  long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define endl "\n"
const ll maxn=1e6+50;
const ll mod =998244353 ;
const ll base=3e18;
vector<ll> vt;

ll st[1][4*maxn];
ll a[maxn];

void update(ll id,ll left,ll right,ll x,ll diff,ll t )
{
    if (x>right||x<left) return ;
    if (right==left )
    {
        st[t][id]+=diff;

        return ;
    }
    ll mid=(left+right)/2;
    update(id*2,left,mid, x, diff,t);
    update(id*2+1, mid+1, right, x, diff,t);
    st[t][id]=(st[t][id*2]+st[t][id*2+1]);
}
ll get(ll id,ll left,ll right,ll x,ll y,ll t)
{
    if (x>right||y<left||x> y) return 0;
    if (x<=left&&y>=right)
    {
        return st[t][id];
    }
    ll mid=(left+right)/2;
    return  get(id*2,left,mid, x, y, t )+get(id*2+1, mid+1, right, x, y, t);

}
ll f[maxn];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    vector<ll> vt;
    vt.pb(-1e17);
    vt.pb(0);
   ll n;
   ll p;
   cin>>n;
   for (ll i=1;i<=n;i++) cin>>a[i], f[i]=f[i-1]+a[i];

    cin>>p ;
   for (ll i=1;i<=n;i++)
   {
        vt.pb(f[i]-i*p);

   }
   sort(vt.begin(),vt.end());
   vt.resize(unique(vt.begin(),vt.end())-vt.begin());
   auto h=lower_bound(vt.begin(),vt.end(),0)-vt.begin();
  // for (auto to:)
   update(1,1,vt.size(),h,1,0);
   ll ans=0;
   for (ll i=1;i<=n;i++)
   {
        auto h=lower_bound(vt.begin(),vt.end(),f[i]-i*p)-vt.begin();
      ans=ans+get(1,1,vt.size(),1,h,0);
    //  cout <<h<<endl;
    //  if (a[i]>=p) ans++;
      update(1,1,vt.size(),h,1,0);
   }
   cout <<ans;





}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 748 KB Output is correct
2 Correct 4 ms 748 KB Output is correct
3 Correct 4 ms 748 KB Output is correct
4 Correct 960 ms 39620 KB Output is correct
5 Correct 477 ms 29812 KB Output is correct
6 Correct 787 ms 37060 KB Output is correct
7 Correct 787 ms 37956 KB Output is correct
8 Correct 702 ms 35140 KB Output is correct
9 Correct 905 ms 40388 KB Output is correct
10 Correct 787 ms 37432 KB Output is correct