QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#163574#7105. Pixel ArtTsReaperAC ✓392ms16552kbC++172.0kb2023-09-04 11:12:252023-09-04 11:12:26

Judging History

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

  • [2023-09-04 11:12:26]
  • 评测
  • 测评结果:AC
  • 用时:392ms
  • 内存:16552kb
  • [2023-09-04 11:12:25]
  • 提交

answer

#include <bits/stdc++.h>
#define MAXN ((int) 1e5)
#define MAXK ((int) 1e5)
using namespace std;
typedef pair<int, int> pii;

int n, K, ans1, ans2;
int R1[MAXK + 10], C1[MAXK + 10], R2[MAXK + 10], C2[MAXK + 10];

vector<int> add[MAXK + 10], del[MAXK + 10];
int root[MAXK + 10];

int findroot(int x) {
    if (root[x] != x) root[x] = findroot(root[x]);
    return root[x];
}

void merge(int x, int y) {
    x = findroot(x); y = findroot(y);
    if (x == y) return;
    root[x] = y;
    ans2--;
}

void solve() {
    scanf("%d%*d%d", &n, &K);
    for (int i = 1; i <= n + 1; i++) add[i].clear(), del[i].clear();
    for (int i = 1; i <= K; i++) {
        scanf("%d%d%d%d", &R1[i], &C1[i], &R2[i], &C2[i]);
        add[R1[i]].push_back(i);
        del[R2[i] + 1].push_back(i);
    }
    for (int i = 1; i <= K; i++) root[i] = i;

    ans1 = ans2 = 0;
    int cnt = 0;
    map<pii, int> mp;
    for (int i = 1; i <= n; i++) {
        for (int idx : add[i]) {
            cnt += C2[idx] - C1[idx] + 1;
            auto it = mp.lower_bound(pii(C1[idx], 0));
            if (it != mp.begin()) it = prev(it);
            while (it != mp.end() && it->first.first <= C2[idx]) {
                if (it->first.second >= C1[idx]) merge(it->second, idx);
                it++;
            }
        }

        for (int idx : del[i]) {
            cnt -= C2[idx] - C1[idx] + 1;
            mp.erase(pii(C1[idx], C2[idx]));
        }

        ans1 += cnt; ans2 += add[i].size();
        for (int idx : add[i]) {
            mp[pii(C1[idx], C2[idx])] = idx;
            auto it = mp.find(pii(C1[idx], C2[idx]));
            if (it != mp.begin() && prev(it)->first.second == C1[idx] - 1) merge(prev(it)->second, idx);
            if (next(it) != mp.end() && next(it)->first.first == C2[idx] + 1) merge(next(it)->second, idx);
        }
        printf("%d %d\n", ans1, ans2);
    }
}

int main() {
    int tcase; scanf("%d", &tcase);
    while (tcase--) solve();
    return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 9244kb

input:

3
2 5 2
1 1 1 2
2 3 2 5
2 5 2
1 1 1 3
2 3 2 5
3 3 3
1 1 1 2
3 1 3 2
1 3 2 3

output:

2 1
5 2
3 1
6 1
3 1
4 1
6 2

result:

ok 7 lines

Test #2:

score: 0
Accepted
time: 392ms
memory: 16552kb

input:

2130
2 5 2
1 1 1 2
2 3 2 5
2 5 2
1 1 1 3
2 3 2 5
3 3 3
1 1 1 2
3 1 3 2
1 3 2 3
3 100 51
1 2 2 2
1 4 2 4
1 6 2 6
1 8 2 8
1 10 2 10
1 12 2 12
1 14 2 14
1 16 2 16
1 18 2 18
1 20 2 20
1 22 2 22
1 24 2 24
1 26 2 26
1 28 2 28
1 30 2 30
1 32 2 32
1 34 2 34
1 36 2 36
1 38 2 38
1 40 2 40
1 42 2 42
1 44 2 44
...

output:

2 1
5 2
3 1
6 1
3 1
4 1
6 2
50 50
100 50
200 1
50 50
150 1
200 1
2 1
4 1
6 1
8 1
10 1
12 1
14 1
16 1
18 1
20 1
22 1
24 1
26 1
28 1
30 1
32 1
34 1
36 1
38 1
40 1
42 1
44 1
46 1
48 1
50 1
52 1
54 1
56 1
58 1
60 1
62 1
64 1
66 1
68 1
70 1
72 1
74 1
76 1
78 1
80 1
82 1
84 1
86 1
88 1
90 1
92 1
94 1
96 1...

result:

ok 355756 lines

Extra Test:

score: 0
Extra Test Passed