QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#332375 | #1286. Ternary String Counting | Tokido_Saya | TL | 701ms | 46904kb | C++14 | 3.2kb | 2024-02-19 14:58:41 | 2024-02-19 14:58:42 |
Judging History
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';
for(int j = 0; j < n; ++j)
for(int k = 0; k <= j; ++k)
f[now][j][k] = 0;
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
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5880kb
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: 0
Accepted
time: 1ms
memory: 7864kb
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 0 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 0 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 0 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 810...
result:
ok 741 tokens
Test #3:
score: 0
Accepted
time: 1ms
memory: 5936kb
input:
332 17 5 4 9 1 4 6 1 7 17 1 5 5 1 5 6 3 13 5 10 12 3 8 13 2 1 10 3 2 9 1 9 10 1 19 5 11 13 1 9 17 2 1 7 1 4 4 2 3 9 1 15 4 8 11 2 9 14 3 10 12 2 4 5 2 12 4 3 9 2 7 8 1 1 7 3 6 7 3 16 5 4 14 3 1 5 1 2 10 1 2 12 3 6 9 3 20 4 10 17 3 4 20 3 17 19 3 8 17 1 20 5 11 11 1 9 13 1 1 5 3 17 17 3 3 18 3 17 5 1...
output:
0 0 0 2047032 0 0 0 0 0 839808 0 0 0 0 0 0 0 0 0 0 0 0 44641044 0 20412 0 0 0 0 0 0 0 6 0 0 0 0 81 0 0 0 0 0 0 0 0 0 0 0 313155072 0 0 0 0 0 0 0 0 0 5400 0 10368 0 0 0 0 14580 0 0 0 217728 40310784 0 0 218700 0 0 0 0 1620 0 0 0 0 0 108 146304 0 0 0 466560 288 0 0 0 0 0 0 0 276138 0 0 0 0 0 0 0 52488...
result:
ok 332 tokens
Test #4:
score: 0
Accepted
time: 496ms
memory: 46904kb
input:
5 1000 0 1000 5 779 779 2 543 840 3 30 477 1 10 295 3 463 741 1 1000 6 379 569 1 249 826 2 194 819 3 90 400 1 614 808 2 102 868 2 1000 8 463 981 1 680 857 3 560 623 1 209 659 1 55 957 2 244 327 1 321 888 3 37 204 3 1000 5 336 851 3 410 676 1 522 911 2 165 962 1 258 330 3
output:
56888193 0 0 0 0
result:
ok 5 tokens
Test #5:
score: 0
Accepted
time: 701ms
memory: 43184kb
input:
5 1000 9 190 765 1 212 745 3 437 798 3 682 814 3 122 289 1 44 821 1 115 448 3 400 936 2 562 639 3 1000 5 561 808 3 23 160 2 57 915 2 211 943 3 125 596 2 1000 1 398 739 2 1000 3 629 973 2 7 721 2 591 815 2 1000 10 536 708 1 217 256 2 690 913 3 418 871 2 302 325 2 334 830 2 496 573 2 396 865 1 240 837...
output:
0 0 722271060 85306976 0
result:
ok 5 tokens
Test #6:
score: -100
Time Limit Exceeded
input:
2 2000 1 1501 1703 2 2000 5 1230 1521 3 1022 1939 3 1241 1283 3 767 1944 2 303 1163 3