QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#410121 | #6178. 区间子集问题 | Max_s_xaM | 15 | 1186ms | 71412kb | C++17 | 5.6kb | 2024-05-13 15:05:06 | 2024-05-13 15:05:06 |
Judging History
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], tr[MAXN];
int fa[MAXN];
int fst[MAXN], lst[MAXN];
int f[MAXN][MAXN][4], g[MAXN][MAXN][4], h[MAXN][4];
inline void Solve(int u)
{
if (!e[u].size())
{
f[u][0][0] = f[u][0][1] = f[u][0][2] = f[u][0][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] + 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 pre = sum; sum += rf[x] - rf[y];
for (int i = 0; i <= sum; i++)
for (int j = 0; j < 4; j++)
{
h[i][j] = 0;
for (int s = 0; s <= pre && s <= i; s++)
for (int t = 0; t < 4; t++)
{
int p1 = (j & 1) ^ (t & 2), p2 = (t & 1) ^ (j & 2);
if (((p1 >> 1) & 1) ^ (p2 & 1)) continue;
if ((p2 & 1) && i != s) h[i][j] = max(h[i][j], f[y][s][p1] + f[x][i - s - 1][p2] + b[lf[x]] - b[rf[y]]);
else if (!(p2 & 1)) h[i][j] = max(h[i][j], f[y][s][p1] + f[x][i - s][p2]);
}
}
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] + 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];
}
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++) e[fa[i]].push_back(i);
for (int i = 1; i <= n; i++) tr[i].resize(e[i].size()), 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: 2ms
memory: 7856kb
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: 2ms
memory: 7708kb
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: 3ms
memory: 9812kb
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:
25040
result:
wrong answer 1st numbers differ - expected: '8167', found: '25040'
Test #4:
score: 0
Wrong Answer
time: 19ms
memory: 13924kb
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:
1006796698
result:
wrong answer 1st numbers differ - expected: '848026569', found: '1006796698'
Test #5:
score: 0
Wrong Answer
time: 37ms
memory: 24244kb
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:
-62738820
result:
wrong answer 1st numbers differ - expected: '841569322', found: '-62738820'
Test #6:
score: 0
Wrong Answer
time: 15ms
memory: 15976kb
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:
1899769629
result:
wrong answer 1st numbers differ - expected: '795087927', found: '1899769629'
Test #7:
score: 0
Wrong Answer
time: 2ms
memory: 9764kb
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:
6686
result:
wrong answer 1st numbers differ - expected: '6957', found: '6686'
Test #8:
score: 0
Wrong Answer
time: 0ms
memory: 9908kb
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:
11076
result:
wrong answer 1st numbers differ - expected: '7585', found: '11076'
Test #9:
score: 0
Wrong Answer
time: 38ms
memory: 69768kb
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:
2000
result:
wrong answer 1st numbers differ - expected: '3998', found: '2000'
Test #10:
score: 5
Accepted
time: 3ms
memory: 69228kb
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: 0
Time Limit Exceeded
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:
result:
Test #12:
score: 0
Wrong Answer
time: 68ms
memory: 69728kb
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:
692757808
result:
wrong answer 1st numbers differ - expected: '999481159', found: '692757808'
Test #13:
score: 0
Wrong Answer
time: 808ms
memory: 67552kb
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:
2147483585
result:
wrong answer 1st numbers differ - expected: '999768008', found: '2147483585'
Test #14:
score: 0
Wrong Answer
time: 360ms
memory: 71412kb
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:
1162430799
result:
wrong answer 1st numbers differ - expected: '834266055', found: '1162430799'
Test #15:
score: 0
Wrong Answer
time: 578ms
memory: 69572kb
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:
2147483622
result:
wrong answer 1st numbers differ - expected: '998764362', found: '2147483622'
Test #16:
score: 0
Time Limit Exceeded
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:
result:
Test #17:
score: 0
Wrong Answer
time: 20ms
memory: 69296kb
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:
-904358106
result:
wrong answer 1st numbers differ - expected: '771318558', found: '-904358106'
Test #18:
score: 0
Time Limit Exceeded
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:
result:
Test #19:
score: 0
Wrong Answer
time: 1186ms
memory: 69636kb
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:
2147483628
result:
wrong answer 1st numbers differ - expected: '999494881', found: '2147483628'
Test #20:
score: 0
Wrong Answer
time: 403ms
memory: 69508kb
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:
2147483554
result:
wrong answer 1st numbers differ - expected: '998998410', found: '2147483554'