QOJ.ac
QOJ
ID | 提交记录ID | 题目 | Hacker | Owner | 结果 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|
#840 | #494835 | #9141. Array Spread | ucup-team3953 | ucup-team052 | Success! | 2024-09-18 18:52:59 | 2024-09-18 18:58:31 |
详细
Extra Test:
Wrong Answer
time: 1ms
memory: 4052kb
input:
1 17 8 5 10 9 15 6 12 2 3 8 13 7 17 11 16 4 14
output:
1
result:
wrong answer 1st numbers differ - expected: '499122178', found: '1'
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#494835 | #9141. Array Spread | ucup-team052# | WA | 7ms | 4180kb | C++14 | 2.2kb | 2024-07-27 17:11:28 | 2024-10-14 07:39:25 |
answer
#include <bits/stdc++.h>
using namespace std;
const int md = 998244353;
inline int mul(int x, int y) {
return 1ull * x * y % md;
}
inline int fpow(int x, int y) {
int ans = 1;
while (y) {
if (y & 1) ans = mul(ans, x);
y >>= 1; x = mul(x, x);
}
return ans;
}
const int N = 4005;
vector <int> vec[N];
int l[N], r[N], b[N], mxr[N], mnr[N];
int T, n, m, ans1, ans2;
int main() {
scanf("%d", &T);
while (T--) {
memset(mxr, 0, sizeof(mxr));
memset(mnr, 0x3f, sizeof(mnr));
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d%d", &l[i], &r[i]);
b[i] = l[i]; b[i + m] = r[i] + 1;
}
for (int i = 1; i <= 2 * m; i++) vec[i].clear();
sort(b + 1, b + 2 * m + 1);
int len = unique(b + 1, b + 2 * m + 1) - b - 1;
for (int i = 1; i <= m; i++) {
l[i] = lower_bound(b + 1, b + len + 1, l[i]) - b;
r[i] = lower_bound(b + 1, b + len + 1, r[i] + 1) - b - 1;
vec[l[i]].push_back(r[i]);
}
for (int i = 1; i <= len; i++) {
mxr[i] = mxr[i - 1];
for (auto j : vec[i]) mxr[i] = max(mxr[i], j);
}
for (int i = len; i >= 1; i--) {
mnr[i] = mnr[i + 1];
for (auto j : vec[i]) mnr[i] = min(mnr[i], j);
}
ans1 = ans2 = 1;
for (int i = 1; i <= m; i++) {
// l[i], r[i]
int now1 = l[i] - 1, now2 = r[i], cnt1 = 0, cnt2 = 1;
while (1) {
while (now1 < now2) {
if (mxr[now1 + 1] > now1) {
++cnt1;
now1 = mxr[now1 + 1];
} else break;
}
if (now1 < now2) break;
if (cnt2 * ans2 > cnt1 * ans1) {
ans1 = cnt2;
ans2 = cnt1;
}
if (mnr[now2 + 1] == 0x3f3f3f3f) break;
now2 = mnr[now2 + 1]; ++cnt2;
}
}
int ans = mul(ans1, fpow(ans2, md - 2));
printf("%d\n", ans);
}
return 0;
}