QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#410138#6178. 区间子集问题Max_s_xaM35 78ms69520kbC++176.2kb2024-05-13 16:00:222024-05-13 16:00:22

Judging History

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

  • [2024-05-13 16:00:22]
  • 评测
  • 测评结果:35
  • 用时:78ms
  • 内存:69520kb
  • [2024-05-13 16:00:22]
  • 提交

answer

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

typedef long long ll;

// #define DEBUG 1
struct IO
{
    #define MAXSIZE (1 << 20)
    #define isdigit(x) (x >= '0' && x <= '9')
    char buf[MAXSIZE], *p1, *p2;
    char pbuf[MAXSIZE], *pp;
    #if DEBUG
    #else
    IO() : p1(buf), p2(buf), pp(pbuf) {}
    ~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
    #endif
    #define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
    #define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')

    template <typename T>
    void Read(T &x)
    {
        #if DEBUG
        std::cin >> x;
        #else
        bool sign = 0; char ch = gc(); x = 0;
        for (; !isdigit(ch); ch = gc())
            if (ch == '-') sign = 1;
        for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
        if (sign) x = -x;
        #endif
    }
    void Read(char *s)
    {
        #if DEBUG
        std::cin >> s;
        #else
        char ch = gc();
        for (; blank(ch); ch = gc());
        for (; !blank(ch); ch = gc()) *s++ = ch;
        *s = 0;
        #endif
    }
    void Read(char &c) {for (c = gc(); blank(c); c = gc());}

    void Push(const char &c)
    {
        #if DEBUG
        putchar(c);
        #else
        if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
        *pp++ = c;
        #endif
    }
    template <typename T>
    void Write(T x)
    {
        if (x < 0) x = -x, Push('-');
        static T sta[35];
        int top = 0;
        do sta[top++] = x % 10, x /= 10; while (x);
        while (top) Push(sta[--top] ^ 48);
    }
    template <typename T>
    void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)

using namespace std;

const int MAXN = 2e3 + 10;

int n, lf[MAXN], rf[MAXN];
int m, b[MAXN << 1];

vector <int> e[MAXN];
int fa[MAXN];

int f[MAXN][MAXN][4], g[MAXN][MAXN][4], h[MAXN][4];

inline void Print(int u)
{
    cout << b[lf[u]] << ' ' << b[rf[u]] << '\n';
    for (auto v : e[u]) Print(v);
}

inline void Solve(int u)
{
    if (!e[u].size())
    {
        for (int i = 0; i <= 3; i++)
            f[u][i][0] = f[u][i][1] = f[u][i][2] = f[u][i][3] = b[rf[u]] - b[lf[u]];
        return;
    }
    for (auto v : e[u]) Solve(v);
    int sum = rf[e[u][0]] - lf[u];
    for (int i = 0, x = e[u][0]; i <= sum; i++)
        for (int j = 0; j < 4; j++)
        {
            h[i][j] = f[x][i][j];
            // cout << b[lf[x]] << ' ' << b[lf[u]] << '\n';
            if (j & 1) h[i][j] = max(h[i][j], f[x][i][j] + b[lf[x]] - b[lf[u]]);
            else if (i != 0) h[i][j] = max(h[i][j], f[x][i - 1][j | 1] + b[lf[x]] - b[lf[u]]);
        }
    for (int i = 0, x = e[u][0]; i <= sum; i++)
        for (int j = 0; j < 4; j++)
            f[x][i][j] = h[i][j];

    // cout << "dp " << u << "\n";
    // for (int i = 0, x = e[u][0]; i <= sum; i++, cout << "\n")
    //     for (int j = 0; j < 4; j++)
    //         cout << f[x][i][j] << ' ';
    
    
    for (int ch = 1; ch < e[u].size(); ch++)
    {
        int y = e[u][ch - 1], x = e[u][ch];
        int cur = rf[x] - rf[y];
        for (int i = 0; i <= sum + cur; i++)
            for (int j = 0; j < 4; j++)
                h[i][j] = 0;
        for (int i = 0; i <= cur; i++)
            for (int j = 0; j < 4; j++)
            {
                for (int s = 0; s <= sum; s++)
                    for (int t = 0; t < 2; t++)
                    {
                        int p1 = (j & 1) ^ (t << 1), p2 = t ^ (j & 2);
                        if (t) h[i + s + 1][j] = max(h[i + s + 1][j], f[y][i][p1] + f[x][s][p2] + b[lf[x]] - b[rf[y]]);
                        else h[i + s][j] = max(h[i + s][j], f[y][i][p1] + f[x][s][p2]);
                    }
            }
        sum += cur;
        for (int i = 0; i <= sum; i++)
            for (int j = 0; j < 4; j++)
                f[x][i][j] = h[i][j];
    }

    sum++;
    for (int i = 0, x = e[u].back(); i <= sum; i++)
        for (int j = 0; j < 4; j++)
        {
            h[i][j] = f[x][i][j];
            if (j & 2) h[i][j] = max(h[i][j], f[x][i][j] + b[rf[u]] - b[rf[x]]);
            else if (i != 0) h[i][j] = max(h[i][j], f[x][i - 1][j | 2] + b[rf[u]] - b[rf[x]]);
        }
    for (int i = 0; i <= sum; i++)
        for (int j = 0; j < 4; j++)
            f[u][i][j] = h[i + 1][j];
    for (int i = 1; i <= sum; i++)
        for (int j = 0; j < 4; j++)
            f[u][i][j] = max(f[u][i - 1][j], f[u][i][j]);

    if (f[u][0][0] > b[rf[u]] - b[lf[u]])
    {
        Print(u);
        exit(0);
    }

    // cout << "dp " << u << ' ' << lf[u] << ' ' << rf[u] << '\n';
    // for (int i = 0; i <= sum; i++, cout << '\n')
    //     for (int j = 0; j < 4; j++)
    //         cout << f[u][i][j] << ' ';
}

int main()
{
    // freopen("A.in", "r", stdin);
    // freopen("A.out", "w", stdout);
    #if DEBUG
    #else
    ios::sync_with_stdio(0), cin.tie(0);
    #endif
    Read(n);
    for (int i = 1; i <= n; i++) Read(lf[i]), Read(rf[i]), b[++m] = lf[i], b[++m] = rf[i];
    sort(b + 1, b + m + 1);
    for (int i = 1; i <= n; i++)
    {
        lf[i] = lower_bound(b + 1, b + m + 1, lf[i]) - b;
        rf[i] = lower_bound(b + 1, b + m + 1, rf[i]) - b;
    }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            if (i != j && lf[j] < lf[i] && rf[i] < rf[j])
            {
                if (!fa[i] || rf[j] - lf[j] < rf[fa[i]] - lf[fa[i]]) fa[i] = j;
            }
    
    // for (int i = 1; i <= n; i++) cout << lf[i] << ' ' << rf[i] << '\n';
    for (int i = 1; i <= n; i++) e[fa[i]].push_back(i);
    for (int i = 1; i <= n; i++)
        sort(e[i].begin(), e[i].end(), [&](int x, int y) {return lf[x] < lf[y];});

    int ans = 0;
    for (int i = 1; i <= n; i++)
        if (!fa[i]) Solve(i), ans += f[i][0][0];
    cout << ans << '\n';

    // for (int i = 1; i <= n; i++) cout << fa[i] << ' '; cout << "\n";
    // for (int i = 1; i <= n; i++, cout << '\n')
    //     for (int j = 0; j < 4; j++) cout << f[i][j] << ' ';
    return 0;
}

详细

Test #1:

score: 5
Accepted
time: 0ms
memory: 7864kb

input:

9
31 62
97 98
53 59
17 79
3 87
40 60
72 77
22 29
7 11

output:

69

result:

ok 1 number(s): "69"

Test #2:

score: 5
Accepted
time: 1ms
memory: 7776kb

input:

10
77 78
43 49
60 75
11 32
81 94
64 67
17 19
52 53
40 76
46 48

output:

57

result:

ok 1 number(s): "57"

Test #3:

score: 0
Wrong Answer
time: 2ms
memory: 9848kb

input:

69
2356 2546
7498 7527
2114 2172
2866 4692
6101 6104
2607 2662
619 949
5495 5513
8013 8166
2704 2765
306 567
1192 1292
5241 6149
7468 7556
9455 9480
1926 1965
427 542
3033 3087
2218 2234
9423 9485
6312 6584
65 2857
1165 1341
4247 4615
7068 7241
8853 8971
9049 9061
7621 7747
6920 6925
2975 3405
8874 ...

output:

219 1995
232 1054
306 567
427 542
619 949
845 882
1069 1700
1125 1392
1165 1341
1192 1292
1926 1965

result:

wrong answer 1st numbers differ - expected: '8167', found: '219'

Test #4:

score: 0
Wrong Answer
time: 0ms
memory: 13988kb

input:

226
907689292 910731765
637315418 640270766
649957861 656645930
330108609 332693231
327790388 341052210
452058987 452711364
164678004 227157125
701219833 702883478
35857149 36022443
652977298 655883456
200127263 204937919
873141333 894247545
964266670 986217229
168568045 174180280
743434879 76941787...

output:

8357407 294942788
9049264 284706061
10306286 160060282
13860157 149497374
14260265 48384925
17267762 33552024
17427103 25640165
18722459 24830826
29754306 31055097
35506900 41034626
35857149 36022443
43571801 47931775
48533133 128136186
51511865 52087211
52218276 64718205
53689264 64014530
55062418 ...

result:

wrong answer 1st numbers differ - expected: '848026569', found: '8357407'

Test #5:

score: 0
Wrong Answer
time: 2ms
memory: 24180kb

input:

476
714654653 727563662
429167515 431143191
842243203 848961893
700045985 702768740
342430157 343401134
573738448 575113786
646109543 646481599
129101080 130854863
819944089 827765544
487460829 488975983
75470140 76077173
996513423 999545857
828006214 829269130
313030891 314257417
2556612 72746358
8...

output:

750778559 763886991
751053889 757166819
751249867 754198779
751518517 754175198
751761830 754040388
757531092 758880700

result:

wrong answer 1st numbers differ - expected: '841569322', found: '750778559'

Test #6:

score: 0
Wrong Answer
time: 0ms
memory: 15964kb

input:

244
195504221 200903817
183982018 184267455
886052909 887397280
774138753 778393959
885144456 885660700
773293500 780988242
480097924 558064110
207189240 208497911
802453825 812658707
706209219 722799069
688092845 691466627
285159759 290428263
482152317 482429364
359239303 365087642
982083965 983237...

output:

900453207 915629132
900660876 914575263
901445968 913052877
902272637 910240088
903311544 908513794
914586401 915468467

result:

wrong answer 1st numbers differ - expected: '795087927', found: '900453207'

Test #7:

score: 5
Accepted
time: 2ms
memory: 9772kb

input:

61
4857 4890
2474 2581
7705 7729
2151 2212
3831 4045
675 680
6791 7772
132 1181
5859 6029
1861 1948
6183 6258
5673 5708
9728 9892
5025 5451
8361 8431
1200 2605
5033 5221
5016 5503
9102 9122
6453 6475
6286 6307
3645 3828
7285 7658
3198 3203
6692 8039
9948 9974
9136 9140
7866 7970
784 888
4761 4836
13...

output:

6957

result:

ok 1 number(s): "6957"

Test #8:

score: 5
Accepted
time: 2ms
memory: 9844kb

input:

48
4735 4834
5477 5835
3971 4180
907 1845
5552 5819
410 1872
9909 9983
1116 1449
6544 7083
1368 1433
5077 5143
122 8492
6059 6129
1481 1580
3423 3492
3918 4391
7724 7754
7174 7352
6735 6767
8592 9365
86 96
3356 3419
4441 4499
331 2433
926 1069
9453 9761
2004 2122
8523 9817
7902 8314
9834 9843
2860 3...

output:

7585

result:

ok 1 number(s): "7585"

Test #9:

score: 5
Accepted
time: 59ms
memory: 67696kb

input:

2000
999996000 999999999
999996001 999999998
999996002 999999997
999996003 999999996
999996004 999999995
999996005 999999994
999996006 999999993
999996007 999999992
999996008 999999991
999996009 999999990
999996010 999999989
999996011 999999988
999996012 999999987
999996013 999999986
999996014 99999...

output:

3998

result:

ok 1 number(s): "3998"

Test #10:

score: 5
Accepted
time: 3ms
memory: 69236kb

input:

2000
999996000 999996001
999996002 999996003
999996004 999996005
999996006 999996007
999996008 999996009
999996010 999996011
999996012 999996013
999996014 999996015
999996016 999996017
999996018 999996019
999996020 999996021
999996022 999996023
999996024 999996025
999996026 999996027
999996028 99999...

output:

2000

result:

ok 1 number(s): "2000"

Test #11:

score: 5
Accepted
time: 29ms
memory: 69260kb

input:

2000
186292029 186381429
39531755 39997885
715829714 715943849
89593082 89975740
501618789 502142452
524895573 525177152
239867002 239989666
90634704 90840196
347118449 347622111
937915910 938117133
37592276 37754952
148576316 148874708
9347683 9627715
946069019 946148305
192522660 192836061
1006072...

output:

518221954

result:

ok 1 number(s): "518221954"

Test #12:

score: 0
Wrong Answer
time: 11ms
memory: 30792kb

input:

2000
26277805 971703271
441822414 547285226
22630689 976323424
177503973 838783634
359289289 622892772
336566267 653471488
468554386 471234224
211952703 802002437
275616745 718960728
488074800 488251685
270761751 724659408
98076671 917014793
188142828 828559658
33718424 968949516
414639447 570469725...

output:

459517750 463266501
459546539 460030710
459605959 459752236
460531983 462591032
460877893 461839953
461131589 461779893
461419773 461766403
462766444 462892815

result:

wrong answer 1st numbers differ - expected: '999481159', found: '459517750'

Test #13:

score: 0
Wrong Answer
time: 16ms
memory: 30504kb

input:

2000
106612522 904126667
454199953 459183353
518266011 521309001
100152739 912058268
118630668 891166021
73939844 935218444
184402560 818639601
275980248 281176406
640956183 643120656
576495602 577327144
302302907 306330636
46420140 957275508
86493782 923649549
190816371 816086677
59971696 946574467...

output:

271187372 272912890
271222628 272898157
271405596 272490664
271432720 272273977
271676414 271890243
272565601 272621874

result:

wrong answer 1st numbers differ - expected: '999768008', found: '271187372'

Test #14:

score: 0
Wrong Answer
time: 11ms
memory: 69272kb

input:

2000
834317527 837483207
871389010 877611186
251418042 251768616
692807140 695715240
980698227 980757849
860246405 869437586
315175804 318104161
297132323 297762460
697999996 698512693
921473187 943059724
172530643 173152426
29249487 29496853
668322217 668577462
409724653 410213113
662520150 6631430...

output:

618659 47821465
1041771 8803703
1395167 4407027
2049317 3464509
2151598 2863955
2316058 2318515
2995798 3354538
3547836 4332008
4566350 5401147
4655857 5031472
5548183 6167772
5747999 5973932
8230684 8611476
8857693 38667042
8889318 31837778
8916596 13064162
9001700 10589513
9019403 10411999
9106678...

result:

wrong answer 1st numbers differ - expected: '834266055', found: '618659'

Test #15:

score: 0
Wrong Answer
time: 12ms
memory: 34676kb

input:

2000
22260436 983513300
44838411 959813215
178325390 819236924
191801218 805837790
686893042 687006983
366369393 366889609
588266579 629664794
717449062 718633671
448280421 449080467
434924925 446983549
488707390 489188828
242289139 746330221
47463138 957512142
7739035 994947857
489705763 492780357
...

output:

247448626 256741826
247515501 249694328
247550239 249129475
247611852 249082552
248282875 248992398
248493503 248679543
250666862 254995771
251059919 254495186
251080370 253129343
251446918 252319877
251533823 252210765
251789978 252080233
253534090 254042304
254999726 255994560
255051777 255958469
...

result:

wrong answer 1st numbers differ - expected: '998764362', found: '247448626'

Test #16:

score: 0
Wrong Answer
time: 17ms
memory: 67532kb

input:

2000
93109583 914905690
321520881 324064593
293243664 715774698
82783636 927527844
265688192 739625011
32757327 974206351
237459822 769556241
655287073 655726696
202305001 801303875
383923155 383928230
259669745 745121842
107036497 902898650
302132562 704877392
151976811 853539335
626692562 62765552...

output:

373121397 378494936
373185428 375295696
374747623 375117041
375321755 377776292
375352186 376594455
375479842 376473669
375511704 376416430
376617104 377740089
376754324 376864641
377168932 377713549
377458531 377494679
377792766 377822243

result:

wrong answer 1st numbers differ - expected: '999353069', found: '373121397'

Test #17:

score: 0
Wrong Answer
time: 12ms
memory: 67224kb

input:

2000
490101141 491331623
493416297 493544197
250031938 255484592
169345113 170934038
358634879 359110770
275923033 276381509
816955174 817466221
868403211 868930384
429367760 429946920
966828782 966998727
275548906 279511969
718471635 718949435
823236205 823940122
475357447 476832667
106562982 10828...

output:

783203791 784979421
783211831 784845232
783486851 784502114
783685418 784435125
783733993 783964336
784692175 784706547

result:

wrong answer 1st numbers differ - expected: '771318558', found: '783203791'

Test #18:

score: 0
Wrong Answer
time: 78ms
memory: 69520kb

input:

2000
400419022 400515434
311805468 312563722
513848101 514429488
557006776 557077877
53675155 954215429
70688309 933142221
116626359 884974190
728863542 728996879
462652370 463341088
57964317 948157377
279739587 279927638
70204877 935018658
564513118 564686325
182175743 813676272
70731735 932948734
...

output:

776453453

result:

wrong answer 1st numbers differ - expected: '999760084', found: '776453453'

Test #19:

score: 0
Wrong Answer
time: 17ms
memory: 61304kb

input:

2000
409036366 416844473
618790087 619213533
7403331 994487672
163952573 829019701
215041441 781602949
217762165 779732629
43881986 953602305
684439518 687102112
240342797 761725553
78486686 918019439
200034282 795877377
253486418 743160520
673597366 673693533
272648301 723654511
55221277 944002628
...

output:

299956165 311541747
300229071 303634450
300675442 301927520
301086691 301633795
303013407 303070968
303913548 309214398
303995974 307888208
304764882 307221088
305600277 305950891
307386225 307624618
308747818 309100711
309271373 311026960
309759427 310521837
309840737 310464909
309884598 310424706

result:

wrong answer 1st numbers differ - expected: '999494881', found: '299956165'

Test #20:

score: 0
Wrong Answer
time: 12ms
memory: 48996kb

input:

2000
301098910 301463273
172899058 822678193
303061223 304250391
455852994 457327795
342099842 351024966
353859985 360223624
80309261 916568803
100842570 899492109
62985101 937484158
183972063 807953314
665766799 665922782
379373982 379758598
145991794 855328796
653383586 691457465
436578769 4385278...

output:

263577333 267091895
263684753 266847202
263797051 265044261
263987086 264591070
264326933 264372975
265100594 265364264
265539096 265596872
265558593 265566335
265713073 266741136
266120339 266407090

result:

wrong answer 1st numbers differ - expected: '998998410', found: '263577333'