QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#332371#1286. Ternary String CountingTokido_SayaTL 45ms199508kbC++143.2kb2024-02-19 14:57:422024-02-19 14:57:42

Judging History

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

  • [2024-02-19 14:57:42]
  • 评测
  • 测评结果:TL
  • 用时:45ms
  • 内存:199508kb
  • [2024-02-19 14:57:42]
  • 提交

answer

// Sea, You & Me
#include<bits/stdc++.h>
#define LL long long
#define DB double
#define MOD 1000000007
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
#define lowbit(x) ((-x) & x)
#define MP make_pair
#define MT make_tuple
#define VI vector<int>
#define VL vector<LL>
#define VII VI::iterator
#define VLI VL::iterator
#define all(x) x.begin(), x.end()
#define EB emplace_back
#define PII pair<int, int>
#define SI set<int>
#define SII SI::iterator
#define fi first
#define se second
using namespace std;
template<typename T> void chkmn(T &a, const T b) { (a > b) && (a = b); }
template<typename T> void chkmx(T &a, const T b) { (a < b) && (a = b); }
void Inc(int &a, const int &b) { ((a += b) >= MOD) && (a -= MOD); }
void Dec(int &a, const int &b) { ((a -= b) < 0) && (a += MOD); }
void Mul(int &a, const int &b) { a = 1LL * a * b % MOD; }
void Sqr(int &a) { a = 1LL * a * a % MOD; }
int inc(const int &a, const int &b) { return (a + b >= MOD) ? a + b - MOD : a + b; }
int dec(const int &a, const int &b) { return (a - b < 0) ? a - b + MOD : a - b; }
int mul(const int &a, const int &b) { return 1LL * a * b % MOD; }
int sqr(const int &a) { return 1LL * a * a % MOD; }
int qwqmi(int x, int k = MOD - 2)
{
	int res = 1;
	while(k)
	{
		if(k & 1) Mul(res, x);
		k >>= 1, Sqr(x);
	}
	return res;
}
template<typename T> void read(T &x)
{
	x = 0;
	int f = 1;
	char ch = getchar();
	while(!isdigit(ch))
	{
		if(ch == '-')
			f = -1;
		ch = getchar();
	}
	while(isdigit(ch))
	{
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	x = x * f;
}
const int N = 5e3 + 5;
int T, n, m;
int jl[N], jr[N], kl[N], kr[N];
int f[2][N][N];
void work()
{
	read(n), read(m);
	for(int i = 1; i <= n; ++i)
	{
		jl[i] = kl[i] = 0;
		jr[i] = kr[i] = i - 1;
	}
	for(int i = 1; i <= m; ++i)
	{
		int l, r, x;
		read(l), read(r), read(x);
		if(x == 1) chkmn(jr[r], l - 1), chkmn(kr[r], l - 1);
		if(x == 2) chkmx(jl[r], l), chkmn(kr[r], l - 1);
		if(x == 3) chkmx(jl[r], l), chkmx(kl[r], l);
	}
	for(int i = 2; i <= n; ++i)
	{
		chkmx(jl[i], jl[i - 1]);
		chkmx(kl[i], kl[i - 1]);
	}
	for(int i = n; i >= 2; --i)
	{
		chkmn(jr[i - 1], jr[i]);
		chkmn(kr[i - 1], kr[i]);
	}
	for(int i = 1; i <= n; ++i)
		if(jl[i] > jr[i] || kl[i] > kr[i])
			return puts("0"), void();
//	for(int i = 1; i <= n; ++i)
//		cerr << jl[i] << ' ' << jr[i] << ' ' << kl[i] << ' ' << kr[i] << '\n';
	int now = 0, lst = 1;
	for(int j = 0; j < n; ++j)
		for(int k = 0; k <= j; ++k)
			f[now][j][k] = 0;
	f[now][0][0] = 3;
	for(int i = 1; i < n; ++i)
	{
		swap(now, lst);
//		cerr << jl[i] << ' ' << jr[i] << '\n';
//		cerr << kl[i] << ' ' << kr[i] << '\n';
		memset(f[now], 0, sizeof(f[now]));
		for(int j = jl[i]; j <= jr[i]; ++j)
			for(int k = kl[i]; k <= kr[i] && (k < j || k == 0); ++k)
			{
				Inc(f[now][i][j], f[lst][j][k]);
				Inc(f[now][i][k], f[lst][j][k]);
				Inc(f[now][j][k], f[lst][j][k]);
			}
	}
	int ans = 0;
	for(int j = jl[n]; j <= jr[n]; ++j) 
		for(int k = kl[n]; k <= kr[n]; ++k)
			Inc(ans, f[now][j][k]);
	printf("%d\n", ans);
}
int main()
{
	read(T);
	while(T--)
		work();
	return 0;
}

/* sample
4
1 0
2 0
3 0
5 2
1 3 3
4 5 1
ans : 
3
9
27
18
*/




詳細信息

Test #1:

score: 100
Accepted
time: 45ms
memory: 199508kb

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
Time Limit Exceeded

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:


result: