QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#397306#1286. Ternary String CountingmaoyitingWA 2ms9192kbC++141.2kb2024-04-23 21:50:412024-04-23 21:50:41

Judging History

你现在查看的是最新测评结果

  • [2024-04-23 21:50:41]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9192kb
  • [2024-04-23 21:50:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=5e3+5,mod=1e9+7;
int t,n,m,Lj[N],Rj[N],Lk[N],Rk[N],sx[N],sy[N],f[N][N],ans;
deque<int>q[N];
void upd(int x,int y,int v){
	q[y].push_back(x);
	(sx[x]+=v)%=mod,(sy[y]+=v)%=mod,(f[x][y]+=v)%=mod;
}
void del(int x,int y){
	(sx[x]-=f[x][y])%=mod,(sy[y]-=f[x][y])%=mod,f[x][y]=0;
}
signed main(){
	scanf("%d",&t);
	while(t--){
		scanf("%d%d",&n,&m),ans=0;
		for(int i=0;i<=n;i++)
			sx[i]=sy[i]=Lj[i]=Lk[i]=0,Rj[i]=Rk[i]=i-1,
			fill(f[i],f[i]+1+n,0),q[i].clear();
		for(int i=1,l,r,x;i<=m;i++){
			scanf("%d%d%d",&l,&r,&x);
			if(x==1) Rj[r]=min(Rj[r],l-1);
			if(x==2) Lj[r]=max(Lj[r],l),Rk[r]=min(Rk[r],l-1);
			if(x==3) Lk[r]=max(Lk[r],l);
		}
		upd(0,0,3);
		for(int i=1;i<n;i++){
			for(int j=0;j<i;j++) upd(i,j,(sx[j]+sy[j])%mod);
			for(int k=0;k<i;k++){
				int lj=Lj[i+1],rj=Rj[i+1];
				if(!(Lk[i+1]<=k&&k<=Rk[i+1])) lj=n;
				while(q[k].size()&&q[k].front()<lj)
					del(q[k].front(),k),q[k].pop_front();
				while(q[k].size()&&q[k].back()>rj)
					del(q[k].back(),k),q[k].pop_back();
			}
		}
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++) (ans+=f[i][j])%=mod;
		printf("%d\n",ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 7224kb

input:

4
1 0
2 0
3 0
5 2
1 3 3
4 5 1

output:

3
9
27
18

result:

ok 4 tokens

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 9192kb

input:

741
5 3
1 5 3
3 4 2
1 4 3
4 3
2 4 2
1 4 1
2 3 3
10 3
9 10 2
3 6 3
1 9 1
3 4
2 3 2
1 3 2
2 3 3
1 3 3
10 4
6 6 1
9 10 2
4 8 3
4 10 3
6 3
1 4 3
2 4 2
2 2 2
4 3
1 4 1
1 1 2
2 3 1
5 3
4 5 2
4 5 1
1 4 3
9 3
2 3 2
1 9 2
2 4 2
4 3
1 3 3
2 3 2
1 2 3
8 4
5 8 1
4 8 1
3 5 3
1 3 3
9 3
4 5 1
1 5 3
3 8 2
8 3
5 7 2...

output:

90
0
0
0
24300
0
3
0
768
0
0
972
2916
0
6480
864
0
0
0
0
0
0
0
0
6
0
0
0
0
0
96
0
6
0
0
0
4374
0
0
0
108
0
0
0
2916
0
0
0
0
0
0
0
0
0
0
324
8748
0
0
0
0
0
0
4320
0
0
0
18
0
0
0
0
0
0
0
0
0
0
0
1992
0
0
450
0
162
1656
0
0
3
0
0
54
0
18
0
0
0
0
744
0
1620
324
0
0
36
36
0
0
60
6
54
0
0
0
0
0
0
0
0
243
...

result:

wrong answer 7th words differ - expected: '0', found: '3'