Submission #27743665
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define per(i, a, n) for (ll i = n - 1; i >= a; i--)
constexpr ll mod = 998244353;
#define all(v) (v).begin(), (v).end()
vector<int> vle[305]; // [r pos] = {l pos...} 区间右端点到左端点
ll dp[305][305][305]; // [l][r][x] = [l..r] 最大的是x的方案数, 其中不论l取值多少,x与[l,r]至少属于[l,r]中的一个完整区间
ll rdp[305][305][305]; // dp 前缀和
// 默认 全false, 在[l..r]之间 是否存在完整区间
bool exi[305][305];
int cl[305]; // 右端点 in [i..最右测] = 区间的最小左端点
int main() {
int n, m;
scanf("%d %d", &n, &m);
rep(i, 0, m) {
int l, r;
scanf("%d %d", &l, &r);
vle[r].push_back(l);
}
rep(i, 1, n+1) sort(all(vle[i]));
rep(len, 2, n+1) { // 枚举 长度
rep(r, len, n+1) { // 右端点 从小到大
int l = r - len + 1; // 左侧端点 = 右端点 - 长度 +1
int nw = r + 1; // 左端点, 在[l..r] 中
per(j, l, r + 1) { // j(右端点)从大到小 [l,r] 范围内的每个右端点
int t = lower_bound(all(vle[j]), l) - vle[j].begin();
if (t < vle[j].size()) nw = min(nw, vle[j][t]);
cl[j] = nw;
}
if (nw == r+1) { // 没有任何有效区间
exi[l][r] = false;
continue;
}
exi[l][r] = true; // 右端点在 [l+1 ..r], 长度小于等于 len 的区间 存在
rep(x, l, r+1) { // [l..x-1]x[x+1..r]
if (x < cl[x]) continue; // 不存在 [l,r] 之间的小区间 包含 坐标x
// 注意这里, 当[l..x-1]不存在时是1, 而[l..x-1]存在时,因为防止重复统计可能[cl[x]..x-1]是0
ll sl = exi[l][x-1] ? rdp[l][x-1][x-1] - rdp[l][x-1][cl[x]-1] : 1;
// 而对于右侧 似乎可以直接判断前缀和是否非零,但实际上因为是取mod运算,可能为mod的倍数,所以还是需要一个exi的辅助数组
ll sr = exi[x+1][r] ? rdp[x+1][r][r] - rdp[x + 1][r][x] : 1;
dp[l][r][x] = ((sl%mod) * (sr%mod))%mod; // [l,r-1]中 最大的下标为x, 方案数
}
rep(j, l, r + 1) rdp[l][r][j] = (rdp[l][r][j-1] + dp[l][r][j])%mod;
}
}
printf("%lld", (rdp[1][n][n]+mod)%mod); // [0,n-1] 最大下标[0..n-1]的方案数
return 0;
}
Submission Info
| Submission Time |
|
| Task |
B - Range Argmax |
| User |
cromarmot |
| Language |
C++ (GCC 9.2.1) |
| Score |
900 |
| Code Size |
2414 Byte |
| Status |
AC |
| Exec Time |
389 ms |
| Memory |
219572 KiB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:30:15: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
30 | if (t < vle[j].size()) nw = min(nw, vle[j][t]);
| ~~^~~~~~~~~~~~~~~
./Main.cpp:17:8: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
17 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
./Main.cpp:20:10: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
20 | scanf("%d %d", &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
900 / 900 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt |
| All |
00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt, 01-024.txt, 01-025.txt, 01-026.txt, 01-027.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00-sample-001.txt |
AC |
5 ms |
3736 KiB |
| 00-sample-002.txt |
AC |
2 ms |
3928 KiB |
| 00-sample-003.txt |
AC |
2 ms |
3924 KiB |
| 01-001.txt |
AC |
2 ms |
3736 KiB |
| 01-002.txt |
AC |
8 ms |
7688 KiB |
| 01-003.txt |
AC |
293 ms |
179312 KiB |
| 01-004.txt |
AC |
91 ms |
70952 KiB |
| 01-005.txt |
AC |
45 ms |
33476 KiB |
| 01-006.txt |
AC |
22 ms |
14944 KiB |
| 01-007.txt |
AC |
23 ms |
23908 KiB |
| 01-008.txt |
AC |
131 ms |
114640 KiB |
| 01-009.txt |
AC |
246 ms |
198484 KiB |
| 01-010.txt |
AC |
170 ms |
145020 KiB |
| 01-011.txt |
AC |
4 ms |
4944 KiB |
| 01-012.txt |
AC |
199 ms |
162384 KiB |
| 01-013.txt |
AC |
16 ms |
12168 KiB |
| 01-014.txt |
AC |
369 ms |
218136 KiB |
| 01-015.txt |
AC |
389 ms |
219136 KiB |
| 01-016.txt |
AC |
374 ms |
218524 KiB |
| 01-017.txt |
AC |
49 ms |
36524 KiB |
| 01-018.txt |
AC |
27 ms |
10964 KiB |
| 01-019.txt |
AC |
93 ms |
71432 KiB |
| 01-020.txt |
AC |
276 ms |
218148 KiB |
| 01-021.txt |
AC |
338 ms |
218932 KiB |
| 01-022.txt |
AC |
256 ms |
205456 KiB |
| 01-023.txt |
AC |
305 ms |
216772 KiB |
| 01-024.txt |
AC |
345 ms |
219572 KiB |
| 01-025.txt |
AC |
15 ms |
3820 KiB |
| 01-026.txt |
AC |
275 ms |
218116 KiB |
| 01-027.txt |
AC |
318 ms |
219284 KiB |