QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#429744#4887. Fast BridgesSampsonYWWA 332ms32928kbC++144.6kb2024-06-02 20:16:422024-06-02 20:16:44

Judging History

你现在查看的是最新测评结果

  • [2024-06-02 20:16:44]
  • 评测
  • 测评结果:WA
  • 用时:332ms
  • 内存:32928kb
  • [2024-06-02 20:16:42]
  • 提交

answer

#include <bits/stdc++.h>
#define db double
#define il inline
#define re register
#define ll long long
#define ui unsigned
#define ull ui ll
#define i128 __int128
#define pii pair<int, int>
#define fi first
#define se second
#define eb emplace_back
#define SZ(v) (int)v.size()
#define ALL(v) v.begin(), v.end()
#define mems(v, x) memset(v, x, sizeof(v))
#define memc(a, b) memcpy(a, b, sizeof(a))
#define FOR(i, L, R) for(re int i = (L); i <= (R); ++i)
#define ROF(i, R, L) for(re int i = (R); i >= (L); --i)
#define LS i << 1, l, mid
#define RS i << 1 | 1, mid + 1, r
#define popc(x) __builtin_popcount(x)
#define popcll(x) __builtin_popcountll(x)
using namespace std;
#define N 505
#define M 1000000000
#define P 998244353
il int add(int x, int y) {return x + y < P ? x + y : x + y - P;}
il void addr(int &x, int y) {(x += y) >= P && (x -= P);}
il int qpow(int p, int n = P - 2) {
  int s = 1;
  while(n) {
    if(n & 1) s = 1ll * s * p % P;
    p = 1ll * p * p % P, n >>= 1;
  }
  return s;
}
il void chkmin(int &x, int y) {(x > y) && (x = y);}
il void chkmax(int &x, int y) {(x < y) && (x = y);}
int n, m;
struct edge {
  int a, b, c, d;
} e[N];
int X[N * 2], LX;
int Y[N * 2], LY;
int dp[N][N];
vector<int> pos[N * 2][N * 2];
int f[2][N * 2][N];
int val[N];
il int solve(vector<edge> e) {
  // if(e.empty()) return 0;
  sort(ALL(e), [](edge A, edge B) {return A.c < B.c;});
  LX = LY = 0; int K = SZ(e), ans = 0;
  for(auto [a, b, c, d] : e) X[++LX] = a, X[++LX] = c, Y[++LY] = b, Y[++LY] = d;
  X[++LX] = Y[++LY] = m + 1;
  sort(X + 1, X + 1 + LX), LX = unique(X + 1, X + 1 + LX) - X - 1;
  sort(Y + 1, Y + 1 + LY), LY = unique(Y + 1, Y + 1 + LY) - Y - 1;
  auto idX = [](int v) {return lower_bound(X + 1, X + 1 + LX, v) - X;} ;
  auto idY = [](int v) {return lower_bound(Y + 1, Y + 1 + LY, v) - Y;} ;
  for(auto &[a, b, c, d] : e) a = idX(a), c = idX(c), b = idY(b), d = idY(d);
  // for(auto [a, b, c, d] : e) cout << "(" << a << ", " << b << ") -> (" << c << ", " << d << ")\n";
  // FOR(i, 1, LX) cout << X[i] << " \n"[i == LX];
  // FOR(i, 1, LY) cout << Y[i] << " \n"[i == LY];
  auto chk = [&](int i, int j) {--i, --j; if(e[i].c > e[j].a || e[i].d > e[j].b) return 0; return 1;} ;
  FOR(i, 1, K) FOR(j, 1, K) if(i != j && chk(i, j)) dp[i][j] = 2; else dp[i][j] = (i == j);
  FOR(k, 1, K) FOR(i, 1, K) FOR(j, 1, K) if(chk(i, k) && chk(k, j)) chkmax(dp[i][j], dp[i][k] + dp[k][j] - 1);
  // mems(dp, 0);
  // FOR(i, 1, n) dp[i][i] = 1;
  // FOR(L, 2, n) FOR(i, 1, n - L + 1) {
  //   int j = i + L - 1; if(!chk(i, j)) continue; dp[i][j] = 2;
  //   FOR(k, i + 1, j - 1) if(chk(i, k) && chk(k, j)) chkmax(dp[i][j], dp[i][k] + dp[k][j] - 1);
  // }
  // FOR(i, 1, K) FOR(j, 1, K) cout << dp[i][j] << " \n"[j == K];
  FOR(i, 1, LX) FOR(j, 1, LY) vector<int>().swap(pos[i][j]);
  FOR(i, 0, K - 1) pos[e[i].a][e[i].b].eb(i + 1);
  int now = 0, cur = 1; mems(f, 0);
  ROF(x, LX - 1, 1) {
    swap(now, cur), mems(f[now], 0);
    ROF(y, LY - 1, 1) {
      FOR(i, 1, K) {
        f[now][y][i] = max(f[now][y + 1][i], f[cur][y][i]);
        for(auto id : pos[x][y]) chkmax(f[now][y][i], dp[id][i]);//, cerr << x << " " << y << " " << i << " " << id << " val = " << dp[id][i] << "\n";
      }
      int s = 0;
      FOR(i, 1, K) val[i] = m + 1;
      FOR(i, 1, K) {
        int v = f[now][y][i];
        // cerr << x << " " << y << " " << i << " " << v << "\n";
        if(!v || e[i - 1].d >= val[v]) continue;
        // cerr << "OK\n";
        // cerr << "goto = " << e[i - 1].c << " " << e[i - 1].d << " " << val[v] << " and s = " << s << "\n";
        addr(s, 1ll * (m - X[e[i - 1].c] + 1) * (val[v] - Y[e[i - 1].d]) % P), val[v] = Y[e[i - 1].d];
      }
      // cerr << "A plane = " << s << "\n";
      // cout << x << " " << y << " " << s << "\n";
      addr(ans, 1ll * (X[x] - X[x - 1]) * (Y[y] - Y[y - 1]) % P * s % P);
    }
  }
  // cout << "-----------------------------------------------\n";
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> n >> m;
  FOR(i, 1, n) {
    auto &[a, b, c, d] = e[i];
    cin >> a >> b >> c >> d;
  }
  vector<edge> A, B;
  FOR(i, 1, n) if(e[i].b < e[i].d) A.eb(e[i]); else B.eb(e[i]);
  for(auto &[a, b, c, d] : B) {
    a = m - a + 1, c = m - c + 1, swap(a, c), swap(b, d);
    // b = m - b + 1, d = m - d + 1;
  }
  int ans = add(1ll * m * (m + 1) % P * (m * 2 + 1) % P * qpow(3) % P, P - 1ll * m * (m + 1) / 2 % P * (m + 1) % P);
  ans = 2ll * m * m % P * ans % P;
  // cerr << ans << " " << solve(A) << " " << solve(B) << "\n";
  cout << add(ans, P - add(solve(A), solve(B)));
  cerr << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 32032kb

input:

2 2
1 1 2 2
1 2 2 1

output:

6

result:

ok answer is '6'

Test #2:

score: 0
Accepted
time: 4ms
memory: 31908kb

input:

0 1000000000

output:

916520226

result:

ok answer is '916520226'

Test #3:

score: 0
Accepted
time: 4ms
memory: 31752kb

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: 3ms
memory: 32196kb

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: 25ms
memory: 32316kb

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: 28ms
memory: 32348kb

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: 49ms
memory: 32280kb

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: 78ms
memory: 32928kb

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: 332ms
memory: 32452kb

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:

-1973216050

result:

wrong answer expected '230090667', found '-1973216050'