ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#214463 | #2718. 8.2t3 | KXG | 90 | 2188ms | 76352kb | C++11 | 3.4kb | 2024-11-18 22:35:17 | 2024-11-19 08:39:01 |
answer
#include <cstdio>
#include <algorithm>
using namespace std;
const int mod = 998244353;
struct matrix {
int n = 0, m = 0;
int a[5][5] = {};
void print() {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
printf("%d ", a[i][j]);
}
printf("\n");
}
printf("\n");
}
};
matrix mul(matrix a, matrix b) {
matrix res;
res.n = a.n;
res.m = b.m;
for (int i = 1; i <= a.n; i++) {
for (int j = 1; j <= a.m; j++) {
for (int k = 1; k <= b.m; k++) {
res.a[i][k] = (res.a[i][k] + 1ll * a.a[i][j] * b.a[j][k] % mod) % mod;
}
}
}
return res;
}
matrix unit(int n) {
matrix res;
res.n = res.m = n;
for (int i = 1; i <= n; i++) {
res.a[i][i] = 1;
}
return res;
}
matrix pow(matrix a, long long p) {
matrix res = unit(a.n);
for (; p; p >>= 1, a = mul(a, a)) {
if (p & 1) {
res = mul(res, a);
}
}
return res;
}
struct segmenttree {
matrix a[200010];
matrix nodes[800010];
void pushup(int p) {
nodes[p] = mul(nodes[p << 1], nodes[p << 1 | 1]);
}
void build(int p, int l, int r) {
if (l == r) {
nodes[p] = a[l];
return;
}
int mid = (l + r) >> 1;
build(p << 1, l, mid);
build(p << 1 | 1, mid + 1, r);
pushup(p);
}
void modify(int p, int l, int r, int k, matrix x) {
if (l == r) {
nodes[p] = x;
return;
}
int mid = (l + r) >> 1;
if (k <= mid) {
modify(p << 1, l, mid, k, x);
} else {
modify(p << 1 | 1, mid + 1, r, k, x);
}
pushup(p);
}
} sgt;
matrix base;
int n, m, q, x[100010], y[100010], t[100010];
bool is[200010][5];
matrix make(int k) {
matrix res;
res.n = res.m = n;
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) {
if (is[k][j]) break;
if (i - j == 1 || j - i == 1) {
res.a[i][j] = res.a[j][i] = 1;
}
}
}
return res;
}
int main() {
scanf("%d%d%d", &n, &m, &q);
base = make(0);
for (int i = 1; i <= q; i++) {
scanf("%d%d", &x[i], &y[i]);
t[i] = y[i];
}
sort(t + 1, t + q + 1);
int uq = unique(t + 1, t + q + 1) - t - 1;
for (int i = 1; i <= uq; i++) {
sgt.a[2 * i - 1] = pow(base, t[i] - t[i - 1] - 1);
sgt.a[2 * i] = base;
}
sgt.a[2 * uq + 1] = pow(base, m - t[uq]);
int sgtn = 2 * uq + 1;
// for (int i = 1; i <= sgtn; i++) {
// sgt.a[i].print();
// }
sgt.build(1, 1, sgtn);
// sgt.nodes[1].print();
for (int i = 1; i <= q; i++) {
int k = lower_bound(t + 1, t + uq + 1, y[i]) - t;
is[k][x[i]] = true;
sgt.a[2 * k] = make(k);
// printf("===== %d =====\n", i);
// for (int j = 1; j <= sgtn; j++) {
// sgt.a[j].print();
// }
// printf("===== %d =====\n", i);
// printf("then the ans is :\n");
sgt.modify(1, 1, sgtn, 2 * k, make(k));
// sgt.nodes[1].print();
// printf("===== %d =====\n\n\n\n", i);
printf("%d\n", sgt.nodes[1].a[1][n]);
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 572kb
input:
3 4 5 3 1 1 4 1 2 1 3 2 2
output:
2 2 1 1 0
result:
ok 5 number(s): "2 2 1 1 0"
Test #2:
score: 10
Accepted
time: 297ms
memory: 43052kb
input:
2 99999 100000 2 70567 1 17791 2 77890 2 12623 2 13544 1 18390 2 8888 1 74050 2 67101 1 56764 2 3761...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 100000 numbers
Test #3:
score: 10
Accepted
time: 0ms
memory: 584kb
input:
3 1000 5 3 805 3 596 3 575 3 58 3 577
output:
154029661 576137007 787190680 393595340 196797670
result:
ok 5 number(s): "154029661 576137007 787190680 393595340 196797670"
Test #4:
score: 10
Accepted
time: 0ms
memory: 1156kb
input:
3 1000 1000 1 45 3 898 1 799 1 48 1 847 3 607 1 760 1 802 3 903 3 836 1 526 3 264 1 96 3 244 3 242 3...
output:
154029661 576137007 787190680 393595340 196797670 98398835 548321594 274160797 636202575 817223464 4...
result:
ok 1000 numbers
Test #5:
score: 10
Accepted
time: 445ms
memory: 43044kb
input:
3 100000 100000 1 74197 3 11259 3 65940 3 1906 3 40328 1 71201 1 50943 1 98978 1 70015 3 43996 1 114...
output:
159434530 79717265 538980809 768612581 883428467 940836410 470418205 734331279 866287816 433143908 2...
result:
ok 100000 numbers
Test #6:
score: 10
Accepted
time: 409ms
memory: 43048kb
input:
3 100000 100000 1 16644 3 29648 3 77047 1 94435 1 43985 1 89629 1 78236 1 93267 3 25517 1 52560 1 89...
output:
159434530 79717265 538980809 768612581 883428467 940836410 470418205 734331279 866287816 433143908 2...
result:
ok 100000 numbers
Test #7:
score: 10
Accepted
time: 0ms
memory: 656kb
input:
3 1000000000 100 1 574043575 1 413916829 3 96 1 394696238 1 40 3 38 1 69 1 968879034 1 52 1 62558778...
output:
745547840 372773920 186386960 93193480 46596740 23298370 11649185 504946769 751595561 874919957 9365...
result:
ok 100 numbers
Test #8:
score: 10
Accepted
time: 670ms
memory: 76352kb
input:
3 1000000000 100000 3 15019 1 79221 3 22394 1 89278 3 875067515 1 15404 1 615238057 3 89925 3 271777...
output:
745547840 372773920 186386960 93193480 46596740 23298370 11649185 504946769 751595561 874919957 9365...
result:
ok 100000 numbers
Test #9:
score: 10
Accepted
time: 367ms
memory: 39612kb
input:
4 99999 50000 4 66854 4 48295 4 95292 4 86389 4 9961 4 33406 4 96945 4 64418 4 19331 4 71257 4 36656...
output:
636299371 215744819 252527760 691521797 334927651 491663361 2328689 543779237 706792728 577050832 33...
result:
ok 50000 numbers
Test #10:
score: 0
Time Limit Exceeded
input:
4 999999999 100000 4 908546081 4 885383980 4 37966517 4 191661556 4 107475378 4 699076844 4 58764448...
output:
991199402 576071352 289809637 863841042 998188739 377996189 808622907 336679175 553400478 673609116 ...