QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#59846#3024. Zoning HousesYaoBIG#AC ✓205ms17144kbC++171.9kb2022-11-01 19:16:092022-11-01 19:16:11

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-01 19:16:11]
  • Judged
  • Verdict: AC
  • Time: 205ms
  • Memory: 17144kb
  • [2022-11-01 19:16:09]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
const int INF = 2 * (int)1e9 + 7;

struct Seg {
	private:
		const array<int, 3> neutral = {-INF, -INF, -1};
		vector<array<int, 3>> maxs;
		int h = 1;

		array<int, 3> combine(const array<int, 3>& a, const array<int, 3>& b) {
			auto res = neutral;
			if (a[0] > b[0]) {
				res[0] = a[0];
				res[1] = max(a[1], b[0]);
				res[2] = a[2];
			} else {
				res[0] = b[0];
				res[1] = max(a[0], b[1]);
				res[2] = b[2];
			}
			return res;
		}

		array<int, 3> recGet(int a, int b, int i, int ia, int ib) {
			if (ib <= a || b <= ia) return neutral;
			if (a <= ia && ib <= b) return maxs[i];

			int im = (ia + ib) >> 1;
			return combine(recGet(a, b, 2*i, ia, im), recGet(a, b, 2*i+1, im, ib));
		}
	public:
		Seg(const vector<int>& vec) {
			int n = vec.size();
			while(h < n) h <<= 1;

			maxs.resize(2*h, neutral);
			for (int i = 0; i < n; ++i) {
				maxs[i + h][0] = vec[i];
				maxs[i + h][2] = i;
			}
			for (int i = h-1; i > 0; --i) maxs[i] = combine(maxs[2*i], maxs[2*i+1]);
		}
		array<int, 3> get(int a, int b) {
			return recGet(a, b + 1, 1, 0, h);
		}

};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n, q;
	cin >> n >> q;

	vector<int> xs(n), ys(n), rxs(n), rys(n);
	for (int i = 0; i < n; ++i) {
		cin >> xs[i] >> ys[i];
		rxs[i] = -xs[i];
		rys[i] = -ys[i];
	}
	
	Seg x0(rxs), x1(xs), y0(rys), y1(ys);
	for (int qi = 0; qi < q; ++qi) {
		int a, b;
		cin >> a >> b;
		--a; --b;

		auto lo_x = x0.get(a, b);
		auto hi_x = x1.get(a, b);
		auto lo_y = y0.get(a, b);
		auto hi_y = y1.get(a, b);
		lo_x[0] *= -1;
		lo_y[0] *= -1;
		lo_x[1] *= -1;
		lo_y[1] *= -1;

		vector<int> inds = {lo_x[2], hi_x[2], lo_y[2], hi_y[2]};

		int res = INF;
		for (int ind : inds) {
			int dx = hi_x[ind == hi_x[2]] - lo_x[ind == lo_x[2]];
			int dy = hi_y[ind == hi_y[2]] - lo_y[ind == lo_y[2]];
			res = min(res, max(dx, dy));
		}
		cout << res << '\n';
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3516kb

input:

3 2
1 0
0 1
1000 1
1 3
2 3

output:

1
0

result:

ok 2 number(s): "1 0"

Test #2:

score: 0
Accepted
time: 2ms
memory: 3520kb

input:

4 2
0 0
1000 1000
300 300
1 1
1 3
2 4

output:

300
299

result:

ok 2 number(s): "300 299"

Test #3:

score: 0
Accepted
time: 2ms
memory: 3580kb

input:

4 6
0 1
1 3
2 0
3 2
1 3
2 3
2 4
1 2
3 4
1 4

output:

2
0
2
0
0
3

result:

ok 6 numbers

Test #4:

score: 0
Accepted
time: 2ms
memory: 3572kb

input:

8 28
0 1
0 2
3 1
3 2
1 0
2 0
1 3
2 3
4 8
1 2
3 5
2 4
1 5
3 8
2 8
3 4
5 7
7 8
2 5
4 5
2 6
4 6
1 8
1 7
2 7
1 3
6 7
3 7
1 4
4 7
3 6
1 6
6 8
2 3
5 8
5 6

output:

3
0
1
1
3
3
3
0
1
0
2
0
2
1
3
3
3
1
0
2
3
2
2
3
1
0
3
0

result:

ok 28 numbers

Test #5:

score: 0
Accepted
time: 1ms
memory: 3472kb

input:

6 15
100 20
50 30
49 0
0 20
0 10
100 10
1 3
1 4
3 6
3 4
2 6
3 5
1 6
2 3
5 6
4 6
4 5
2 5
2 4
1 2
1 5

output:

30
50
49
0
50
10
100
0
0
10
0
49
30
0
50

result:

ok 15 numbers

Test #6:

score: 0
Accepted
time: 2ms
memory: 3556kb

input:

6 15
20 100
30 50
0 49
20 0
10 0
10 100
3 6
1 4
1 3
5 6
4 5
3 4
3 5
1 5
2 3
2 4
1 6
4 6
2 6
2 5
1 2

output:

49
50
30
0
0
0
10
50
0
30
100
10
50
49
0

result:

ok 15 numbers

Test #7:

score: 0
Accepted
time: 1ms
memory: 3476kb

input:

6 15
100 80
0 0
100 0
0 80
10 10
30 10
3 6
2 6
1 3
2 4
1 5
1 4
4 5
3 4
1 6
4 6
2 3
1 2
3 5
5 6
2 5

output:

70
80
80
80
100
100
0
0
100
20
0
0
70
0
80

result:

ok 15 numbers

Test #8:

score: 0
Accepted
time: 2ms
memory: 3552kb

input:

6 15
80 100
0 0
0 100
80 0
10 10
10 30
2 3
5 6
2 5
1 3
1 5
1 4
4 5
4 6
3 4
1 2
3 5
2 6
3 6
2 4
1 6

output:

0
0
80
80
100
100
0
20
0
0
70
80
70
80
100

result:

ok 15 numbers

Test #9:

score: 0
Accepted
time: 62ms
memory: 3664kb

input:

400 79800
18 1
12 17
3 8
15 6
12 1
4 8
12 5
15 1
3 19
3 7
5 6
18 0
16 4
1 12
19 17
2 16
4 15
8 9
10 10
8 0
11 7
1 13
12 19
5 5
17 11
5 2
8 2
14 19
16 7
16 12
1 15
14 2
18 6
9 12
5 3
2 1
15 4
6 13
5 8
7 1
18 3
4 7
4 9
19 10
13 3
5 15
7 18
8 10
5 12
0 12
17 13
1 19
14 10
13 8
16 9
6 4
9 1
13 2
10 3
7 ...

output:

19
19
19
19
19
19
19
19
19
19
19
19
19
15
19
19
19
12
19
19
19
19
19
19
19
19
19
19
19
19
19
17
19
19
19
18
19
19
19
19
19
19
19
19
19
19
19
19
19
9
19
17
18
19
19
19
19
19
19
19
19
19
19
19
14
13
19
19
5
19
19
19
19
19
19
19
19
0
18
19
19
19
19
19
19
19
19
17
19
5
19
17
19
19
19
0
19
19
19
19
19
19...

result:

ok 79800 numbers

Test #10:

score: 0
Accepted
time: 187ms
memory: 17144kb

input:

100000 99996
0 0
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
0 10
0 11
0 12
0 13
0 14
0 15
0 16
0 17
0 18
0 19
0 20
0 21
0 22
0 23
0 24
0 25
0 26
0 27
0 28
0 29
0 30
0 31
0 32
0 33
0 34
0 35
0 36
0 37
0 38
0 39
0 40
0 41
0 42
0 43
0 44
0 45
0 46
0 47
0 48
0 49
0 50
0 51
0 52
0 53
0 54
0 55
0 56
0 57
0 58
0 ...

output:

999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
999
998
999
999
999
999
999
999
999
999
999
999
999
999
999
378
998
999
999
999
999
999
999
999
999
999
999
999
999
998
998
999
999
999
999
998
998
999
999
999
999
999
...

result:

ok 99996 numbers

Test #11:

score: 0
Accepted
time: 200ms
memory: 17128kb

input:

100000 99997
0 0
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
0 10
0 11
0 12
0 13
0 14
0 15
0 16
0 17
0 18
0 19
0 20
0 21
0 22
0 23
0 24
0 25
0 26
0 27
0 28
0 29
0 30
0 31
0 32
0 33
0 34
0 35
0 36
0 37
0 38
0 39
0 40
0 41
0 42
0 43
0 44
0 45
0 46
0 47
0 48
0 49
0 50
0 51
0 52
0 53
0 54
0 55
0 56
0 57
0 58
0 ...

output:

99
832
616
99
378
392
580
99
730
382
164
133
253
444
427
405
99
99
699
109
99
336
118
544
405
348
345
334
99
513
165
781
99
234
635
159
278
150
506
375
734
123
126
259
158
357
261
99
671
577
367
172
512
99
99
99
676
149
435
99
99
99
490
320
190
215
108
174
225
241
973
281
150
504
205
256
378
277
751...

result:

ok 99997 numbers

Test #12:

score: 0
Accepted
time: 205ms
memory: 17140kb

input:

100000 99995
-560503114 775639741
-414293351 -547361889
-89816875 416783478
354863777 639273005
742857133 735843002
735048967 731105561
-260694369 -89407316
-4536805 206228327
-651840538 142687735
341872164 155276150
-534562261 184488125
-61124016 402135121
709610603 652212586
499499561 778614734
-6...

output:

1999953414
1999941292
1999947469
1999947469
1999915835
1999915835
1999941292
1999829499
1999915835
1999945194
1999829499
1999923357
1999923357
1999947237
1999953414
1999930063
1994894974
1999755742
1999941292
1999820444
1999941292
1999947469
1999524085
1999930063
1999915835
1999814416
1999526826
199...

result:

ok 99995 numbers

Test #13:

score: 0
Accepted
time: 188ms
memory: 17104kb

input:

100000 99997
1 1
1 0
0 1
0 0
0 3
0 2
1 3
1 2
1 5
0 4
0 5
1 4
0 7
1 6
0 6
1 7
0 9
1 8
1 9
0 8
1 10
1 11
0 11
0 10
1 13
0 13
0 12
1 12
1 15
1 14
0 14
0 15
1 16
1 17
0 17
0 16
1 19
0 18
0 19
1 18
1 20
0 21
0 20
1 21
0 22
0 23
1 23
1 22
1 25
1 24
0 24
0 25
1 27
0 27
1 26
0 26
0 29
0 28
1 29
1 28
1 30
1 ...

output:

499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
389
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
499
...

result:

ok 99997 numbers