QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#735246 | #4887. Fast Bridges | Selnev | WA | 87ms | 18176kb | C++14 | 2.6kb | 2024-11-11 18:40:18 | 2024-11-11 18:40:20 |
Judging History
answer
#include <bits/stdc++.h>
#define MOD 998244353
#define inv3 332748118
using namespace std;
struct Node {
int x[2], y[2];
} a0;
int m;
long long ans;
struct {
int n = 0, nx, ny;
Node a[509];
int arrx[509], arry[509], dis[509][509];
vector<int> b[509][509];
void init() {
sort(a + 1, a + n + 1, [](const Node &i, const Node &j) {return i.x[0] == j.x[0] ? i.y[0] > j.y[0] : i.x[0] > j.x[0];});
for (int i = 1; i <= n; ++ i) arrx[i] = a[i].x[1], arry[i] = a[i].y[1];
arrx[0] = 1, arrx[n + 1] = m + 1, arry[0] = 1, arry[n + 1] = m + 1;
sort(arrx + 1, arrx + n + 1);
sort(arry + 1, arry + n + 1);
nx = unique(arrx, arrx + n + 2) - arrx - 1;
ny = unique(arry, arry + n + 2) - arry - 1;
memset(dis, 0xc0, sizeof(dis));
for (int i = 1; i <= n; ++ i) dis[i][i] = 0;
for (int i = 1; i <= n; ++ i)
for (int j = 1; j <= n; ++ j)
if (a[i].x[0] >= a[j].x[1] && a[i].y[0] >= a[j].y[1])
dis[i][j] = 1;
for (int k = 1; k <= n; ++ k)
for (int i = 1; i <= n; ++ i)
for (int j = 1; j <= n; ++ j)
dis[i][j] = max(dis[i][j], dis[i][k] + dis[k][j]);
for (int i = 1; i <= n; ++ i)
b[lower_bound(arrx, arrx + nx + 1, a[i].x[1]) - arrx][lower_bound(arry, arry + ny + 1, a[i].y[1]) - arry].push_back(i);
}
vector<int> vec_row, vec_col[509];
int f[509], h[509];
inline void update(int u) {
vec_row.push_back(u);
for (auto i : vec_row) f[i] = max(f[i], dis[u][i]);
}
void solve() {
init();
for (int i = 0; i < nx; ++ i) {
vec_row.clear();
memset(f, -1, sizeof(f));
for (int j = 0; j < ny; ++ j) {
for (auto k : b[i][j]) vec_col[j].push_back(k);
for (auto k : vec_col[j]) update(k);
const long long temp = (long long)(arrx[i + 1] - arrx[i]) * (arry[j + 1] - arry[j]) % MOD;
if (!temp) continue;
memset(h, 0, sizeof(h));
int sum_area = 0;
for (int k = 1; k <= n; ++ k) {
const int d = f[k];
if (d == -1 || h[d] >= a[k].y[0]) continue;
sum_area += (a[k].y[0] - h[d]) * a[k].x[0];
h[d] = a[k].y[0];
}
(ans = (ans - sum_area * temp) % MOD) < 0 ? ans += MOD, void() : void();
}
}
}
} task[2];
int main() {
int n;
scanf("%d %d", &n, &m);
ans = (long long)(m - 1) * (m + 1) % MOD * m % MOD * m % MOD * m % MOD * inv3 % MOD;
for (int i = 1; i <= n; ++ i) {
scanf("%d %d %d %d", &a0.x[0], &a0.y[0], &a0.x[1], &a0.y[1]);
if (a0.y[0] < a0.y[1]) task[0].a[++ task[0].n] = a0;
else task[1].a[++ task[1].n] = {{m - a0.x[1] + 1, m - a0.x[0] + 1}, {a0.y[1], a0.y[0]}};
}
task[0].solve(), task[1].solve();
printf("%lld", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 18176kb
input:
2 2 1 1 2 2 1 2 2 1
output:
6
result:
ok answer is '6'
Test #2:
score: 0
Accepted
time: 0ms
memory: 17992kb
input:
0 1000000000
output:
916520226
result:
ok answer is '916520226'
Test #3:
score: 0
Accepted
time: 4ms
memory: 18176kb
input:
5 5 1 1 3 3 3 3 5 1 3 3 4 5 3 3 5 4 1 5 3 3
output:
946
result:
ok answer is '946'
Test #4:
score: 0
Accepted
time: 0ms
memory: 18128kb
input:
200 5 1 1 4 2 2 5 4 4 2 3 4 2 2 4 3 5 1 4 4 2 2 5 4 2 1 2 4 4 1 2 2 4 1 4 5 1 3 4 5 1 4 2 5 1 2 2 5 4 3 2 5 1 3 1 5 2 4 2 5 3 1 3 5 1 3 4 4 5 2 2 4 3 2 3 5 4 1 4 5 3 2 2 3 1 2 5 3 3 1 1 5 3 4 4 5 5 1 3 4 4 4 3 5 1 2 3 3 4 3 4 4 2 1 4 4 5 2 1 4 4 1 3 5 2 1 1 3 3 1 5 3 1 1 1 3 5 1 4 3 5 4 5 5 4 1 1 4 ...
output:
708
result:
ok answer is '708'
Test #5:
score: 0
Accepted
time: 24ms
memory: 18156kb
input:
500 10 5 6 7 10 1 3 8 10 3 3 4 9 2 10 10 2 9 4 10 10 5 4 7 8 7 1 10 7 3 1 7 10 5 2 8 9 6 3 7 10 3 10 7 9 4 9 5 1 2 5 3 3 7 10 8 2 7 7 9 8 6 6 8 3 5 10 8 8 1 1 5 5 3 3 10 5 5 5 7 6 3 8 4 7 6 7 7 5 7 3 10 9 5 3 9 4 4 6 10 5 1 5 9 10 5 6 9 7 3 10 10 3 1 2 5 7 4 6 5 1 3 1 8 5 5 8 8 9 1 8 4 3 6 4 7 10 7 ...
output:
27373
result:
ok answer is '27373'
Test #6:
score: 0
Accepted
time: 24ms
memory: 18044kb
input:
500 30 3 13 20 29 14 5 16 25 2 29 9 15 23 30 24 9 1 18 24 28 4 16 5 2 3 29 30 25 4 8 24 19 8 26 10 24 20 14 26 25 15 8 25 25 5 13 18 28 3 30 29 10 14 26 25 11 11 19 16 4 9 4 29 30 15 10 16 8 2 29 12 2 11 22 20 28 4 10 28 1 24 17 30 1 8 26 27 9 15 25 30 14 16 20 24 17 9 23 12 13 9 16 25 28 2 15 8 16 ...
output:
7717993
result:
ok answer is '7717993'
Test #7:
score: 0
Accepted
time: 28ms
memory: 18148kb
input:
500 100 25 55 55 43 14 22 84 5 57 7 79 15 63 9 86 23 22 3 53 97 2 22 64 65 32 52 66 30 76 37 79 22 46 100 76 22 21 78 78 44 29 41 92 55 43 14 46 3 14 97 42 1 16 7 35 64 15 27 29 3 11 92 92 70 4 13 66 2 3 38 55 82 41 94 83 44 52 90 100 82 6 100 99 70 18 38 24 22 74 17 98 20 17 94 44 82 33 97 48 19 12...
output:
291628571
result:
ok answer is '291628571'
Test #8:
score: 0
Accepted
time: 87ms
memory: 18056kb
input:
500 8 2 4 8 2 3 7 5 4 2 6 8 1 4 8 5 5 6 6 7 5 2 6 5 5 1 6 8 5 6 5 7 3 4 8 5 7 5 7 6 5 1 6 4 5 2 3 4 2 2 8 8 6 3 8 4 3 5 6 7 2 7 8 8 3 1 8 4 7 1 6 6 1 1 8 7 1 1 4 3 3 2 3 3 1 1 4 5 1 1 8 5 4 7 7 8 5 2 7 4 1 3 7 4 3 2 3 5 1 3 7 8 1 4 7 5 5 6 6 8 3 2 7 5 1 2 5 4 3 5 4 8 2 4 5 8 3 2 3 4 1 2 8 3 2 5 6 8 ...
output:
9321
result:
ok answer is '9321'
Test #9:
score: -100
Wrong Answer
time: 64ms
memory: 18152kb
input:
500 1000000000 228604634 522874974 789854111 585676486 340802063 175643637 661594207 749079321 490078806 844144515 583746323 707696611 833939453 901516824 867397264 848066012 553537526 886003963 679012061 187030606 351500555 847099665 751201742 855105070 169763646 729114554 248951243 211939611 17040...
output:
442159862
result:
wrong answer expected '230090667', found '442159862'