QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#468687#2853. Paint by RectanglesLR100 ✓3587ms47976kbC++205.7kb2024-07-08 22:52:082024-07-08 22:52:09

Judging History

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

  • [2024-07-08 22:52:09]
  • 评测
  • 测评结果:100
  • 用时:3587ms
  • 内存:47976kb
  • [2024-07-08 22:52:08]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define ii pair<int,int>
#define ff first
#define ss second

using namespace std;
const int maxn = 2e5 + 5;
int n, m, t, cnt, timer;
int lz[maxn * 4];
tuple<int,int,int> events[maxn];
ii asn[4 * maxn];
int _t;
struct node{
    array<int, 2> col;
    int l, r;
    node(int val = 0)
    {
        l = r = val;
        col = {0, 0};
        if (val >= 0) col[val]++;
    }
    void rev()
    {
        l ^= 1; r ^= 1;
        swap(col[0], col[1]);
    }
};

node nothing(-1), seg[4 * maxn];;

bool check(node &a, node &b)
{
    return a.col == b.col && a.l == b.l && a.r == b.r;
}

node operator + (node a, node b)
{
    if (check(a, nothing)) return b;
    if (check(b, nothing)) return a;
    node c;
    c.l = a.l; c.r = b.r;
    c.col[0] = a.col[0] + b.col[0];
    c.col[1] = a.col[1] + b.col[1];
    if (a.r == b.l) c.col[a.r]--;
    return c;
}

void rev(int id)
{
    seg[id].rev();
    (lz[id] += 1) %= 2;
}

void down(int id)
{
    if (lz[id] == 0) return;
    rev(id * 2);
    rev(id * 2 + 1);
    lz[id] = 0;
}

void upd_rev(int lx, int rx, int id = 1, int l = 1, int r = n)
{
    if (lx > r || l > rx) return;
    if (lx <= l && r <= rx) return rev(id);
    down(id);
    int mid = (l + r) / 2;
    upd_rev(lx, rx, id * 2, l, mid);
    upd_rev(lx, rx, id * 2 + 1, mid + 1, r);
    seg[id] = seg[id * 2] + seg[id * 2 + 1];
}

node qry(int lx, int rx, int id = 1, int l = 1, int r = n)
{
    if (lx > r || l > rx) return nothing;
    if (lx <= l && r <= rx) return seg[id];
    int mid = (l + r) / 2;
    down(id);
    return qry(lx, rx, id * 2, l, mid) + qry(lx, rx, id * 2 + 1, mid + 1, r);
}

void upd_asn(int lx, int rx, ii val, int id, int l, int r)
{
    if (lx > r || l > rx) return;
    if (lx <= l && r <= rx)
    {
        asn[id] = val;
        return;
    }
    int mid = (l + r) / 2;
    upd_asn(lx, rx, val, id * 2, l, mid);
    upd_asn(lx, rx, val, id * 2 + 1, mid + 1, r);
}

ii getid(int pos, int id, int l, int r)
{
    if (l == r) return asn[id];
    int mid = (l + r) / 2;
    if (pos <= mid) return max(asn[id], getid(pos, id * 2, l, mid));
    return max(asn[id], getid(pos, id * 2 + 1, mid + 1, r));
}

int getid(int pos)
{
    return getid(pos, 1, 1, n).ss;
}

void upd_asn(int l, int r, int val)
{
    upd_asn(l, r, {++timer, val}, 1, 1, n);
}

int getl(int l, int r)
{
    int lx = l, rx = r, ans;
    while (lx <= rx)
    {
        int mid = (lx + rx) / 2;
        auto tmp = qry(l, mid);
        if (min(tmp.col[0], tmp.col[1]) == 0)
            ans = mid, lx = mid + 1;
        else rx = mid - 1;
    }
    return ans;
}

int getr(int l, int r)
{
    int lx = l, rx = r, ans;
    while (lx <= rx)
    {
        int mid = (lx + rx) / 2;
        auto tmp = qry(mid, r);
        if (min(tmp.col[0], tmp.col[1]) == 0)
            ans = mid, rx = mid - 1;
        else lx = mid + 1;
    }
    return ans;
}

void build(int id = 1, int l = 1, int r = n)
{
    if (l == r) {
        seg[id] = node(0);
        return;
    }
    int mid = (l + r) / 2;
    build(id * 2, l, mid);
    build(id * 2 + 1, mid + 1, r);
    seg[id] = seg[id * 2] + seg[id * 2 + 1];
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//    freopen("test.inp", "r", stdin);
//    freopen("test.out", "w", stdout);
    cin >> n >> t;
    for (int i = 1; i <= n; i++)
    {
        int u, v, x, y;
        cin >> u >> v >> x >> y;
        y--;
        events[u] = {v, y, 0};
        events[x] = {v, y, 1};
    }
    n *= 2;
    array<int, 2> ans = {0, 0};
    for (int i = 1; i <= n; i++)
    {
        _t = -1;
        auto [l, r, oc] = events[i];
        if (oc == 0)
        {
            upd_rev(l, r);
            auto tmp = qry(l, r);
            ans[0] += tmp.col[0];
            ans[1] += tmp.col[1];
            int u = getl(l, r);
            int v = getr(l, r);
            upd_asn(l, u, ++cnt);
            upd_asn(v, r, ++cnt);
        }
        else
        {
            upd_rev(l, r);
            auto tmp = qry(l, r);
            ans[0] += tmp.col[0];
            ans[1] += tmp.col[1];
            int u = getl(l, r), v = getr(l, r);
            upd_asn(l, u, ++cnt);
            upd_asn(v, r, ++cnt);
            if (min(tmp.col[0], tmp.col[1]) == 0)
            {
                int c = tmp.l;
                if (l > 1 && r < n && getid(l - 1) == getid(r + 1))
                {
                    ans[c]--;
                    upd_asn(l, r, getid(l - 1));
                }
                else
                {
                    int L = -1;
                    if (l > 1) L = getid(l - 1);
                    if (l > 1)
                    {
                        int v = getr(1, l - 1);
                        upd_asn(v, r, L);
                        ans[c]--;
                    }
                    if (r < n)
                    {
                        int v = getl(r + 1, n);
                        if (L != -1) upd_asn(l, v, L);
                        else upd_asn(l, v, getid(r + 1));
                        ans[c]--;
                    }
                }
            } else
            {
                if (l > 1)
                {
                    ans[tmp.l]--;
                    upd_asn(l, getl(l, r), getid(l - 1));
                }
                if (r < n)
                {
                    ans[tmp.r]--;
                    upd_asn(getr(l, r), r, getid(r + 1));
                }
            }
        }
    }
    if (t == 1) cout << ans[0] + ans[1] + 1;
    else cout << ans[0] + 1 << " " << ans[1];
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 4.34783
Accepted
time: 0ms
memory: 32372kb

input:

2 1
1 1 3 3
2 2 4 4

output:

4

result:

ok single line: '4'

Test #2:

score: 4.34783
Accepted
time: 3575ms
memory: 47836kb

input:

100000 1
26985 73088 172951 126943
32480 67597 167520 132400
83611 16456 116373 183588
16220 83844 183781 116158
1505 98499 198501 101509
89365 10653 110626 189330
32669 67416 167334 132591
4882 95107 195114 104876
44940 55123 155060 144906
15707 84359 184308 115638
28653 71405 171303 128609
57912 4...

output:

19074899358

result:

ok single line: '19074899358'

Test #3:

score: 4.34783
Accepted
time: 3552ms
memory: 47892kb

input:

100000 2
28806 71262 171163 128784
34129 65917 165857 134103
84029 16038 115960 183972
18288 81765 181690 118260
3971 96032 196038 103961
89634 10405 110360 189569
34316 65741 165679 134278
7261 92741 192738 107257
46269 53782 153687 146262
17786 82269 182196 117749
30432 69659 169546 130391
58917 4...

output:

9691724059 9691723449

result:

ok single line: '9691724059 9691723449'

Test #4:

score: 4.34783
Accepted
time: 3526ms
memory: 47900kb

input:

100000 2
29257 70796 170746 129247
34551 65488 165457 134535
84140 15950 115862 184070
18812 81237 181182 118786
4579 95418 195418 104582
89702 10349 110301 189641
34727 65313 165275 134717
7854 92147 192153 107855
46621 53438 153371 146616
18296 81734 181688 118285
30880 69197 169136 130845
59198 4...

output:

9731424888 9731425560

result:

ok single line: '9731424888 9731425560'

Test #5:

score: 4.34783
Accepted
time: 3500ms
memory: 47844kb

input:

100000 2
30203 69818 169793 130205
35439 64584 164560 135443
84366 15702 115657 184300
19893 80125 180102 119898
5877 94133 194134 105871
89853 10180 110168 189787
35618 64405 164386 135617
9112 90902 190922 109098
47344 52650 152638 147352
19402 80619 180602 119397
31793 68225 168211 131784
59752 4...

output:

9818976201 9818979527

result:

ok single line: '9818976201 9818979527'

Test #6:

score: 4.34783
Accepted
time: 2498ms
memory: 47820kb

input:

100000 1
99526 108390 117785 108923
165829 163074 172485 175230
123418 122371 131782 132833
39744 48254 57647 49141
143116 147662 157047 152513
179010 179010 179015 179015
46089 41904 51297 55494
179473 179473 179474 179474
81836 83502 92888 91255
189142 181367 190769 198536
39717 48281 57675 49114
...

output:

1711403287

result:

ok single line: '1711403287'

Test #7:

score: 4.34783
Accepted
time: 2494ms
memory: 47848kb

input:

100000 1
79858 75140 83776 88491
130063 135238 143874 138707
170883 164637 173255 179530
6845 2290 14772 14078
57124 61511 70148 65767
116160 114293 122914 124814
37505 44424 53061 46140
150078 150167 158801 158659
7381 1814 10444 15991
43269 38664 47300 51899
118228 112235 120865 126864
19714 26982...

output:

1573991960

result:

ok single line: '1573991960'

Test #8:

score: 4.34783
Accepted
time: 2416ms
memory: 45872kb

input:

100000 1
106304 97230 106381 115451
166143 164184 173337 175285
149656 140689 149840 158805
87558 78499 87647 96706
25110 24262 33430 34275
59561 68130 77276 68711
86227 79826 88985 95356
44953 42926 52059 54127
180464 189162 198308 189612
101771 101764 110916 110946
60548 67138 76281 69706
23211 27...

output:

1612814739

result:

ok single line: '1612814739'

Test #9:

score: 4.34783
Accepted
time: 2530ms
memory: 47896kb

input:

100000 1
66857 65281 74917 76453
66851 65288 74924 76447
167548 159951 169566 177162
6881 3126 12740 16487
62880 69260 78889 72500
84714 86067 95676 94327
88383 82387 91991 98008
166253 161245 170857 175869
146012 141609 151218 155644
105405 103858 113459 114999
168374 159125 168743 177992
147356 14...

output:

1799010175

result:

ok single line: '1799010175'

Test #10:

score: 4.34783
Accepted
time: 2463ms
memory: 47976kb

input:

100000 1
118129 126625 135952 127449
1300 9305 18616 10609
157384 157384 157385 157385
27232 24081 33405 36551
64730 63642 72967 74056
187687 180913 190243 196988
81933 84274 93601 91261
2875 7720 17044 12182
167913 160702 175018 176804
47930 42143 51482 57247
138182 147416 156735 147501
145618 1399...

output:

1674191591

result:

ok single line: '1674191591'

Test #11:

score: 4.34783
Accepted
time: 2478ms
memory: 47832kb

input:

100000 2
84438 89081 98475 93795
102645 109209 118573 112013
122113 127536 136921 131474
108509 103344 112706 117889
65371 65928 75292 74752
67342 63948 73310 76713
106896 104959 114316 116269
22735 24514 33892 32095
102717 109136 118501 112086
168109 169656 174244 178073
142750 148608 157969 152118...

output:

851761401 851761678

result:

ok single line: '851761401 851761678'

Test #12:

score: 4.34783
Accepted
time: 0ms
memory: 32280kb

input:

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

output:

4 5

result:

ok single line: '4 5'

Test #13:

score: 4.34783
Accepted
time: 2443ms
memory: 47840kb

input:

100000 2
63560 58988 67495 72039
109892 118296 126794 118388
27250 25656 34144 35731
187930 186425 194919 196397
11358 3147 11644 19853
26230 26676 35172 34706
5022 9489 17985 13519
26655 26254 34744 35137
99328 92699 101192 107826
47530 39882 48394 56026
171613 173672 175428 177081
111016 117175 12...

output:

774247407 774248923

result:

ok single line: '774247407 774248923'

Test #14:

score: 4.34783
Accepted
time: 2395ms
memory: 47840kb

input:

100000 2
169491 175152 182894 177233
73680 69526 77280 81406
90639 90108 97854 98386
139600 137989 145724 147345
71470 71748 79497 79198
125110 120959 128710 132854
105363 109502 117218 113115
90370 90377 98123 98117
188623 188084 195823 196354
184820 191882 199623 192562
90217 90531 98277 97964
715...

output:

697368262 697372029

result:

ok single line: '697368262 697372029'

Test #15:

score: 4.34783
Accepted
time: 2446ms
memory: 47904kb

input:

100000 2
62439 66997 76295 71721
182958 188403 197679 192230
183557 187803 197080 192831
28842 22127 31400 38109
181352 190002 199281 190629
129253 123247 132522 138529
1195 8779 18067 10471
81401 85727 95020 90659
24937 26018 35306 34213
88031 79094 88373 97313
163913 168023 177303 173193
81957 851...

output:

842094175 842094586

result:

ok single line: '842094175 842094586'

Test #16:

score: 4.34783
Accepted
time: 2491ms
memory: 47836kb

input:

100000 2
102133 106574 114605 110149
105949 102770 110794 113955
106445 101015 114691 114524
36287 38458 46474 44308
68580 73163 81190 76611
120317 121080 129108 128333
52114 54827 62845 60130
122133 119245 127253 130148
83672 91160 99167 91695
104903 103816 111826 112910
74754 67006 75019 82772
852...

output:

740580852 740582021

result:

ok single line: '740580852 740582021'

Test #17:

score: 4.34783
Accepted
time: 10ms
memory: 31420kb

input:

1000 2
58 77 153 134
1685 1754 1832 1763
1074 1037 1115 1153
412 363 442 488
1 1 4 4
230 232 310 307
206 255 333 284
1030 1083 1161 1108
235 227 305 312
1920 1845 1923 1998
1195 1232 1309 1273
56 79 155 132
543 558 636 620
1407 1344 1422 1485
256 206 283 333
208 253 331 286
923 866 944 1001
1694 174...

output:

70036 70011

result:

ok single line: '70036 70011'

Test #18:

score: 4.34783
Accepted
time: 8ms
memory: 30996kb

input:

1000 2
1339 1300 1390 1429
1720 1651 1740 1808
395 425 515 485
938 970 1061 1029
252 209 298 344
589 595 685 677
1113 1163 1254 1203
1547 1460 1550 1637
618 567 657 707
274 200 302 315
958 947 1041 1049
939 969 1060 1030
1137 1139 1230 1227
1488 1519 1610 1577
1108 1169 1259 1197
758 787 878 845
190...

output:

84631 84729

result:

ok single line: '84631 84729'

Test #19:

score: 4.34783
Accepted
time: 2239ms
memory: 45748kb

input:

100000 2
53867 53911 149440 53912
31315 31286 31316 31287
103232 103309 103365 103442
137214 137291 137215 137292
197713 197712 197714 197713
61238 61292 142635 142689
22457 22484 178574 178601
81398 81462 81399 81463
33016 32998 168685 168667
39766 39790 39767 39791
59888 59939 143799 143850
60698 ...

output:

50031 49970

result:

ok single line: '50031 49970'

Test #20:

score: 4.34783
Accepted
time: 2217ms
memory: 47960kb

input:

100000 2
53971 53913 149810 149752
31522 31425 31523 170988
103348 103416 103663 103731
137078 136990 137095 137007
197450 197448 197451 197449
61362 61274 142933 142845
22587 22543 22588 179156
81577 81583 81580 124100
33237 33132 33244 33139
39986 39873 163213 163100
59999 59932 60000 144081
60819...

output:

49970 50031

result:

ok single line: '49970 50031'

Test #21:

score: 4.34783
Accepted
time: 2232ms
memory: 47840kb

input:

100000 2
53728 53921 149557 149750
31274 31383 31277 170578
103108 103445 103455 103792
136944 137165 136945 137166
197560 197550 197565 197555
61064 61266 142555 142757
22432 22481 22433 178954
81249 81534 123800 124085
32968 33102 168873 169007
39767 39885 162836 162954
59707 59937 143792 59938
60...

output:

50041 49960

result:

ok single line: '50041 49960'

Test #22:

score: 4.34783
Accepted
time: 3587ms
memory: 47840kb

input:

100000 1
27525 72551 172437 127481
32974 67115 167041 132901
83736 16333 116242 183694
16836 83222 183184 116767
2214 97773 197783 102226
89450 10576 110547 189386
33149 66930 166863 133082
5575 94412 194401 105563
45331 54738 154664 145302
16320 83746 183697 116245
29168 70897 170796 129125
58193 4...

output:

19162906764

result:

ok single line: '19162906764'

Test #23:

score: 4.34783
Accepted
time: 3534ms
memory: 47920kb

input:

100000 1
28394 71690 171582 128380
33755 66308 166244 133718
83935 16133 116064 183890
17817 82246 182172 117782
3403 96596 196611 103407
89573 10457 110424 189517
33933 66130 166068 133900
6719 93285 193286 106717
45963 54091 154015 145962
17311 82756 182685 117270
30024 70061 169951 129993
58679 4...

output:

19311455516

result:

ok single line: '19311455516'