QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#410444#3024. Zoning HousesLspeed#AC ✓349ms17216kbC++144.6kb2024-05-14 00:28:102024-05-14 00:28:10

Judging History

This is the latest submission verdict.

  • [2024-05-14 00:28:10]
  • Judged
  • Verdict: AC
  • Time: 349ms
  • Memory: 17216kb
  • [2024-05-14 00:28:10]
  • Submitted

answer

#include <iostream>     // Input/output stream objects
#include <fstream>      // File stream objects
#include <sstream>      // String stream objects
#include <iomanip>      // Input/output manipulators
#include <string>       // String class and functions
#include <vector>       // Dynamic array
#include <list>         // Doubly linked list
#include <set>          // Set container
#include <map>          // Map container
#include <queue>        // Queue container
#include <stack>        // Stack container
#include <algorithm>    // Algorithms on sequences (e.g., sort, find)
#include <cmath>        // Mathematical functions
#include <climits>      // LLONG_MAX, LLONG_MIN
#include <ctime>        // Date and time functions
#include <cstdlib>      // General purpose functions (e.g., memory management)
#include <cstring>      // C-style string functions
#include <cctype>       // Character classification functions
#include <cassert>      // Assert function for debugging
#include <exception>    // Standard exceptions
#include <functional>   // Function objects
#include <iterator>     // Iterator classes
#include <limits>       // Numeric limits
#include <locale>       // Localization and internationalization
#include <numeric>      // Numeric operations (e.g., accumulate)
#include <random>       // Random number generators
#include <stdexcept>    // Standard exception classes
#include <typeinfo>     // Runtime type information
#include <utility>      // Utility components (e.g., std::pair)
#include <bitset>

using namespace std;

#define FOR(i, a, b) for(int i = a; i < (b); i++)
#define FORE(i, a, b) for(int i = a; i <= (b); i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define x first 
#define y second
#define mp make_pair
#define PI 3.141592653
#define compress(coord) sort(all(coord)), coord.resize(unique(all(coord)) - coord.begin())
const double eps = 1e-9;
const ll inf = LLONG_MAX;

static char buf[450<<20];
void* operator new(size_t s) {
    static size_t i = sizeof buf;
    assert(s < i);
    return (void*)&buf[i-=s];
}

void operator delete(void *) {}

const int INF = 1e9 + 10;

struct segData {
    int mxx, mix, mxy, miy, idmxx, idmix, idmxy, idmiy;
    segData() : mxx(-INF), mix(INF), mxy(-INF), miy(INF) {}
    segData(int mxx, int mix, int mxy, int miy, int idmxx, int idmix, int idmxy, int idmiy) : 
    mxx(mxx), mix(mix), mxy(mxy), miy(miy), idmxx(idmxx), idmix(idmix), idmxy(idmxy), idmiy(idmiy) {}
};

struct Node {
    typedef segData T;
    Node *l = 0, *r = 0;
    int lo, hi;
    T val;
    T f(T a, T b) {
        int nmxx, nmix, nmxy, nmiy;
        int nidmxx, nidmix, nidmxy, nidmiy;
        nmxx = max(a.mxx, b.mxx);
        nidmxx = a.mxx >= b.mxx ? a.idmxx : b.idmxx;

        nmix = min(a.mix, b.mix);
        nidmix = a.mix <= b.mix ? a.idmix : b.idmix;

        nmxy = max(a.mxy, b.mxy);
        nidmxy = a.mxy >= b.mxy ? a.idmxy : b.idmxy;

        nmiy = min(a.miy, b.miy);
        nidmiy = a.miy <= b.miy ? a.idmiy : b.idmiy;

        return {nmxx, nmix, nmxy, nmiy, nidmxx, nidmix, nidmxy, nidmiy};
    }

    Node (vector<pii> &v, int lo, int hi) : lo(lo), hi(hi) {
        if (lo == hi) val = T(v[lo].x, v[lo].x, v[lo].y, v[lo].y, lo, lo, lo, lo);
        else {
            int mid = lo + hi >> 1;
            l = new Node(v, lo, mid); r = new Node(v, mid + 1, hi);
            val = f(l->val, r->val);
        }
    }

    T query(int L, int R) {
        if (L > R || lo > R || hi < L) return T();
        if (lo >= L && hi <= R) return val;
        return f(l->query(L, R), r->query(L, R));
    }
};

const int N = 1e5 + 10;
int n, q;
vector<pii> pts(N);
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin >> n >> q;

    FORE(i, 1, n) cin >> pts[i].x >> pts[i].y;
    Node *t = new Node(pts, 1, n);
    while (q--) {
        int L, R, ans = 2*INF;
        cin >> L >> R;
        segData ret = t->query(L, R);
        segData tocal;
        tocal = t->f(t->query(L, ret.idmxx-1), t->query(ret.idmxx+1, R));
        ans = min(ans, max(tocal.mxx - tocal.mix, tocal.mxy - tocal.miy));
        
        tocal = t->f(t->query(L, ret.idmix-1), t->query(ret.idmix+1, R));
        ans = min(ans, max(tocal.mxx - tocal.mix, tocal.mxy - tocal.miy));

        tocal = t->f(t->query(L, ret.idmxy-1), t->query(ret.idmxy+1, R));
        ans = min(ans, max(tocal.mxx - tocal.mix, tocal.mxy - tocal.miy));

        tocal = t->f(t->query(L, ret.idmiy-1), t->query(ret.idmiy+1, R));
        ans = min(ans, max(tocal.mxx - tocal.mix, tocal.mxy - tocal.miy));

        cout << max(ans, 0) << endl;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4400kb

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

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

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

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

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

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

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

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

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

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

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

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

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