Submission #4570489


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dat[1000000];
ll u;
ll inf=1000000000000000001;
ll mod=1000000007;
void add(ll n,ll x){
  ll i=n+u-1;
  dat[i]=x;
  while(i>0){
    i=(i-1)/2;
    dat[i]=min(dat[2*i+1],dat[2*i+2]);
  }
}
ll que(ll a,ll b,ll k,ll l,ll r){
  if(a>=r||b<=l)return inf;
  if(a<=l&&b>=r)return dat[k];
  ll m1=que(a,b,2*k+1,l,(l+r)/2);
  ll m2=que(a,b,2*k+2,(l+r)/2,r);
  return min(m1,m2);
}
int main(){
  fill(dat,dat+1000000,inf);
  ll n,a,b;cin>>n>>a>>b;
  vector<ll> s(n);
  for(ll i=0;i<n;i++)cin>>s[i];
  for(ll i=0;;i++){
    ll e=pow(2,i);
    if(e>=n-1){
      u=e;
      break;
    }
  }
  for(ll i=0;i<n-1;i++){
    add(i,s[i+1]-s[i]);
  }
  ll dp1[n],dp2[n];
  fill(dp1,dp1+n,0);
  fill(dp2,dp2+n,0);
  dp1[0]=1;
  dp2[0]=1;
  for(ll i=1;i<n;i++){
    ll t=upper_bound(s.begin(),s.end(),s[i]-a)-s.begin();
    if(t==0){
      if(i==1){
        dp1[i]=1;
      }
      else{
        ll r=que(0,i-1,0,0,u);
        if(r>=b)dp1[i]=1;
      }
    }
    else{
      if(t==i){
        dp1[i]+=dp1[t-1]+dp2[t-1];
        dp1[i]%=mod;
      }
      else if(t==i-1){
        dp1[i]+=dp1[t-1];
        dp1[i]%=mod;
        if(s[i-1]-s[i-2]>=b)dp1[i]+=dp2[t-1];
        dp1[i]%=mod;
      }
      else{
        ll f=que(t-1,i-1,0,0,u);
        ll g=que(t,i-1,0,0,u);
        if(f>=b)dp1[i]+=dp2[t-1];
        dp1[i]%=mod;
        if(g>=b)dp1[i]+=dp1[t-1];
        dp1[i]%=mod;
      }
    }
    ll tt=upper_bound(s.begin(),s.end(),s[i]-b)-s.begin();
    //if(i==3)cout<<tt<<endl;
    if(tt==0){
      if(i==1){
        dp2[i]=1;
      }
      else{
        ll r=que(0,i-1,0,0,u);
        if(r>=b)dp2[i]=1;
      }
    }
    else{
      if(tt==i){
        dp2[i]+=dp1[tt-1]+dp2[tt-1];
        dp2[i]%=mod;
      }
      else if(tt==i-1){
        dp2[i]+=dp2[tt-1];
        dp2[i]%=mod;
        if(s[i-1]-s[i-2]>=a)dp2[i]+=dp1[tt-1];
        dp2[i]%=mod;
      }
      else{
        ll f=que(tt-1,i-1,0,0,u);
        ll g=que(tt,i-1,0,0,u);
        if(f>=a)dp2[i]+=dp1[tt-1];
        dp2[i]%=mod;
        if(g>=a)dp2[i]+=dp2[tt-1];
        dp2[i]%=mod;
      }
    }
  }
 
  ll ans=dp1[n-1]+dp2[n-1];
  cout<<ans%mod<<endl;
}

Submission Info

Submission Time
Task C - Division into Two
User ttttan
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2282 Byte
Status WA
Exec Time 129 ms
Memory 10368 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1100
Status
AC × 4
AC × 46
WA × 22
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt, s4.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt, 53.txt, 54.txt, 55.txt, 56.txt, 57.txt, 58.txt, 59.txt, 60.txt, 61.txt, 62.txt, 63.txt, 64.txt, s1.txt, s2.txt, s3.txt, s4.txt
Case Name Status Exec Time Memory
01.txt AC 85 ms 10368 KB
02.txt AC 80 ms 10368 KB
03.txt AC 86 ms 10368 KB
04.txt AC 84 ms 10368 KB
05.txt AC 80 ms 10368 KB
06.txt AC 84 ms 10368 KB
07.txt AC 86 ms 10368 KB
08.txt AC 82 ms 10368 KB
09.txt AC 86 ms 10368 KB
10.txt AC 86 ms 10368 KB
11.txt AC 86 ms 10368 KB
12.txt AC 84 ms 10368 KB
13.txt AC 84 ms 10368 KB
14.txt AC 90 ms 10368 KB
15.txt AC 83 ms 10368 KB
16.txt AC 56 ms 10368 KB
17.txt WA 66 ms 10368 KB
18.txt AC 76 ms 10368 KB
19.txt WA 100 ms 10368 KB
20.txt WA 74 ms 10368 KB
21.txt WA 62 ms 10368 KB
22.txt WA 97 ms 10368 KB
23.txt WA 85 ms 10368 KB
24.txt WA 81 ms 10368 KB
25.txt WA 76 ms 10368 KB
26.txt WA 72 ms 10368 KB
27.txt WA 75 ms 10368 KB
28.txt WA 86 ms 10368 KB
29.txt WA 86 ms 10368 KB
30.txt WA 90 ms 10368 KB
31.txt WA 94 ms 10368 KB
32.txt WA 101 ms 10368 KB
33.txt WA 111 ms 10368 KB
34.txt WA 97 ms 10368 KB
35.txt WA 118 ms 10368 KB
36.txt AC 47 ms 10368 KB
37.txt AC 86 ms 10368 KB
38.txt WA 90 ms 10368 KB
39.txt AC 129 ms 10368 KB
40.txt AC 49 ms 10368 KB
41.txt AC 84 ms 10368 KB
42.txt AC 64 ms 10368 KB
43.txt AC 85 ms 10368 KB
44.txt AC 85 ms 10368 KB
45.txt AC 85 ms 10368 KB
46.txt AC 85 ms 10368 KB
47.txt AC 85 ms 10368 KB
48.txt AC 85 ms 10368 KB
49.txt AC 4 ms 8064 KB
50.txt AC 4 ms 8064 KB
51.txt AC 4 ms 8064 KB
52.txt AC 4 ms 8064 KB
53.txt AC 4 ms 8064 KB
54.txt WA 4 ms 8064 KB
55.txt AC 4 ms 8064 KB
56.txt AC 4 ms 8064 KB
57.txt AC 3 ms 8064 KB
58.txt AC 4 ms 8064 KB
59.txt AC 3 ms 8064 KB
60.txt WA 4 ms 8064 KB
61.txt WA 4 ms 8064 KB
62.txt AC 4 ms 8064 KB
63.txt AC 4 ms 8064 KB
64.txt AC 3 ms 8064 KB
s1.txt AC 4 ms 8064 KB
s2.txt AC 4 ms 8064 KB
s3.txt AC 4 ms 8064 KB
s4.txt AC 4 ms 8064 KB