QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#364597#6304. RectangleJCY_WA 1449ms61652kbC++148.2kb2024-03-24 15:32:392024-03-24 15:32:40

Judging History

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

  • [2024-03-24 15:32:40]
  • 评测
  • 测评结果:WA
  • 用时:1449ms
  • 内存:61652kb
  • [2024-03-24 15:32:39]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using i128 = __int128;
using u128 = unsigned __int128;
template <typename T>
void chkmax(T &x, const T &y) {
  if (x < y) x = y;
}
template <typename T>
void chkmin(T &x, const T &y) {
  if (y < x) x = y;
}
constexpr int MOD = 998244353;
void inc(int &x, int y) {
  x += y;
  if (x >= MOD) x -= MOD;
}
void dec(int &x, int y) {
  x -= y;
  if (x < 0) x += MOD;
}
int add(int x, int y) {
  x += y;
  return x >= MOD ? x - MOD : x;
}
int sub(int x, int y) {
  x -= y;
  return x < 0 ? x + MOD : x;
}
int adj(int x) { return x < 0 ? x + MOD : x; }
int S1(int x) { return (ll)x * (x + 1) / 2 % MOD; }
int S2(int x) { return (i128)x * (x + 1) * (x * 2 + 1) / 6 % MOD; }
struct rectangle {
  int xl, xr, yl, yr;
};
constexpr int MAXN = 1e5 + 10, MAXV = 1e9, INF = 0x3f3f3f3f;
int n, mpx[MAXN * 2], mpy[MAXN * 2], szx, szy;
rectangle a[MAXN];
namespace sub1 {
pair<int, int> prf[MAXN * 2], suf[MAXN * 2];
int solve() {
  fill(prf, prf + szx + 1, make_pair(-INF, INF));
  fill(suf + 1, suf + szx + 2, make_pair(-INF, INF));
  for (int i = 1; i <= n; ++i) {
    chkmax(prf[a[i].xr].first, a[i].xl);
    chkmin(prf[a[i].xr].second, a[i].xr);
    chkmax(suf[a[i].xl].first, a[i].xl);
    chkmin(suf[a[i].xl].second, a[i].xr);
  }
  for (int i = 1; i <= szx; ++i) {
    chkmax(prf[i].first, prf[i - 1].first);
    chkmin(prf[i].second, prf[i - 1].second);
  }
  for (int i = szx; i >= 1; --i) {
    chkmax(suf[i].first, suf[i + 1].first);
    chkmin(suf[i].second, suf[i + 1].second);
  }
  int ret = 0;
  for (int i = 1; i <= szx; ++i) {
    if (prf[i - 1].first > prf[i - 1].second ||
        suf[i + 1].first > suf[i + 1].second) {
      continue;
    }
    if (prf[i - 1].first == -INF && suf[i + 1].first == -INF) {
      ret = (ret + (ll)(MAXV + 1) * (S1(mpx[i]) - S1(mpx[i - 1])) -
             (ll)MAXV * (mpx[i] - mpx[i - 1]) - (S2(mpx[i]) - S2(mpx[i - 1]))) %
            MOD;
    } else if (prf[i - 1].first == -INF) {
      ret = (ret + (ll)(S1(mpx[i] - 1) - S1(mpx[i - 1] - 1)) *
                       (mpx[suf[i + 1].second] - mpx[suf[i + 1].first - 1])) %
            MOD;
    } else if (suf[i + 1].first == -INF) {
      ret = (ret + (ll)(S1(MAXV - mpx[i - 1] - 1) - S1(MAXV - mpx[i] - 1)) *
                       (mpx[prf[i - 1].second] - mpx[prf[i - 1].first - 1])) %
            MOD;
    } else {
      ret = (ret + (ll)(mpx[i] - mpx[i - 1]) *
                       (mpx[prf[i - 1].second] - mpx[prf[i - 1].first - 1]) %
                       MOD *
                       (mpx[suf[i + 1].second] - mpx[suf[i + 1].first - 1])) %
            MOD;
    }
  }
  return adj(ret);
}
}  // namespace sub1
namespace sub2 {
namespace sgt1 {
int ls(int p) { return p << 1; }
int rs(int p) { return p << 1 | 1; }
int sum[MAXN * 4], cov[MAXN * 4], mx[MAXN * 4];
stack<pair<int *, int>> stk;
void get_down(int p, int l, int r, int x) {
  stk.emplace(sum + p, sum[p]);
  stk.emplace(mx + p, mx[p]);
  stk.emplace(cov + p, cov[p]);
  sum[p] = (ll)mpx[x] * (mpx[r] - mpx[l - 1]) % MOD;
  mx[p] = x;
  cov[p] = x;
}
void push_down(int p, int l, int mid, int r) {
  if (cov[p] != -1) {
    get_down(ls(p), l, mid, cov[p]);
    get_down(rs(p), mid + 1, r, cov[p]);
    stk.emplace(cov + p, cov[p]);
    cov[p] = -1;
  }
}
void push_up(int p) {
  stk.emplace(sum + p, sum[p]);
  stk.emplace(mx + p, mx[p]);
  sum[p] = add(sum[ls(p)], sum[rs(p)]);
  mx[p] = mx[rs(p)];
}
void build(int p, int l, int r) {
  cov[p] = -1;
  sum[p] = (ll)(mpx[r] - mpx[l - 1]) * MAXV % MOD;
  mx[p] = szx;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(ls(p), l, mid);
  build(rs(p), mid + 1, r);
}
void update(int p, int l, int r, int ql, int qr, int x) {
  if (ql <= l && r <= qr) {
    get_down(p, l, r, x);
    return;
  }
  int mid = (l + r) >> 1;
  push_down(p, l, mid, r);
  if (ql <= mid) update(ls(p), l, mid, ql, qr, x);
  if (qr > mid) update(rs(p), mid + 1, r, ql, qr, x);
  push_up(p);
}
int find_gt(int p, int l, int r, int x) {
  if (mx[p] <= x) return szx + 1;
  if (l == r) return l;
  int mid = (l + r) >> 1;
  push_down(p, l, mid, r);
  int tmp = find_gt(ls(p), l, mid, x);
  return tmp == szx + 1 ? find_gt(rs(p), mid + 1, r, x) : tmp;
}
int query(int p, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) return sum[p];
  int mid = (l + r) >> 1;
  push_down(p, l, mid, r);
  if (qr <= mid) return query(ls(p), l, mid, ql, qr);
  if (ql > mid) return query(rs(p), mid + 1, r, ql, qr);
  return add(query(ls(p), l, mid, ql, qr), query(rs(p), mid + 1, r, ql, qr));
}
void undo(int tar) {
  for (; (int)stk.size() > tar; stk.pop()) *stk.top().first = stk.top().second;
}
}  // namespace sgt1
namespace sgt2 {
int ls(int p) { return p << 1; }
int rs(int p) { return p << 1 | 1; }
vector<pair<int, int>> buc[MAXN * 8];
void build(int p, int l, int r) {
  buc[p].clear();
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(ls(p), l, mid);
  build(rs(p), mid + 1, r);
}
void insert(int p, int l, int r, int ql, int qr, const pair<int, int> &x) {
  if (ql <= l && r <= qr) {
    buc[p].emplace_back(x);
    return;
  }
  int mid = (l + r) >> 1;
  if (ql <= mid) insert(ls(p), l, mid, ql, qr, x);
  if (qr > mid) insert(rs(p), mid + 1, r, ql, qr, x);
}
int solve(int p, int l, int r, int mnr, int mxl) {
  int rec = sgt1::stk.size(), ret = 0;
  for (auto &i : buc[p]) {
    int tmp = sgt1::find_gt(1, 1, szx, i.second);
    if (tmp < i.first) sgt1::update(1, 1, szx, tmp, i.first - 1, i.second);
    chkmax(mxl, i.first);
    chkmin(mnr, i.second);
  }
  if (l == r) {
    int pos = sgt1::find_gt(1, 1, szx, mxl - 1);
    if (pos <= mnr) {
      // i \in [mpx[pos - 1] + 1, mpx[mnr]]
      // - max(i, mpx[mxl - 1])

      // i \in [max(mpx[pos - 1] + 1, mpx[mxl - 1]), mpx[mnr]] => -i
      // i \in [mpx[pos - 1] + 1, min(mpx[mnr], mpx[mxl - 1] - 1)] => - mpx[mxl - 1]
      ret = sgt1::query(1, 1, szx, pos, mnr);
      int pl = max(mpx[pos - 1] + 1, mpx[mxl - 1]), pr = mpx[mnr];
      if (pl <= pr) dec(ret, sub(S1(pr), S1(pl - 1)));
      pl = mpx[pos - 1] + 1;
      pr = min(mpx[mnr], mpx[mxl - 1] - 1);
      if (pl <= pr) ret = adj((ret - (ll)mpx[mxl - 1] * (pr - pl + 1)) % MOD);
      ret = (ll)ret * (mpy[l] - mpy[l - 1]) % MOD;
    }
  } else {
    int mid = (l + r) >> 1;
    ret = add(solve(ls(p), l, mid, mnr, mxl), solve(rs(p), mid + 1, r, mnr, mxl));
  }
  sgt1::undo(rec);
  return ret;
}
}  // namespace sgt2
int solve() {
  sgt2::build(1, 1, szy);
  for (int i = 1; i <= n; ++i) {
    if (a[i].yl != 1)
      sgt2::insert(1, 1, szy, 1, a[i].yl - 1, {a[i].xl, a[i].xr});
    if (a[i].yr != szy)
      sgt2::insert(1, 1, szy, a[i].yr + 1, szy, {a[i].xl, a[i].xr});
  }
  sgt1::build(1, 1, szx);
  return sgt2::solve(1, 1, szy, szx, 1);
}
}  // namespace sub2
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int cas;
  cin >> cas;
  while (cas--) {
    cin >> n;
    szx = szy = 0;
    for (int i = 1, xl, xr, yl, yr; i <= n; ++i) {
      cin >> xl >> yl >> xr >> yr;
      mpx[++szx] = xl - 1;
      mpx[++szx] = xr;
      mpy[++szy] = yl - 1;
      mpy[++szy] = yr;
      a[i] = {xl, xr, yl, yr};
    }
    mpx[++szx] = mpy[++szy] = MAXV;
    sort(mpx + 1, mpx + szx + 1);
    szx = unique(mpx + 1, mpx + szx + 1) - mpx - 1;
    sort(mpy + 1, mpy + szy + 1);
    szy = unique(mpy + 1, mpy + szy + 1) - mpy - 1;
    for (int i = 1; i <= n; ++i) {
      a[i].xl = lower_bound(mpx + 1, mpx + szx + 1, a[i].xl - 1) - mpx + 1;
      a[i].xr = lower_bound(mpx + 1, mpx + szx + 1, a[i].xr) - mpx;
      a[i].yl = lower_bound(mpy + 1, mpy + szy + 1, a[i].yl - 1) - mpy + 1;
      a[i].yr = lower_bound(mpy + 1, mpy + szy + 1, a[i].yr) - mpy;
    }
    int ans = add(sub1::solve(), sub2::solve());
    swap_ranges(mpx + 1, mpx + max(szx, szy) + 1, mpy + 1);
    swap(szx, szy);
    for (int i = 1; i <= n; ++i) {
      swap(a[i].xl, a[i].yl);
      swap(a[i].xr, a[i].yr);
    }
    inc(ans, add(sub1::solve(), sub2::solve()));
    cout << ans << "\n";
  }
  return 0;
}
/*
g++ G.cpp -o G -O2 -std=c++14 -Wall -Wextra -Wshadow -g
-fsanitize=address,undefined
*/
/*
1
1
1 1 1000000000 1000000000
*/

详细

Test #1:

score: 100
Accepted
time: 6ms
memory: 32072kb

input:

3
1
1 1 1000000000 1000000000
3
1 1 2 2
3 3 4 4
5 5 6 6
5
581574116 47617804 999010750 826131769
223840663 366320907 613364068 926991396
267630832 51913575 488301124 223957497
217461197 492085159 999485867 913732845
28144453 603781668 912516656 993160442

output:

230616300
64
977066618

result:

ok 3 number(s): "230616300 64 977066618"

Test #2:

score: 0
Accepted
time: 15ms
memory: 32768kb

input:

1000
10
5 7 6 10
4 3 6 9
1 6 3 7
1 1 7 10
1 2 7 7
5 2 8 3
2 1 5 7
1 1 10 6
1 7 2 8
4 7 5 9
10
6 6 8 10
4 4 9 9
2 4 6 5
5 3 10 10
1 3 4 4
2 2 3 6
7 5 8 6
2 7 8 8
5 7 10 10
2 4 7 8
10
3 6 6 10
1 2 7 4
7 5 10 9
4 5 8 9
2 7 5 9
2 2 9 7
3 3 8 4
1 1 8 6
5 4 10 6
3 9 7 10
10
3 1 8 9
1 3 8 10
4 1 7 4
2 4 5 ...

output:

28090346
21067815
91293528
63203269
14045217
24579047
49158123
56180656
10533942
83
28090372
101827338
512901428
38624242
10533932
42135595
7022614
7022661
7022622
31601641
21067817
35112979
7022628
7022682
17556485
42135554
59692019
28090452
14045202
73737099
42135505
31601703
49158091
28090434
108...

result:

ok 1000 numbers

Test #3:

score: 0
Accepted
time: 19ms
memory: 32236kb

input:

1000
10
56 6 85 86
2 67 79 76
41 32 57 94
7 24 95 72
4 82 98 99
21 16 64 95
5 15 97 50
75 34 93 63
65 1 74 40
62 50 91 57
10
1 66 4 99
73 28 80 35
9 46 84 72
57 12 74 75
24 20 72 86
30 35 51 52
20 32 80 48
1 27 38 38
79 30 91 86
49 11 78 31
10
84 36 95 84
18 76 83 96
87 6 97 24
59 74 79 81
36 6 49 1...

output:

286940182
6719
3879
10985
284425706
1482
154507014
337096188
15634
15198
13957
311811545
2065
487051821
104322525
4160
6232
3566
259869863
676660625
533734216
1108
210694302
941064564
9524057
366655439
960
712817222
294969344
505637269
5277
216
807601960
6489
192
252834684
9863
523061934
1036
370
16...

result:

ok 1000 numbers

Test #4:

score: 0
Accepted
time: 22ms
memory: 32996kb

input:

1000
10
151949335 343818689 226887829 843487881
26268786 629172470 727820988 753588469
239557045 129989050 828912527 803511337
216216272 737211068 952614934 901139965
9412307 270208240 969836975 781270622
210767204 691143582 734743967 978765608
115072779 149374200 365237395 723260248
373039270 50881...

output:

989992685
889170389
199600526
811602467
101647877
422274637
988817681
775346897
987827054
201664770
0
425324155
654779513
129937888
504567840
567363794
953468940
390846625
863893486
832900735
549488122
626520957
651708706
325695215
265584217
535054615
654784437
835844534
970196650
259827660
73563096...

result:

ok 1000 numbers

Test #5:

score: 0
Accepted
time: 387ms
memory: 31656kb

input:

20000
10
387518709 362080654 857718988 413892967
259574026 383071239 349422952 406322216
252781835 421214199 960954668 766986966
709548059 152868851 829506776 286195984
533564379 238783143 835360470 804665480
37715197 439312193 350269160 510361284
760325088 379134217 996444460 640572941
75706031 242...

output:

425031005
145199488
76594243
608094392
105901554
767793557
925027675
718008576
542146803
257776847
83948409
557131094
957234323
316994452
711146361
878596101
863265391
86278462
882556696
943381219
171834801
312110039
509815322
995001589
267270543
321796762
646607323
535110629
612892338
264981338
862...

result:

ok 20000 numbers

Test #6:

score: 0
Accepted
time: 363ms
memory: 33168kb

input:

20000
9
23397362 5465077 922916650 905326448
334129892 259574026 806023297 349422952
85390000 14589070 252781835 159363469
518493829 9904109 881263301 763351170
376515120 592421912 709548059 922381128
522936 888125869 919020884 968891551
192627293 528719402 238783143 846674462
269993278 155196111 41...

output:

38446691
441652008
80634077
86958519
313123987
37147655
292453230
135822548
347213034
875178269
572593450
121333363
910761745
288628833
144542647
336001702
492148086
504465362
307137735
40715447
936972207
895075762
698856636
442121431
960601688
728799681
619152060
51416671
586371383
183976942
996194...

result:

ok 20000 numbers

Test #7:

score: 0
Accepted
time: 508ms
memory: 32424kb

input:

2000
98
441828066 355550044 980140398 758338808
139187839 379489833 732496729 915149220
6198442 7406064 811667085 671521385
634108502 54340068 750182168 712125681
51518185 164417838 414217749 690302726
26971686 349814847 96913121 613904116
18885592 344395345 969337141 761958781
6500321 288362602 695...

output:

847505316
69861689
762022665
942187496
610542723
297361682
408287130
37288980
129194998
781348133
138625309
885806848
596340815
251557403
136654463
415973838
348935020
217451841
607735223
183258123
453186006
29511771
486730947
90933161
744360742
932334149
464917933
58351031
36268611
777434481
348682...

result:

ok 2000 numbers

Test #8:

score: 0
Accepted
time: 563ms
memory: 32684kb

input:

200
993
336152525 31049117 970839548 34483370
257968529 73378100 760295564 459870661
769587893 565770848 979251259 884779692
92706327 715631888 976631772 730467480
102936760 674056008 996888200 756831534
141490448 466112222 761954523 960644829
601216664 500053814 974949771 928192751
298296452 359164...

output:

163043779
101789580
214159985
605122084
222495872
595662571
919415389
27790333
940923361
745272650
432367810
269413997
881525570
275197159
128519736
759744770
394059985
858394070
885939030
507707772
380648232
853123251
659897376
142847962
866652391
78179639
672081467
655879491
267275050
880872481
74...

result:

ok 200 numbers

Test #9:

score: 0
Accepted
time: 88ms
memory: 32096kb

input:

200
989
1 8 5 9
6 4 9 7
9 4 10 10
3 3 8 7
7 1 9 5
9 4 10 6
4 3 7 8
3 1 7 4
2 5 3 6
3 4 4 7
4 3 7 9
1 2 9 8
4 3 6 4
2 2 6 10
6 8 7 10
2 1 3 9
1 1 4 10
1 5 4 8
2 3 4 9
4 3 9 9
1 2 6 7
7 4 9 5
4 3 8 10
4 1 8 10
7 2 8 5
2 4 3 8
5 4 10 6
9 1 10 5
5 3 7 7
6 4 10 10
6 6 7 9
1 1 3 10
2 2 9 8
2 3 7 8
3 9 10 ...

output:

3
1
2
1
2
1
2
3511294
1
3511294
2
2
3511295
3
2
2
6
1
2
1
1
3
1
3511294
1
1
10533874
1
1
1
2
2
1
6
432141794
1
1
2
4
1
3511294
2
3511294
3
3
1
2
1
853749714
3
3
7022585
3511294
2
2
3
7022585
3
14045164
1
2
1
1
1
4
2
4
3511295
3
3
3511295
3511295
7022585
1
2
1
3
2
1
7022585
2
2
2
3
2
7022585
2
4
3
2
...

result:

ok 200 numbers

Test #10:

score: 0
Accepted
time: 213ms
memory: 32988kb

input:

200
993
5 48 42 78
55 33 66 92
6 5 38 34
38 34 82 48
9 76 34 86
50 39 72 44
46 54 96 82
4 13 68 24
39 25 93 56
36 53 98 86
19 10 73 24
54 27 97 84
34 21 93 76
44 7 70 89
63 73 97 98
50 24 94 35
8 30 98 67
3 15 81 67
39 9 78 24
8 65 100 98
13 5 86 33
54 67 99 84
3 2 43 4
53 51 70 86
1 61 61 90
46 78 ...

output:

1
1
2
1
2
3
2
1
2
1
1
1
1
1
2
2
1
2
2
17
1
3
1
10
1
2
2
1
1
81
15
1
170
1
4
1
2
1
1
2
1
2
1
2
1
1
4
1
2
1
2
1
1
1
1
2
3511413
1
2
1
2
2
7022597
1
2
2
2
2
2
1
1
1
1
2
1
1
2
1
1
1
1
1
1
3
2
4
1
2
3
1
6
1
1
1
2
1
1
1
1
2
10
6
5
1
1
1
1
1
1
2
10
6
2
4
3
3511332
2
2
1
1
1
4
1
2
1
2
1
5
7
6
1
1
2
1
1
1
1
...

result:

ok 200 numbers

Test #11:

score: 0
Accepted
time: 860ms
memory: 36120kb

input:

20
9956
444627993 347200064 774678572 839098978
96936514 121569633 839637347 729127099
343857875 554213034 875416430 628610537
15566043 187047055 405963021 764745923
487340755 59747358 604299543 832826844
486772462 67273090 826002755 268527861
703758831 112254125 887710074 874858855
569284980 830139...

output:

723891885
824191538
424987081
659035365
778857924
125675099
919713447
291966121
841813
399938856
822967409
178787426
958377822
295302425
835192235
569958073
114037901
814150865
893384876
929070768

result:

ok 20 numbers

Test #12:

score: 0
Accepted
time: 1316ms
memory: 61304kb

input:

2
99774
247800693 19906287 955213467 53123614
752909581 205074868 772413424 686934334
565298662 150234672 941079197 750300220
29485217 794172007 678447605 874228231
524081254 14156413 775198532 256753797
121163010 271762780 489047491 996802646
61272893 135510320 459683721 975698463
37577668 16804082...

output:

272047384
165799897

result:

ok 2 number(s): "272047384 165799897"

Test #13:

score: 0
Accepted
time: 1326ms
memory: 61652kb

input:

2
99484
80367959 446700298 316938043 713030699
180389 97354205 991264982 207371172
227833166 343626198 994287807 999074121
223486533 274166047 762438540 996451527
139307586 443291005 936748272 801084030
368603416 246191750 992851831 575339592
136221208 723918872 407787921 838545617
455487191 6275486...

output:

802453384
719182239

result:

ok 2 number(s): "802453384 719182239"

Test #14:

score: 0
Accepted
time: 1308ms
memory: 61516kb

input:

2
99702
94595645 404782179 993272416 799556541
245960576 714158438 987938798 821638563
327691314 213461603 998000552 819971477
908733781 18331290 994253841 385477664
28676928 357826789 998470667 719588896
710572487 806027973 975068392 829637377
822675537 183304736 991051351 955945560
469997956 65270...

output:

652843490
385598972

result:

ok 2 number(s): "652843490 385598972"

Test #15:

score: 0
Accepted
time: 1337ms
memory: 61044kb

input:

2
99412
198128938 38044404 520528603 69633461
296156091 253862054 879892175 422416582
113833513 497466407 912643387 778378206
852447189 420378642 973727926 802939446
34007282 574929361 774903967 607765114
349114758 378613356 379719307 996737934
263835095 266671229 866002851 601998719
429266410 68169...

output:

399712945
504439560

result:

ok 2 number(s): "399712945 504439560"

Test #16:

score: -100
Wrong Answer
time: 1449ms
memory: 53092kb

input:

2
99774
75930961 154072381 847971169 627055843
244525147 409278367 925944938 528328481
129723553 183994451 964033785 826775854
68114505 152036158 731700382 837809150
53123614 32632966 910136942 528684484
252909581 230872854 640150186 541470159
486420648 319619359 641792851 842591283
120182438 144662...

output:

500757111
669322594

result:

wrong answer 1st numbers differ - expected: '201422441', found: '500757111'