QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#197468#2266. Colorful RectangleGalexWA 37ms21680kbC++233.2kb2023-10-02 16:17:262023-10-02 16:17:26

Judging History

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

  • [2023-10-02 16:17:26]
  • 评测
  • 测评结果:WA
  • 用时:37ms
  • 内存:21680kb
  • [2023-10-02 16:17:26]
  • 提交

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];
	SGT() {
		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));
	}
//	for (int i = 1; i <= n; i++) {
//		if (a[i].c == 0)
//			t.mdf(1, tot, 1, a[i].y + 1, tot, lsh[a[i].x] + lsh[a[i].y], 1e18);
//		else if (a[i].c == 1)
//			t.mdf(1, tot, 1, a[i].y + 1, tot, -1e18, lsh[a[i].y]);
//		else
//			ans = min(ans, lsh[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: 7ms
memory: 18456kb

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

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: 21680kb

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

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

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

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:

885288

result:

wrong answer 1st lines differ - expected: '529732', found: '885288'