답안 #318047

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
318047 2020-10-31T10:39:29 Z Dymo Vudu (COCI15_vudu) C++14
0 / 140
670 ms 38340 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);

}
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];

    cin>>p ;
   for (int i=1;i<=n;i++)
   {
        vt.pb(a[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(),a[i]-i*p)-vt.begin();
      ans=ans+get(1,1,vt.size(),1,h,0);
      if (a[i]>=p) ans++;
      update(1,1,vt.size(),h,1,0);
   }
   cout <<ans;





}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 748 KB Output isn't correct
2 Incorrect 4 ms 652 KB Output isn't correct
3 Incorrect 3 ms 620 KB Output isn't correct
4 Incorrect 634 ms 37704 KB Output isn't correct
5 Incorrect 360 ms 30408 KB Output isn't correct
6 Incorrect 569 ms 35780 KB Output isn't correct
7 Incorrect 589 ms 36552 KB Output isn't correct
8 Incorrect 513 ms 34376 KB Output isn't correct
9 Incorrect 670 ms 38340 KB Output isn't correct
10 Incorrect 583 ms 36036 KB Output isn't correct