QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#403419 | #1286. Ternary String Counting | nKessi | WA | 1ms | 1704kb | C++14 | 3.0kb | 2024-05-02 11:48:55 | 2024-05-02 11:48:55 |
Judging History
answer
/*
世界の果てさえ
【世界的尽头在何处】
仆らは知らない
【我们也无从知晓】
*/
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <random>
#include <ctime>
#define pr pair <int, int>
#define mr make_pair
#define LL long long
#define ls tree[p].L
#define rs tree[p].R
using namespace std;
const int MAXN = 5e3 + 5, Mod = 1e9 + 7;
int T, n, m, L2[MAXN], R2[MAXN], L3[MAXN], R3[MAXN];
LL dp[MAXN][MAXN], H[MAXN], L[MAXN], nowl[MAXN], nowh[MAXN];
int down[MAXN], up[MAXN];
void read(int &x) {
x = 0; bool f = 1; char C = getchar();
for(; C < '0' || C > '9'; C = getchar()) if(C == '-') f = 0;
for(; C >= '0' && C <= '9'; C = getchar()) x = (x << 1) + (x << 3) + (C ^ 48);
x = (f ? x : -x);
}
int main() {
for(scanf("%d", &T); T; T --) {
read(n); read(m); int l, r, x;
for(int i = 0; i <= n; i ++) R2[i] = R3[i] = MAXN, L2[i] = L3[i] = -MAXN, down[i] = 0, up[i] = n;
for(int i = 1; i <= m; i ++) {
read(l); read(r); read(x);
if(x == 1) {
R2[r] = min(R2[r], l - 1);
}
else if(x == 2) {
L2[r] = max(L2[r], l); R3[r] = min(R3[r], l - 1);
}
else L3[r] = max(L3[r], l);
}
for(int i = 0; i <= n; i ++) for(int j = 0; j <= n; j ++) dp[i][j] = 0;
for(int i = 0; i <= n; i ++) L[i] = H[i] = 0;
dp[0][0] = 3; L[0] = 3; H[0] = 3;
for(int i = 1; i <= n; i ++) {
for(int j = 0; j <= n; j ++) nowl[j] = L[j], nowh[j] = H[j];
if(L2[i] <= i - 1 && R2[i] >= i - 1 && i - 1) {
for(int j = max(0, L3[i]); j <= min(i - 1, R3[i]); j ++) {
dp[j][i - 1] = (dp[j][i - 1] + H[j] + L[j]) % Mod;
nowh[i - 1] = (nowh[i - 1] + H[j] + L[j]) % Mod;
nowl[j] = (nowl[j] + H[j] + L[j]) % Mod;
}
}
for(int j = 0; j <= L3[i] - 1; j ++) {
while(down[j] <= up[j]) {
nowh[down[j]] = (nowh[down[j]] - dp[j][down[j]]) % Mod;
nowl[j] = (nowl[j] - dp[j][down[j]]) % Mod;
down[j] ++;
}
}
for(int j = R3[i] + 1; j <= n; j ++) {
while(down[j] <= up[j]) {
nowh[down[j]] = (nowh[down[j]] - dp[j][down[j]]) % Mod;
nowl[j] = (nowl[j] - dp[j][down[j]]) % Mod;
down[j] ++;
}
}
for(int j = max(0, L3[i]); j <= min(n, R3[i]); j ++) {
while(down[j] <= up[j]) {
// printf("|%d %d %d|\n", down[j], up[j], j);
if(down[j] < L2[i]) {
nowh[down[j]] = (nowh[down[j]] - dp[j][down[j]]) % Mod;
nowl[j] = (nowl[j] - dp[j][down[j]]) % Mod;
down[j] ++;
}
else if(up[j] > R2[i]) {
// printf("?\n");
nowh[up[j]] = (nowh[up[j]] - dp[j][up[j]]) % Mod;
nowl[j] = (nowl[j] - dp[j][up[j]]) % Mod;
up[j] --;
}
else break;
}
}
for(int j = 0; j <= n; j ++) H[j] = nowh[j], L[j] = nowl[j];//, printf("|%d %d|", H[j], L[j]);
// printf("\n");
}
LL ans = 0;
for(int i = 0; i <= n; i ++) ans = (ans + H[i]) % Mod;
printf("%lld\n", (ans + Mod) % Mod);
}
return 0;
}
/*
4
1 0
2 0
3 0
5 2
1 3 3
4 5 1
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 1704kb
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: 1696kb
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 40824 0 0 0 3108 0 0 1458 2916 0 11664 3186 0 0 0 0 0 0 0 0 6 810 0 0 0 30 96 216 6 0 162 0 0 0 162 0 108 0 0 558 2916 0 0 0 0 0 1458 0 0 6 810 324 8748 108 6 0 0 0 0 5004 24 0 0 30 0 18 36 504 0 6 0 1746 0 0 0 2604 0 2106 450 36 324 2772 0 0 0 0 0 108 0 18 0 0 378 0 1350 0 2646 324 0 0 36 ...
result:
wrong answer 5th words differ - expected: '24300', found: '40824'