QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#425052#7105. Pixel ArtHHH666AC ✓291ms18264kbC++143.2kb2024-05-29 21:47:162024-05-29 21:47:16

Judging History

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

  • [2024-05-29 21:47:16]
  • 评测
  • 测评结果:AC
  • 用时:291ms
  • 内存:18264kb
  • [2024-05-29 21:47:16]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define i1 __int128
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define ep emplace
#define eb emplace_back
#define all(v) v.begin(), v.end()

using namespace std;

template<typename types>
void read(types &x) {
    x = 0; char c = getchar(); int f = 1;
    while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); }
    while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
    x *= f; return;
}
void read() {}
template<typename types, typename... Args>
void read(types &x, Args&... args) {
    read(x), read(args...);
    return;
}
template<typename types>
void write(types x) {
    if (x < 0) putchar('-'), x = -x;
    types k = x / 10;
    if (k) write(k);
    putchar(x - k * 10 + '0');
    return;
}
void print() { puts(""); }
template<typename types, typename... Args>
void print(types x, Args... args) {
    write(x), putchar(' '), print(args...);
    return;
}

const int MAXN = 1e5 + 10;

int n, m, k;
struct Segment {
    int l, r, id;
    Segment(int l, int r, int id) : l(l), r(r), id(id) {}
    bool operator < (const Segment &x) const {
        return l < x.l;
    }
};
vector<Segment> seg[MAXN], del[MAXN];
set<Segment> s;
ll sum[MAXN];
int pa[MAXN];
int mx[MAXN];

auto getit(int l, int r) {
    auto itl = prev(s.upper_bound(Segment(l, 0, 0)));
    auto itr = s.upper_bound(Segment(r, 0, 0));
    if (itl -> r < l) ++itl;
    return mp(itl, itr);
}
int find(int x) { return x == pa[x] ? x : pa[x] = find(pa[x]); }
bool merge(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return false;
    pa[x] = y, mx[y] = max(mx[y], mx[x]); return true;
}

void solve() {
    read(n, m, k);
    s.clear();
    for (int i = 1; i <= n; ++i) seg[i].clear(), del[i].clear(), sum[i] = 0;
    for (int i = 1; i <= k; ++i) mx[i] = 0;
    iota(pa + 1, pa + k + 1, 1);
    for (int i = 1; i <= k; ++i) {
        int x1, y1, x2, y2; read(x1, y1, x2, y2);
        mx[i] = x2;
        seg[x1].eb(y1, y2, i);
        del[x2 + 1].eb(y1, y2, i);
        sum[x1] += (y2 - y1 + 1);
        sum[x2 + 1] -= (y2 - y1 + 1);
    }
    ll tot = 0;
    int ex = 0, now = 0;
    s.ep(-1, -1, -1), s.ep(m + 10, m + 10, -1);
    for (int i = 1; i <= n; ++i) {
        sum[i] += sum[i - 1];
        tot += sum[i];
        for (auto j : seg[i]) {
            set<Segment>::iterator itl, itr; tie(itl, itr) = getit(j.l, j.r);
            for (auto it = itl; it != itr; ++it) 
                now -= merge(it -> id, j.id);
        }
        for (auto j : del[i]) 
            if (mx[find(j.id)] == i - 1) ++ex, --now, mx[find(j.id)] = INT_MAX;
        for (auto j : del[i]) s.erase(s.lower_bound(j));
        for (auto j : seg[i]) s.ep(j), ++now;
        for (auto j : seg[i]) {
            auto it = s.lower_bound(j);
            if (prev(it) -> r + 1 == it -> l) now -= merge(prev(it) -> id, it -> id);
            if (it -> r + 1 == next(it) -> l) now -= merge(it -> id, next(it) -> id);
        }
        write(tot), putchar(' '), write(ex + now), puts("");
    }
    return;
}

int main() {
    int t; read(t);
    while (t--) solve();
    return 0;
}

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

详细

Test #1:

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

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

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