Submission #318048

# Submission time Handle Problem Language Result Execution time Memory
318048 2020-10-31T10:41:01 Z Dymo Vudu (COCI15_vudu) C++14
42 / 140
947 ms 32580 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=5e5+50;
const ll mod =998244353 ;
const ll base=3e18;
vector<ll> vt;

ll st[2][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(-1e15);
    vt.pb(0);
   ll n;
   ll p;
   cin>>n;
   for (int i=1;i<=n;i++) cin>>a[i], f[i]=f[i-1]+a[i];

    cin>>p ;
   for (int 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 (int 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 876 KB Output is correct
2 Correct 4 ms 748 KB Output is correct
3 Correct 4 ms 620 KB Output is correct
4 Incorrect 947 ms 32432 KB Output isn't correct
5 Incorrect 488 ms 29148 KB Output isn't correct
6 Incorrect 792 ms 31544 KB Output isn't correct
7 Incorrect 790 ms 31940 KB Output isn't correct
8 Incorrect 703 ms 30916 KB Output isn't correct
9 Incorrect 904 ms 32580 KB Output isn't correct
10 Incorrect 800 ms 31732 KB Output isn't correct