QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#356797 | #7105. Pixel Art | karuna | AC ✓ | 291ms | 35944kb | C++20 | 2.6kb | 2024-03-18 12:08:35 | 2024-03-18 12:08:36 |
Judging History
answer
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 101010;
int n, m, k;
vector<array<int, 3>> V[4][MAXN];
vector<pair<int, int>> E[MAXN];
void run(vector<array<int, 3>> &H, vector<array<int, 3>> &L, int x) {
if (H.empty() || L.empty()) {
return;
}
sort(H.begin(), H.end());
sort(L.begin(), L.end());
auto f = [&](auto s, auto t) {
int l = max(s[1], t[1]);
int r = min(s[0], t[0]);
if (l <= r) {
E[(x == -1) ? l : x + 1].push_back({s[2], t[2]});
}
};
for (int q = 0, p = 0; q < L.size(); q++) {
if (p < H.size()) {
f(H[p], L[q]);
}
while (p < H.size() && L[q][0] >= H[p][0]) {
++p;
if (p < H.size()) f(H[p], L[q]);
}
}
}
struct dsu {
int par[MAXN];
void init(int _n) {
for (int i = 0; i < _n + 5; i++) {
par[i] = i;
}
}
int find(int a) {
return par[a] = ((par[a] == a) ? a : find(par[a]));
}
bool merge(int a, int b) {
a = find(a);
b = find(b);
if (a != b) {
par[b] = a;
}
return a != b; // true if different component
}
} d1;
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
int T;
cin >> T;
while (T--) {
cin >> n >> m >> k;
vector<int> P;
vector<ll> ans(n + 2), cmp(n + 2);
for (int i = 0; i < k; i++) {
int rs, re, cs, ce;
cin >> rs >> cs >> re >> ce;
V[0][re].push_back({ce, cs, i});
V[1][rs].push_back({ce, cs, i});
V[2][ce].push_back({re, rs, i});
V[3][cs].push_back({re, rs, i});
int sz = ce - cs + 1;
ans[rs] += sz;
ans[re + 1] -= sz;
cmp[rs] += 1;
P.push_back(cs);
P.push_back(ce);
}
for (int i = 1; i <= n; i++) ans[i] += ans[i - 1];
for (int i = 1; i <= n; i++) ans[i] += ans[i - 1];
sort(P.begin(), P.end());
P.erase(unique(P.begin(), P.end()), P.end());
for (int x = 1; x < n; x++) {
run(V[0][x], V[1][x + 1], x);
}
for (int i = 0; i < (int)P.size() - 1; i++) {
if (P[i] + 1 != P[i + 1]) continue;
run(V[2][P[i]], V[3][P[i] + 1], -1);
}
d1.init(k);
for (int i = 1; i <= n; i++) {
cmp[i] += cmp[i - 1];
for (auto [u, v] : E[i]) {
cmp[i] -= d1.merge(u, v);
}
}
for (int i = 1; i <= n; i++) {
cout << ans[i] << ' ' << cmp[i] << '\n';
}
// init
for (int i = 1; i <= n; i++) {
for (int t = 0; t < 2; t++) {
V[t][i].clear();
}
E[i].clear();
}
for (int y : P) {
for (int t = 2; t < 4; t++) {
V[t][y].clear();
}
}
}
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
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: 35944kb
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