UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#213954#2662. 折跃White_Wat204ms1260kbC++1.2kb2024-11-14 19:58:552024-11-14 23:04:14

answer

#include<bits/stdc++.h>

using namespace std;

const int N = 5010, mod = 1e9+7;

typedef long long ll;
int n,a,b,k;
ll d[N<<2],P[N<<2];
void update(int x,int s,int t,int p,int c){
	if(s==t){P[p]=c;return ;}
	int mid=(s+t)>>1;
	if(x<=mid) update(x,s,mid,p*2,c);
	else update(x,mid+1,t,p*2+1,c);
	P[p]=(P[p*2]+P[p*2+1])%mod;
}
ll get(int l,int r,int s,int t,int p){
	if(l>r) return 0;
	if(l<=s&&t<=r) return d[p];
	int mid=(s+t)>>1;ll re=0;
	if(l<=mid) re=get(l,r,s,mid,p*2);
	if(r>mid) re+=get(l,r,mid+1,t,p*2+1);
	return re%mod;
}

int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	cin>>n>>a>>b>>k;
	update(a,1,n,1,1);
	for(int i=1;i<=n*4;i++)
		d[i]=P[i];
	while(k--){
		for(int i=1;i<=n;i++){
			if(i==b) continue;
			update(i,1,n,1,-get(i,i,1,n,1));
			int dis=abs(i-b);
//			if(dis/2==0) continue;
//			cout<<i<<' '<<1<<' '<<b-dis/2-1<<' '<<b+dis/2+1<<' '<<n<<'\n';
			if(i<b)
				update(i,1,n,1,(get(1,b-dis/2-1,1,n,1)-get(i,i,1,n,1))%mod);
			else
				update(i,1,n,1,(get(b+dis/2+1,n,1,n,1)-get(i,i,1,n,1))%mod);
		}
		for(int i=1;i<=n*4;i++)
			d[i]=P[i];
//		for(int i=1;i<=n;i++)
//			cout<<get(i,i,1,n,1)<<' ';
//		cout<<'\n';
	}
	
	cout<<(get(1,n,1,n,1)+mod)%mod;
	
	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 4ms
memory: 1260kb

input:

98 18 22 94

output:

27076018

result:

ok single line: '27076018'

Test #2:

score: 10
Accepted
time: 0ms
memory: 1256kb

input:

95 94 73 92

output:

748455277

result:

ok single line: '748455277'

Test #3:

score: 0
Time Limit Exceeded

input:

4674 2740 4172 4983

output:


result:


Test #4:

score: 0
Time Limit Exceeded

input:

4981 813 4046 4994

output:


result:


Test #5:

score: 0
Time Limit Exceeded

input:

4595 3757 519 4810

output:


result:


Test #6:

score: 0
Time Limit Exceeded

input:

4902 277 2317 4821

output:


result:


Test #7:

score: 0
Time Limit Exceeded

input:

4516 1607 639 4990

output:


result:


Test #8:

score: 0
Time Limit Exceeded

input:

4823 1127 3840 4648

output:


result:


Test #9:

score: 0
Time Limit Exceeded

input:

4937 3261 2918 4817

output:


result:


Test #10:

score: 0
Time Limit Exceeded

input:

4744 135 2414 4828

output:


result: