QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#332811#1286. Ternary String CountingTokido_SayaWA 1ms5828kbC++143.7kb2024-02-19 16:06:082024-02-19 16:06:08

Judging History

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

  • [2024-02-19 16:06:08]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5828kb
  • [2024-02-19 16:06:08]
  • 提交

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 xl[N], xr[N], sumx[N], sumy[N], f[N][N];
void keep(int x, int l, int r)
{
	if(xl[x] > xr[x])
		return;
	chkmx(l, xl[x]);
	chkmn(r, xr[x]);
	if(l > r)
	{
		for(int y = xl[x]; y <= xr[x]; ++y)
		{
			Dec(sumx[x], f[x][y]);
			Dec(sumy[y], f[x][y]);
		}
	}
	else
	{
		for(int y = xl[x]; y < l; ++y)
		{
			Dec(sumx[x], f[x][y]);
			Dec(sumy[y], f[x][y]);
		}
		for(int y = xr[x]; y > r; --y)
		{
			Dec(sumx[x], f[x][y]);
			Dec(sumy[y], f[x][y]);
		}
	}
	xl[x] = l, xr[x] = r;
}
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 x = 0; x <= n; ++x)
		for(int y = 0; y <= n; ++y)
			f[x][y] = 0;
	for(int x = 0; x <= n; ++x) sumx[x] = 0;
	for(int y = 0; y <= n; ++y) sumy[y] = 0;
	f[0][0] = sumx[0] = sumy[0] = 3;
	for(int i = 1; i <= n; ++i)
	{
		for(int x = 0; x < jl[i]; ++x) keep(x, 1, 0);
		for(int x = jl[i]; x <= jr[i]; ++x) keep(x, kl[i], kr[i]);
		for(int x = jr[i] + 1; x < i; ++x) keep(x, 1, 0);
		if(i == n)
		{
			int ans = 0;
			for(int x = jl[i]; x <= jr[i]; ++x)
				Inc(ans, sumx[x]);
			return printf("%d\n", ans), void();
		}
		for(int x = jl[i]; x <= jr[i]; ++x)
			Inc(f[i][x], sumx[x]);
		for(int y = kl[i]; y <= kr[i]; ++y)
			Inc(f[i][y], sumy[y]);
		for(int j = 0; j < i; ++j)
		{
			Inc(sumx[i], f[i][j]);
			Inc(sumy[j], f[i][j]);
		}
	}
	return;
}
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
*/




Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5828kb

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

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:

96
0
0
0
29574
0
0
0
5184
18
30
5976
4617
0
23220
13053
0
0
0
0
0
0
0
0
12
0
0
0
0
0
600
0
21
0
0
0
0
0
0
0
183
0
0
0
4638
90
108
0
0
0
0
0
0
0
0
2430
13872
0
15
0
0
0
0
28956
0
0
0
45
0
0
108
0
0
6
0
0
0
0
0
12006
0
2952
13770
1872
954
8496
0
0
0
0
648
378
0
108
0
24
0
0
7488
0
7614
1134
0
0
2799
4...

result:

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