QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#515726 | #2266. Colorful Rectangle | PlentyOfPenalty | TL | 4424ms | 16692kb | C++20 | 4.8kb | 2024-08-11 22:04:12 | 2024-08-11 22:04:13 |
Judging History
answer
#include <bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define all(x) begin(x), end(x)
#define rep(i, l, r) for (int i = (l), i##end = (r); i <= i##end; ++i)
#define per(i, l, r) for (int i = (l), i##end = (r); i >= i##end; --i)
#ifdef memset0
#define log(...) fprintf(stderr, __VA_ARGS__)
#else
#define log(...) (void(0))
#define endl '\n'
#endif
using namespace std;
using ll = long long;
using lf = long double;
using lll = __int128;
using ull = unsigned long long;
inline void updmin(int &x, int y) {
if (y < x) x = y;
}
const int N = 1e5 + 9, inf = 5e8;
int n, m, ans;
vector<int> val;
struct atom {
int x, y, ty, c, oc;
bool operator<(const atom &rhs) const {
if (x != rhs.x) return x < rhs.x;
if (c != rhs.c) return c < rhs.c;
return y < rhs.y;
}
} a[N];
struct segment {
int l, r, mid;
int x2, xy2, s12, y1;
} p[N << 2];
void maintain(int u) {
updmin(p[u].x2, min(p[u << 1].x2, p[u << 1 | 1].x2));
updmin(p[u].xy2, min(p[u << 1].xy2, p[u << 1 | 1].xy2));
updmin(p[u].s12, min(p[u << 1].s12, p[u << 1 | 1].s12));
}
void pushup(int u, int y1) {
updmin(p[u].y1, y1);
updmin(p[u].s12, y1 + p[u].x2);
}
void pushdown(int u) {
if (p[u].y1 != inf && p[u].l != p[u].r) {
pushup(u << 1, p[u].y1);
pushup(u << 1 | 1, p[u].y1);
}
p[u].y1 = inf;
}
void build(int u, int l, int r) {
p[u].l = l, p[u].r = r, p[u].mid = (l + r) >> 1;
p[u].x2 = p[u].xy2 = p[u].s12 = p[u].y1 = inf;
if (l == r) {
return;
}
build(u << 1, l, p[u].mid);
build(u << 1 | 1, p[u].mid + 1, r);
}
void modify12(int u, int k, int it) {
pushdown(u);
if (p[u].l == p[u].r) {
updmin(p[u].s12, it);
return;
}
modify12(k <= p[u].mid ? u << 1 : u << 1 | 1, k, it);
maintain(u);
}
void modify2(int u, int k, const pair<int, int> &it) {
pushdown(u);
if (p[u].l == p[u].r) {
updmin(p[u].x2, it.first);
updmin(p[u].xy2, it.second);
return;
}
modify2(k <= p[u].mid ? u << 1 : u << 1 | 1, k, it);
maintain(u);
}
void modify1(int u, int l, int r, int it) {
pushdown(u);
if (p[u].l == l && p[u].r == r) {
pushup(u, it);
return;
}
if (r <= p[u].mid) {
modify1(u << 1, l, r, it);
} else if (l > p[u].mid) {
modify1(u << 1 | 1, l, r, it);
} else {
modify1(u << 1, l, p[u].mid, it);
modify1(u << 1 | 1, p[u].mid + 1, r, it);
}
maintain(u);
}
int query2(int u, int l, int r) {
pushdown(u);
if (p[u].l == l && p[u].r == r) return p[u].xy2;
if (r <= p[u].mid) return query2(u << 1, l, r);
if (l > p[u].mid) return query2(u << 1 | 1, l, r);
return min(query2(u << 1, l, p[u].mid), query2(u << 1 | 1, p[u].mid + 1, r));
}
int query12(int u, int l, int r) {
pushdown(u);
if (p[u].l == l && p[u].r == r) return p[u].s12;
if (r <= p[u].mid) return query12(u << 1, l, r);
if (l > p[u].mid) return query12(u << 1 | 1, l, r);
return min(query12(u << 1, l, p[u].mid), query12(u << 1 | 1, p[u].mid + 1, r));
}
void solve(int x, int y, int z) {
// log("\n\n\n=== solve %d %d %d ===\n", x, y, z);
for (int i = 1; i <= n; i++) {
a[i].c = a[i].oc == x ? 0 : (a[i].oc == y ? 1 : 2);
}
sort(a + 1, a + n + 1);
build(1, 1, sz(val));
for (int i = n; i >= 1; i--) {
if (a[i].c == 2) {
// log("modify2 %d << %d %d\n", a[i].ty, a[i].x, a[i].x + a[i].y);
modify2(1, a[i].ty, make_pair(a[i].x, a[i].x + a[i].y));
} else if (a[i].c == 1) {
// log("modify12 %d >> %d\n", a[i].ty, query2(1, a[i].ty, sz(val)));
modify12(1, a[i].ty, query2(1, a[i].ty, sz(val)));
modify1(1, 1, a[i].ty, a[i].y);
} else if (a[i].c == 0) {
// log("query12 %d >> %d (- %d)\n", a[i].ty, query12(1, a[i].ty, sz(val)), a[i].x + a[i].y);
updmin(ans, query12(1, a[i].ty, sz(val)) - a[i].x - a[i].y);
}
// log("i=%d >> (%d %d %d) >> ans=%d\n", i, a[i].x, a[i].y, a[i].c, ans);
// assert(ans > 0);
}
}
int main() {
#ifdef memset0
// freopen("D.in", "r", stdin);
freopen("data.txt", "r", stdin);
#endif
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].x >> a[i].y >> a[i].oc;
}
ans = inf;
for (int t = 0; t < 4; t++) {
for (int r = 0; r < 4; r++) {
val.clear();
for (int i = 1; i <= n; i++) {
val.push_back(a[i].y);
}
sort(all(val));
val.erase(unique(all(val)), val.end());
for (int i = 1; i <= n; i++) {
a[i].ty = lower_bound(all(val), a[i].y) - val.begin() + 1;
}
solve(0, 1, 2);
solve(0, 2, 1);
solve(1, 0, 2);
solve(1, 2, 0);
solve(2, 0, 1);
solve(2, 1, 0);
for (int i = 1; i <= n; i++) {
swap(a[i].x, a[i].y), a[i].y *= -1;
}
}
for (int i = 1; i <= n; i++) {
a[i].y *= -1;
}
}
cout << (ans << 1) << endl;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5716kb
input:
10 9991473 83825681 1 26476526 51616963 1 50765942 43355004 0 53028333 5604344 2 57100206 5782798 0 80628150 92688632 2 82964896 73929713 2 85102330 11439534 1 86076990 82286008 0 89626190 52420216 0
output:
75818374
result:
ok single line: '75818374'
Test #2:
score: 0
Accepted
time: 4ms
memory: 5656kb
input:
150 90758267 21234402 1 21737107 45944411 2 71064827 33646685 1 15732041 80099984 2 59366384 89336101 1 23463874 1772178 1 63300491 91439944 2 55016570 76385018 2 68263153 41801574 2 87098378 47936087 1 52162678 88263752 2 33679612 20590713 2 75242487 92720661 1 1669174 61465572 2 99532428 10613104 ...
output:
29171440
result:
ok single line: '29171440'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5772kb
input:
10 4093976 78512657 0 27609174 62042588 1 31354091 61870386 0 35151441 36807411 1 37547440 25518220 0 44055162 7821981 2 66673981 41182270 0 83484785 58963611 1 83713705 24676214 2 88603397 80197017 0
output:
75778302
result:
ok single line: '75778302'
Test #4:
score: 0
Accepted
time: 406ms
memory: 8704kb
input:
10000 12096 65562074 1 14562 60486739 1 20187 50242814 1 35859 51060918 0 50463 52231435 1 56216 44100657 2 68431 98864745 1 73973 62323865 1 74745 22912751 2 100382 29322594 2 106833 31933585 2 123956 66437573 2 124095 72164704 2 130151 80006173 1 149897 26940530 1 150544 42049736 2 154249 83266583...
output:
476190
result:
ok single line: '476190'
Test #5:
score: 0
Accepted
time: 14ms
memory: 5780kb
input:
600 46864911 65058066 1 43812689 67844083 1 47624523 65356242 1 65763113 65439718 2 66870643 65931362 0 100000000 43232094 2 99773659 8651677 1 66502329 65775578 0 67130062 61467562 2 41297284 85249873 0 45570122 61586875 1 68626502 64903738 2 44727214 64595373 1 69383055 64974526 2 50960869 6495575...
output:
29384768
result:
ok single line: '29384768'
Test #6:
score: 0
Accepted
time: 407ms
memory: 8188kb
input:
10000 2177 6599212 0 3313 13493229 1 8624 80455572 2 10635 33135945 0 13266 17210177 0 21252 67913127 0 25630 44096615 0 26868 61301695 0 35959 34225877 2 40034 86139028 1 49019 16335976 0 56879 37023369 1 58406 27475381 2 65029 74490416 1 76280 94487503 0 78480 69430131 0 79030 23340728 0 79320 803...
output:
529732
result:
ok single line: '529732'
Test #7:
score: 0
Accepted
time: 2371ms
memory: 11816kb
input:
60000 56904392 34119842 0 56860702 34345199 0 56863596 34223670 0 56833507 34167094 0 69029799 88014623 1 56701555 34308096 0 56818682 34376693 0 56834926 34330417 0 56949550 34257853 0 56684748 34297211 0 56900683 34127043 0 69073935 88044683 1 57002769 34170885 0 56645259 34209545 0 56949514 34101...
output:
214547970
result:
ok single line: '214547970'
Test #8:
score: 0
Accepted
time: 405ms
memory: 8160kb
input:
10000 5943 40201737 0 14879 96360008 1 84275 93764821 1 88316 65975310 2 92537 83169863 2 120913 54444955 1 122906 99179164 2 129216 52068348 1 138852 89877942 2 141123 97415909 1 155989 59760984 2 169805 6529653 2 170898 51961777 2 189693 18175483 1 198839 91060856 0 200187 19004619 0 207702 916481...
output:
392858
result:
ok single line: '392858'
Test #9:
score: 0
Accepted
time: 4216ms
memory: 16676kb
input:
99999 65554710 12155679 0 78502621 86698549 1 66034198 11853186 0 78908439 86997239 1 75690302 59078887 2 75917845 58838788 2 78706695 87224574 1 75278920 59317406 2 75811752 58764827 2 65449462 11911322 0 79138515 86744879 1 65343865 11801595 0 65831220 12681966 0 78208917 86344984 1 78233596 86692...
output:
167810038
result:
ok single line: '167810038'
Test #10:
score: 0
Accepted
time: 408ms
memory: 6716kb
input:
10000 16453 91339702 2 17091 38182701 1 20936 29620225 2 47682 28151688 0 63221 76101571 0 65233 11392954 2 66284 74135634 2 86624 70956583 1 108068 98693936 1 114014 84167404 1 114265 18545899 1 120274 72079572 1 120373 96300499 2 123059 39784349 2 157658 37801703 0 170521 81004158 1 176351 5250039...
output:
352820
result:
ok single line: '352820'
Test #11:
score: 0
Accepted
time: 3962ms
memory: 16692kb
input:
100000 36557383 100000000 1 53846533 5947338 0 24566151 89955356 2 23273552 91215468 2 36969432 98598695 1 26107898 89329321 2 53542808 6884678 0 37879687 99187185 1 52969807 5797175 0 53372131 4763020 0 36301035 100000000 1 53325023 6481729 0 37569840 100000000 1 24536890 89611841 2 24005966 893013...
output:
219386438
result:
ok single line: '219386438'
Test #12:
score: 0
Accepted
time: 406ms
memory: 6636kb
input:
10000 913 71695869 0 44727 80986550 2 53187 92127111 2 76157 87371194 1 80315 95062820 2 87064 48749409 1 87394 92128884 1 112372 46500690 2 120966 66525629 0 125652 92792157 1 136750 86862566 1 143481 96898726 2 151343 34996186 0 159085 62728567 2 164963 39895589 0 174996 82892797 2 184024 52133875...
output:
431976
result:
ok single line: '431976'
Test #13:
score: 0
Accepted
time: 4292ms
memory: 14584kb
input:
97932 52284988 92138589 2 29206507 82522141 1 52909858 87999226 2 45692188 80211744 1 35493727 86238397 1 34822632 93781153 2 40346454 81255316 1 49468709 92105158 2 31027254 82650917 1 97094988 41517207 0 27125320 68205834 1 56699871 91310811 2 90235937 15919826 0 35696832 76242003 1 47376311 94592...
output:
60926458
result:
ok single line: '60926458'
Test #14:
score: 0
Accepted
time: 403ms
memory: 8520kb
input:
10000 4121 45276640 2 35568 51336364 0 47620 84075629 1 63330 76418369 0 63958 45357799 1 79664 74393497 0 88739 8368773 1 98705 64915375 0 100114 16259520 1 108749 92262958 0 116309 59859481 0 125921 4595658 2 131545 17676231 2 146925 83052695 0 154543 16882767 1 166321 43160274 0 174342 3499817 0 ...
output:
506892
result:
ok single line: '506892'
Test #15:
score: 0
Accepted
time: 4424ms
memory: 14704kb
input:
100000 39798904 68828678 2 56937242 58014952 0 56758306 57451114 0 38746499 51964627 2 56532042 58143844 0 52939689 63344810 2 45049586 65171055 2 20057743 3432569 1 51529728 57602014 0 62773199 68566788 2 51377179 65794879 2 34174168 63457598 2 52814256 69625370 2 58610225 67089086 2 56575100 58165...
output:
34188812
result:
ok single line: '34188812'
Test #16:
score: 0
Accepted
time: 407ms
memory: 6704kb
input:
10000 5737 37220377 0 5803 36404658 2 9249 6747714 2 25732 55571376 1 61246 30922073 0 61836 42608265 1 81477 70348885 0 107589 8738354 0 111307 8040637 2 143560 54882437 2 152517 76825039 2 176017 43369316 0 180092 87823847 0 184947 94495058 0 197882 37492026 0 217517 77700615 2 222701 67543247 1 2...
output:
181554
result:
ok single line: '181554'
Test #17:
score: 0
Accepted
time: 1650ms
memory: 14564kb
input:
100000 17622444 8000033 0 30835380 8000033 1 52663741 8000033 0 70031205 8000033 0 54407389 8000033 2 82444091 8000033 1 79610268 8000033 1 53930150 8000033 0 28541791 8000033 2 43252170 8000033 2 53546829 8000033 2 3516948 8000033 0 51935542 8000033 1 55023622 8000033 0 65885269 8000033 2 89745547 ...
output:
40
result:
ok single line: '40'
Test #18:
score: 0
Accepted
time: 403ms
memory: 7820kb
input:
10000 797 75327956 0 1739 7223559 1 9535 32305593 0 11449 21913826 0 37076 67597268 1 44781 99118529 2 46837 19559579 1 53721 80491438 1 58502 76311712 0 62494 46799879 0 66912 46495165 2 72642 37596193 0 95419 70508156 0 98774 68665733 0 99049 63085873 1 100851 60379638 1 102269 54262558 0 124039 4...
output:
234328
result:
ok single line: '234328'
Test #19:
score: 0
Accepted
time: 1409ms
memory: 14552kb
input:
89999 205666 94455220 1 205666 35678917 2 205666 52256947 2 205666 68754269 1 205666 94005 1 205666 2422108 2 205666 2285892 1 205666 5400544 2 205666 589131 1 205666 11052855 1 205666 58854275 1 205666 49541641 1 205666 9344081 1 205666 72847030 1 205666 88462926 2 205666 18405168 1 205666 37641873...
output:
570
result:
ok single line: '570'
Test #20:
score: 0
Accepted
time: 406ms
memory: 6708kb
input:
10000 16418 25742119 1 19362 72835924 0 25814 55273402 2 28354 16503772 1 35674 73165022 1 44784 1087463 2 47601 12411624 1 50648 33151245 1 65567 31969157 2 90135 58551022 1 93667 66249435 0 94800 81757923 2 95687 96403513 1 111285 5434122 0 122743 49787251 0 124178 24380367 2 127104 33015480 1 138...
output:
314578
result:
ok single line: '314578'
Test #21:
score: 0
Accepted
time: 1602ms
memory: 14624kb
input:
99988 81658596 9857678 1 12901691 9857678 1 51330473 9857678 1 69758723 9857678 1 24863994 9857678 1 24647238 9857678 1 93743 9857678 1 23646126 9857678 1 62838732 9857678 1 87093702 9857678 1 66500611 9857678 1 55552900 9857678 1 69339800 9857678 1 11982991 9857678 1 88136181 9857678 1 58652443 985...
output:
33234210
result:
ok single line: '33234210'
Test #22:
score: 0
Accepted
time: 400ms
memory: 8336kb
input:
10000 12463 53976273 2 16752 44666915 2 35486 22942117 1 69285 10937347 1 90198 70512938 2 107835 17626469 0 110490 89422081 0 114230 76613764 0 116715 91852815 2 127212 33004689 1 129849 65884262 0 155831 3625748 0 197899 45439813 0 202844 90370232 0 221100 20227427 2 225410 86047873 0 243668 50293...
output:
471262
result:
ok single line: '471262'
Test #23:
score: 0
Accepted
time: 1588ms
memory: 14652kb
input:
99000 3867278 6211390 0 3867278 7438194 0 3867278 61921807 0 3867278 64187547 0 3867278 3901333 0 3867278 85260412 0 3867278 90217021 0 3867278 33963707 0 3867278 76240668 0 3867278 9992815 0 3867278 70544690 0 3867278 8775049 0 3867278 59639602 0 3867278 80040055 0 3867278 88397701 0 3867278 686650...
output:
88145142
result:
ok single line: '88145142'
Test #24:
score: -100
Time Limit Exceeded
input:
100000 18889746 80825892 2 94088814 62055130 2 79603215 44900699 2 42896677 38430658 1 49282970 53290837 2 22790858 33522808 2 1308532 63910843 1 12517633 69091444 1 3548743 90642550 2 48276428 28094103 2 40019210 39413695 2 55101430 23501911 1 27540387 29927920 1 52831306 75094677 1 65765384 273908...