QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#97678#1286. Ternary String CountingDaiRuiChen007WA 4ms7040kbC++141.6kb2023-04-17 21:26:562023-04-17 21:26:59

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-17 21:26:59]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:7040kb
  • [2023-04-17 21:26:56]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN=5001,MOD=1e9+7;
int lj[MAXN],rj[MAXN],lk[MAXN],rk[MAXN];
int sumj[MAXN],sumk[MAXN],z[MAXN],dp[MAXN][MAXN];
deque <int> Q[MAXN];
inline void add(int j,int k,int z) {
	dp[j][k]=(dp[j][k]+z)%MOD;
	sumj[j]=(sumj[j]+z)%MOD;
	sumk[k]=(sumk[k]+z)%MOD;
}
inline void del(int j,int k) { add(j,k,MOD-dp[j][k]); }
inline void solve() {
	int n,m;
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;++i) lj[i]=0,rj[i]=i-1,lk[i]=0,rk[i]=i-1;
	while(m--) {
		int l,r,c;
		scanf("%lld%lld%lld",&l,&r,&c);
		if(c==1) rj[r]=min(rj[r],l-1),rk[r]=min(rk[r],l-1);
		if(c==2) lj[r]=max(lj[r],l),rk[r]=min(rk[r],l-1);
		if(c==3) lj[r]=max(lj[r],l),lk[r]=max(lk[r],l);
	}
	add(0,0,1),Q[0].push_back(0);
	for(int i=1;i<=n;++i) {
		for(int c=0;c<i;++c) z[c]=0;
		for(int j=lj[i];j<=rj[i];++j) z[j]=(z[j]+sumj[j])%MOD;
		for(int k=lk[i];k<=rk[i];++k) z[k]=(z[k]+sumk[k])%MOD;
		for(int c=0;c<i;++c) if(z[c]) add(i-1,c,z[c]),Q[i-1].push_back(c);
		for(int j=0;j<i;++j) {
			if(lk[i]<=j&&j<=rk[i]) {
				while(!Q[j].empty()&&Q[j].front()<lk[i]) del(j,Q[j].front()),Q[j].pop_front();
				while(!Q[j].empty()&&Q[j].back()>rk[i])  del(j,Q[j].back()),Q[j].pop_back();
			} else {
				for(int x:Q[j]) del(j,x);
				Q[j].clear();
			}
		}
	}
	int ans=0;
	for(int j=0;j<=n;++j) for(int k=0;k<=n;++k) ans=(ans+dp[j][k])%MOD;
	printf("%lld\n",ans);
	for(int j=0;j<=n;++j) for(int k=0;k<=n;++k) dp[j][k]=0;
	for(int i=0;i<=n;++i) sumj[i]=sumk[i]=0,Q[i].clear();
}
signed main() {
	int T;
	scanf("%lld",&T);
	while(T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 7040kb

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: 1ms
memory: 7020kb

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:

18
0
0
0
12150
0
2
36
3
0
0
18
729
27
81
9
0
0
36
0
0
0
0
0
3
0
3
0
0
0
6
27
0
0
9
9
486
0
9
0
27
0
0
0
2916
0
0
0
0
0
0
3
0
0
0
162
8748
0
0
0
0
0
0
4320
0
0
0
3
3
0
0
0
0
0
3
0
0
0
3
6
0
0
450
0
162
9
3
0
0
0
27
0
3
0
0
0
0
0
3
0
54
0
0
0
9
3
0
0
6
3
9
0
0
0
0
243
0
0
0
243
810
0
9
0
0
0
0
0
0
0
0...

result:

wrong answer 1st words differ - expected: '90', found: '18'