QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#197496#2266. Colorful RectangleGalexWA 925ms21824kbC++233.2kb2023-10-02 16:31:282023-10-02 16:31:29

Judging History

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

  • [2023-10-02 16:31:29]
  • 评测
  • 测评结果:WA
  • 用时:925ms
  • 内存:21824kb
  • [2023-10-02 16:31:28]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;

int read() {
	int s = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9')
		f = (ch == '-' ? -1 : 1), ch = getchar();
	while (ch >= '0' && ch <= '9')
		s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
	return s * f;
}

int n;
int lsh[100005], tot = 0;
int od[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, {1, 2, 0}, {2, 0, 1}, {2, 1, 0}};

struct Node {
	int x, y, c;
	friend bool operator < (const Node &x, const Node &y) {return x.x < y.x || (x.x == y.x && x.c < y.c);}
} a[100005], b[100005];

#define lb(x) (x & (-x))

struct BIT {
	int mx[100005];
	BIT() {memset(mx, ~0x3f, sizeof mx);}
	void mdf(int x, int v) {
		while (x <= tot)
			mx[x] = max(mx[x], v), x += lb(x);
	}
	int qry(int x) {
		int res = -1e18;
		while (x)
			res = max(res, mx[x]), x -= lb(x);
		return res;
	}
} t1, t2;

struct SGT {
	#define ls (p << 1)
	#define rs (p << 1 | 1)
	#define mid ((l + r) >> 1)
	int ans[400005], lmx[400005], rmn[400005];
	void init() {
		memset(ans, 0x3f, sizeof ans);
		memset(lmx, ~0x3f, sizeof lmx);
		memset(rmn, 0x3f, sizeof rmn);
	}
	void pushtag(int p, int lx, int rn) {
		ans[p] = min(ans[p], rn - lmx[p]);
		rmn[p] = min(rmn[p], rn), lmx[p] = max(lmx[p], lx);
	}
	void pushdown(int p) {
		pushtag(ls, lmx[p], rmn[p]), pushtag(rs, lmx[p], rmn[p]);
		lmx[p] = -1e18, rmn[p] = 1e18;
	}
	void mdf(int l, int r, int p, int x, int y, int vl, int vr) {
		if (r < x || y < l)
			return ;
		if (x <= l && r <= y) {
			pushtag(p, vl, vr);
			return ;
		}
		pushdown(p);
		mdf(l, mid, ls, x, y, vl, vr), mdf(mid + 1, r, rs, x, y, vl, vr);
	}
	int qry(int l, int r, int p, int x) {
		if (l == r)
			return ans[p];
		pushdown(p);
		int res = x <= mid ? qry(l, mid, ls, x) : qry(mid + 1, r, rs, x);
		return min(res, ans[p]);
	}
} t;

int ans = 1e18;

void solve() {
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; i++)
		lsh[i] = a[i].y;
	sort(lsh + 1, lsh + n + 1);
	tot = unique(lsh + 1, lsh + n + 1) - lsh - 1;
	for (int i = 1; i <= n; i++)
		a[i].y = lower_bound(lsh + 1, lsh + tot + 1, a[i].y) - lsh;
	t1 = BIT(), t2 = BIT();
	for (int i = 1; i <= n; i++) {
		if (a[i].c == 0)
			t1.mdf(a[i].y, a[i].x + lsh[a[i].y]);
		else if (a[i].c == 1)
			t2.mdf(a[i].y, t1.qry(a[i].y));
		else
			ans = min(ans, a[i].x + lsh[a[i].y] - t2.qry(a[i].y));
	}
	t.init();
	for (int i = 1; i <= n; i++) {
		if (a[i].c == 0)
			t.mdf(1, tot, 1, a[i].y, tot, a[i].x + lsh[a[i].y], 1e18);
		else if (a[i].c == 1)
			t.mdf(1, tot, 1, 1, a[i].y, -1e18, lsh[a[i].y]);
		else
			ans = min(ans, a[i].x + t.qry(1, tot, 1, a[i].y));
	}
}

signed main() {
	n = read();
	for (int i = 1; i <= n; i++)
		a[i].x = read(), a[i].y = read(), a[i].c = read(), b[i] = a[i];
	for (int o = 0; o < 6; o++) {
		for (int i = 1; i <= n; i++)
			a[i] = b[i], a[i].c = od[o][b[i].c];
		solve();
		for (int i = 1; i <= n; i++)
			a[i] = b[i], a[i].x = -a[i].x, a[i].c = od[o][b[i].c];
		solve();
		for (int i = 1; i <= n; i++)
			a[i] = b[i], a[i].y = -a[i].y, a[i].c = od[o][b[i].c];
		solve();
		for (int i = 1; i <= n; i++)
			a[i] = b[i], a[i].x = -a[i].x, a[i].c = od[o][b[i].c];
		solve();
	}
	printf("%lld", ans * 2);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 12ms
memory: 21056kb

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: 12ms
memory: 18588kb

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: 7ms
memory: 19904kb

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: 78ms
memory: 20888kb

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: 16ms
memory: 19616kb

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: 74ms
memory: 18928kb

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: 551ms
memory: 21112kb

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: 73ms
memory: 18728kb

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: 925ms
memory: 21516kb

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: 77ms
memory: 20052kb

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: 873ms
memory: 21824kb

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: 80ms
memory: 20116kb

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: 893ms
memory: 21516kb

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: -100
Wrong Answer
time: 79ms
memory: 20876kb

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:

546790

result:

wrong answer 1st lines differ - expected: '506892', found: '546790'