QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#227701#6806. LandlordjzhAC ✓29ms3472kbC++201.9kb2023-10-27 21:27:472023-10-27 21:27:47

Judging History

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

  • [2023-10-27 21:27:47]
  • 评测
  • 测评结果:AC
  • 用时:29ms
  • 内存:3472kb
  • [2023-10-27 21:27:47]
  • 提交

answer

#include <algorithm>
#include<bits/stdc++.h>

using namespace std;


bool is_in_range(int x, int x1, int x2) {
    return min(x1, x2) <= x && x < max(x1, x2);
}

bool is_in(int x, int y, int x1, int y1, int x2, int y2) {
    bool ret = is_in_range(x, x1, x2) && is_in_range(y, y1, y2);
    return ret;
}

void solve() {

    int x1, y1, x2, y2;
    int xx1, yy1, xx2, yy2;
    cin >> x1 >> y1 >> x2 >> y2;
    cin >> xx1 >> yy1 >> xx2 >> yy2;
    vector<int> xv = {x1, x2, xx1, xx2}, yv = {y1, y2, yy1, yy2};
    sort(xv.begin(), xv.end());
    sort(yv.begin(), yv.end());
    typedef pair<int, int> pii;
    map<pii, pii> fa;
    auto find = [&](pii u) {
        while (u != fa[u]) u = fa[u] = fa[fa[u]];
        return u;
    };
    map<int, vector<pii>> kind;
    map<pii, int> kds;

    for (int i = 0; i < xv.size(); i++) {
        int xi = xv[i];
        for (int j = 0; j < yv.size(); j++) {
            fa[{i, j}] = {i, j};
            int yi = yv[j];
            int kd = 0;
            kd += is_in(xi, yi, x1, y1, x2, y2);
            kd += 2 * is_in(xi, yi, xx1, yy1, xx2, yy2);
            if (kd == 0)continue;
            kds[{i, j}] = kd;
            kind[kd].push_back({i, j});
        }
    }
    for (int i = 1; i <= 3; i++) {
        for (auto pt: kind[i]) {
            for (auto pt2: kind[i]) {
                if (abs(pt.first - pt2.first) + abs(pt.second - pt2.second) <= 1) {
                    fa[find(pt)] = find(pt2);
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < xv.size(); i++) {
        for (int j = 0; j < yv.size(); j++) {
            if ((pii) {i, j} == find({i, j}) && kds[{i, j}] != 0) {
                ans++;
            }
        }
    }
    cout << ans+1 << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

3
4
2

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 29ms
memory: 3376kb

input:

10000
399413444 601729739 838979329 605646850
176742602 192902430 399413444 601729739
19226489 2915752 27806715 977516728
4075670 1872865 19226489 925008461
45547871 393001695 58201503 713825285
18241876 197851829 45547871 713825285
237513514 504913958 868997719 543598899
134432693 110279295 2375135...

output:

3
3
3
3
3
3
3
3
3
3
3
3
3
3
4
4
4
4
4
4
4
4
3
3
4
3
3
4
3
3
4
3
3
4
4
3
3
5
3
3
4
3
3
5
4
3
5
4
3
3
6
3
3
4
4
5
3
3
4
3
4
3
3
3
3
3
4
3
4
3
2
3
3
4
3
3
4
3
3
4
3
3
4
3
3
4
4
3
3
5
3
3
4
4
5
3
3
4
3
4
3
3
3
3
3
4
4
4
4
4
4
4
4
3
3
4
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
4
5
6
3
4
5
...

result:

ok 10000 lines