QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#107695#1286. Ternary String CountingFaccirxWA 2ms3372kbC++203.2kb2023-05-22 15:32:102023-05-22 15:32:13

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-22 15:32:13]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3372kb
  • [2023-05-22 15:32:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define int long long

template<class T>bool chkmax(T &a,T b){return b>a?a=b,true:false;}
template<class T>bool chkmin(T &a,T b){return b<a?a=b,true:false;}

constexpr int inf=2e18;

template<const int mod>
struct modint{
	int x;
	modint(int x=0):x(norm(x%mod)){}
	int val()const{
		return x;
	}
	modint operator-()const{
		return modint(norm(mod-x));
	}
	int norm(int x)const{
		if(x<0) x+=mod;
		if(x>=mod) x-=mod;
		return x;
	}
	modint pow(int x)const{
		modint res=1;
		modint cur=*this;
		while(x){
			if(x&1){
				res*=cur;
			}
			cur*=cur;
			x/=2;
		}
		return res;
	}
	modint inv()const{
		assert(x!=0);
		return pow(mod-2);
	}
	modint &operator*=(const modint &rhs){
		x=(long long)(x)*rhs.x%mod;
		return *this;
	}
	modint &operator+=(const modint &rhs){
		x=norm(x+rhs.x);
		return *this;
	}
	modint &operator-=(const modint &rhs){
		x=norm(x-rhs.x);
		return *this;
	}
	modint &operator/=(const modint &rhs){
		return *this*=rhs.inv();
	}
	friend modint operator*(const modint &lhs,const modint &rhs){
		modint res=lhs;
		res*=rhs;
		return res;
	}
	friend modint operator+(const modint &lhs,const modint &rhs){
		modint res=lhs;
		res+=rhs;
		return res;
	}
	friend modint operator-(const modint &lhs,const modint &rhs){
		modint res=lhs;
		res-=rhs;
		return res;
	}
	friend modint operator/(const modint &lhs,const modint &rhs){
		modint res=lhs;
		res/=rhs;
		return res;
	}
	friend istream &operator>>(istream &is,modint &a){
		long long v;
		is>>v;
		a=modint(v);
		return is;
	}
	friend ostream &operator<<(ostream &os,const modint &a){
		return os<<a.val();
	}
	friend bool operator==(const modint &lhs,const modint &rhs){
		return lhs.val()==rhs.val();
	}
	friend bool operator!=(const modint &lhs,const modint &rhs){
		return lhs.val()!=rhs.val();
	}
};

using Mint=modint<(int)1e9+7>;

void solve(){
	int n,m;
	cin>>n>>m;
	vector<vector<pair<int,int>>>con(n);
	for(int i=0;i<m;i++){
		int l,r,x;
		cin>>l>>r>>x;
		l--,r--;
		con[r].emplace_back(l,x);
	}
	for(auto[l,x]:con[0]){
		if(x>1){
			cout<<"0\n";
			return;
		}
	}
	vector<vector<Mint>>dp(n+2,vector<Mint>(n+2));
	dp[-1+2][-2+2]=3;
	vector<pair<int,int>>alive;
	for(int i=-1;i<n;i++){
		for(int j=-2;j<i;j++){
			alive.emplace_back(i,j);
		}
	}
	for(int i=0;i<n-1;i++){
		int l_j=-inf,r_j=inf;
		int l_k=-inf,r_k=inf;
		for(auto[l,x]:con[i+1]){
			if(x==1){
				chkmin(r_j,l-1);
			}
			else if(x==2){
				chkmax(l_j,l);
				chkmin(r_k,l-1);
			}
			else{
				chkmax(l_k,l);
			}
		}
		vector<Mint>sum(i+2);
		for(auto[j,k]:alive){
			if(j<i){
				sum[j+2]+=dp[j+2][k+2];
				sum[k+2]+=dp[j+2][k+2];
			}
		}
		for(int j=-2;j<i+1;j++){
			dp[i+2][j+2]+=sum[j+2];
		}
		vector<pair<int,int>>nalive;
		for(auto[j,k]:alive){
			if(!(l_j<=j&&j<=r_j&&l_k<=k&&k<=r_k)){
				dp[j+2][k+2]=0;
			}
			else{
				nalive.emplace_back(j,k);
			}
		}
		swap(alive,nalive);
	}
	Mint ans=0;
	for(int j=-1;j<n-1;j++){
		for(int k=-2;k<j;k++){
			ans+=dp[j+2][k+2];
		}
	}
	cout<<ans<<"\n";
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T;
	cin>>T;
	while(T--){
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3372kb

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
3564
0
0
0
1902
0
0
306
2916
90
6426
2214
0
0
6
0
0
0
0
54
6
126
162
18
0
90
420
36
6
0
54
0
0
0
6
0
90
0
0
54
2916
42
0
0
0
0
486
0
0
12
54
324
8748
162
6
0
6
0
0
174
12
0
6
30
0
54
36
54
0
0
18
198
0
0
0
3216
0
72
270
18
36
2250
6
6
0
0
54
54
0
72
0
0
1134
0
72
0
270
540
0
0
18
270
0
0
76...

result:

wrong answer 5th words differ - expected: '24300', found: '3564'