P1400 Tower, P1400
Description
There are N (2 <= N <= 600000) blocks of bricks, to build a n-layer Tower, requirement: If brick A is on Brick B, then A cannot be longer than B's Length + D. There are several ways to output the value of mod 1000000009.
Input/Output Format
Input Format:
The first line: N, D the second line: N number, indicating the length of each brick.
Output Format:
Number of solutions, output mod 1000000009
Input and Output sample
Input example #1:
4 11 2 3 100
Output sample #1:
4
Multiplication principle
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #define lli long long int 6 #include<algorithm> 7 using namespace std; 8 const int MAXN=600001; 9 const int mod=1000000009;10 int read(int & n)11 {12 char c='.';int x=0,flag=0;13 while(c<'0'||c>'9')14 {c=getchar(); if(c=='-')flag=1; }15 while(c>='0'&&c<='9')16 {x=x*10+(c-48);c=getchar();}17 if(flag==1)n=-x;else n=x;18 }19 int n,d;20 int a[MAXN];21 lli ans=1;22 int top=1;23 int maxn=1;24 int main()25 {26 read(n);read(d);27 for(int i=1;i<=n;i++)28 read(a[i]);29 sort(a+1,a+n+1);30 for(int i=2;i<=n;i++)31 {32 while(a[i]>a[top]+d)33 {34 top++;35 }36 ans=ans*(i-top+1);37 ans=ans%mod;38 }39 //printf("%d",ans);40 cout<<ans;41 return 0;42 }