QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#240850 | #7105. Pixel Art | pandapythoner# | AC ✓ | 292ms | 22300kb | C++23 | 3.6kb | 2023-11-05 20:12:42 | 2023-11-05 20:12:43 |
Judging History
answer
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
vector<int> dsu;
int get(int v) {
return dsu[v] < 0 ? v : dsu[v] = get(dsu[v]);
}
bool unite(int a, int b) {
a = get(a), b = get(b);
if (a == b) return false;
if (dsu[a] > dsu[b]) swap(a, b);
dsu[a] += dsu[b];
return dsu[b] = a, true;
}
struct seg {
int l, r, idx;
bool operator<(const seg& o) const {
return r < o.r;
}
seg(int l, int r, int id) : l(l), r(r), idx(id) {}
};
struct rct {
int r1, c1, r2, c2;
rct(int r1 = 0, int c1 = 0, int r2 = 0, int c2 = 0) : r1(r1), c1(c1), r2(r2), c2(c2) {}
};
const int M = 1e5 + 5;
vector<seg> hor[M];
vector<seg> vert[M];
int colh[M], colv[M];
int c = 0;
void solve() {
++c;
int n, k, m;
cin >> n >> m >> k;
dsu.clear();
vector<rct> r(k);
for (int i = 0; i < k; ++i) {
int r1, c1, r2, c2;
cin >> r1 >> c1 >> r2 >> c2;
r[i] = {r1, c1, r2, c2};
if (r1 == r2) {
hor[r1].emplace_back(c1, c2, i);
} else {
vert[c1].emplace_back(r1, r2, i);
}
}
for (auto [r1, c1, r2, c2] : r) {
if (r1 == r2) {
if (colh[r1] == c) continue;
sort(all(hor[r1]));
colh[r1] = c;
} else {
if (colv[c1] == c) continue;
sort(all(vert[c1]));
colv[c1] = c;
}
}
dsu.assign(k, -1);
auto at = [&](int i, int j) {
auto it = lower_bound(all(hor[i]), seg{j, j, -1});
if (it != hor[i].end() && it->l <= j) {
return it->idx;
}
it = lower_bound(all(vert[j]), seg{i, i, -1});
if (it != vert[j].end() && it->l <= i) {
return it->idx;
}
return -1;
};
vector<vector<pair<int, int>>> edges(n + 1);
for (int i = 0; i < k; ++i) {
for (auto [x, y] : {make_pair(r[i].r1, r[i].c1), make_pair(r[i].r2, r[i].c2)}) {
for (auto [dx, dy] : {make_pair(-1, 0), make_pair(1, 0), make_pair(0, -1), make_pair(0, 1)}) {
int j = at(x + dx, y + dy);
if (j != i && j != -1) {
edges[max(x, x + dx)].emplace_back(i, j);
}
}
}
}
vector<vector<int>> ev(n + 1);
vector<int> cnt1(n + 1);
vector<int> cnt2(n + 1);
for (auto [r1, c1, r2, c2] : r) {
if (r1 == r2) {
ev[r1].emplace_back(c2 - c1 + 1);
} else {
cnt1[r1]++;
cnt2[r2]++;
}
}
int cntv = 0;
ll cnt_b = 0, cnt_comp = 0;
for (int i = 1; i <= n; ++i) {
cntv += cnt1[i];
cnt_b += cntv;
cnt_comp += cnt1[i];
for (int tp : ev[i]) {
cnt_comp++;
cnt_b += tp;
}
for (auto [a, b] : edges[i]) {
cnt_comp -= unite(a, b);
}
cntv -= cnt2[i];
cout << cnt_b << ' ' << cnt_comp << '\n';
}
for (auto [r1, c1, r2, c2] : r) {
if (r1 == r2) {
hor[r1].clear();
} else {
vert[c1].clear();
}
}
}
int32_t main() {
if (1) {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
#ifdef LOCAL
freopen("../input.txt", "r", stdin);
freopen("../output.txt", "w", stdout);
#endif
int tt;
cin >> tt;
while (tt--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 8100kb
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: 292ms
memory: 22300kb
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