QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#162778 | #7105. Pixel Art | GenshinImpactsFault# | AC ✓ | 247ms | 31164kb | C++17 | 5.4kb | 2023-09-03 16:35:51 | 2023-09-04 04:31:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define M 100010
int fa[M];
vector<array<int, 3>> row[M], a1[M], a2[M];
int ad[M];
LL Ans1[M]; int Ans2[M];
vector<pair<int, int>> Edge[M];
int add[M];
struct Node{
int r1, c1, r2, c2, id;
bool operator < (const Node& rhs) const {
return c1 < rhs.c1 || (c1 == rhs.c1 && r1 < rhs.r1);
}
} lie[M], hang[M * 2];
int Find(int x) {
return fa[x] == x ? x : fa[x] = Find(fa[x]);
}
void Do() {
int n, m, k;
cin >> n >> m >> k;
for(int i = 1; i <= k; ++ i) {
fa[i] = i;
}
for(int i = 0; i <= n + 1; ++ i) {
row[i].clear();
a1[i].clear();
a2[i].clear();
Edge[i].clear();
add[i] = 0;
ad[i] = 0;
}
int tot = 0, cnt = 0;
for(int i = 1; i <= k; ++ i) {
int r1, c1, r2, c2;
cin >> r1 >> c1 >> r2 >> c2;
++add[r1];
if(r1 == r2) {
row[r1].push_back({c1, c2, i});
if(c1 > 1) hang[++cnt] = {r1, c1 - 1, r1, c1 - 1, i};
if(c2 < m) hang[++cnt] = {r1, c2 + 1, r1, c2 + 1, i};
}
else {
ad[r1] ++; ad[r2 + 1] --;
a1[r1 - 1].push_back({c1, c1, i});
a2[r2 + 1].push_back({c1, c2, i});
lie[++ tot] = {r1, c1, r2, c2, i};
}
}
for(int i = 1; i <= n; ++ i) {
ad[i] += ad[i - 1];
Ans1[i] = Ans1[i - 1] + ad[i];
for(auto [l, r, id] : row[i]) {
Ans1[i] += r - l + 1;
}
}
// lie lie
sort(lie + 1, lie + tot + 1);
for(int i = 1; i < tot; ++ i) {
if(lie[i].c1 == lie[i + 1].c1) {
if(lie[i].r2 + 1 == lie[i + 1].r1) {
Edge[lie[i + 1].r1].push_back({lie[i].id, lie[i + 1].id});
}
}
}
for(int i = 1; i < tot; ++ i) {
if(i == 1 || lie[i].c1 != lie[i - 1].c1) {
int j = i + 1;
while(j <= tot && lie[j].c1 == lie[i].c1) ++ j;
if(j > tot) continue;
if(lie[i].c1 + 1 != lie[j].c1) continue;
int ilim = j - 1, jlim = j;
while(lie[jlim + 1].c1 == lie[j].c1 && jlim < tot) ++ jlim;
int I = i, J = j;
while(I <= ilim && J <= jlim) {
int Li = lie[I].r1, Ri = lie[I].r2;
int Lj = lie[J].r1, Rj = lie[J].r2;
if(max(Li, Lj) <= min(Ri, Rj)) {
Edge[max(Li, Lj)].push_back({lie[I].id, lie[J].id});
}
if(Ri < Rj) {
++ I;
}
else {
++ J;
}
}
}
}
// hang hang
for(int i = 1; i <= n; ++ i) {
sort(row[i].begin(), row[i].end());
sort(a1[i].begin(), a1[i].end());
sort(a2[i].begin(), a2[i].end());
for(int j = 0; j + 1 < row[i].size(); ++ j) {
if(row[i][j][1] + 1 == row[i][j + 1][0]) {
Edge[i].push_back({row[i][j][2], row[i][j + 1][2]});
}
}
}
for(int i = 1; i < n; ++ i) {
int I = 0, J = 0;
while(I < row[i].size() && J < row[i + 1].size()) {
int Li = row[i][I][0], Ri = row[i][I][1];
int Lj = row[i + 1][J][0], Rj = row[i + 1][J][1];
if(max(Li, Lj) <= min(Ri, Rj)) {
Edge[i + 1].push_back({row[i][I][2], row[i + 1][J][2]});
}
if(Ri < Rj) ++ I;
else ++ J;
}
}
// hang lie 1
for(int i = 1; i < n; ++ i) {
int I = 0;
for(auto [l, r, id] : row[i]) {
while(I < a1[i].size() && a1[i][I][0] < l) ++ I;
if(I == a1[i].size()) break;
while(I < a1[i].size() && a1[i][I][0] <= r) {
Edge[i + 1].push_back({id, a1[i][I][2]});
++ I;
}
}
}
for(int i = 2; i <= n; ++ i) {
int I = 0;
for(auto [l, r, id] : row[i]) {
while(I < a2[i].size() && a2[i][I][0] < l) ++ I;
if(I == a2[i].size()) break;
while(I < a2[i].size() && a2[i][I][0] <= r) {
Edge[i].push_back({id, a2[i][I][2]});
++ I;
}
}
}
// hang lie 2
sort(hang + 1, hang + cnt + 1);
if(1) {
int I = 1, J = 1;
for(; I <= tot && J <= cnt;) {
int ci = lie[I].c1, li = lie[I].r1, ri = lie[I].r2;
int cj = hang[J].c1, rj = hang[J].r1;
// cout << "### " << ci << " " << li << " " << ri << " : " << cj << " " << rj << "\n";
if(ci == cj && rj >= li && rj <= ri) {
Edge[rj].push_back({lie[I].id, hang[J].id});
}
if(cj > ci || (cj == ci && rj > ri)) ++I;
else ++J;
}
}
for(int i = 1; i <= n; i++) {
Ans2[i] = Ans2[i - 1] + add[i];
for(auto v : Edge[i]) {
// cout << ">>> " << v.first << " " << v.second << "\n";
int x = Find(v.first), y = Find(v.second);
if(x == y) continue;
fa[x] = y, --Ans2[i];
}
}
for(int i = 1; i <= n; i++) cout << Ans1[i] << " " << Ans2[i] << "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T;
cin >> T;
while(T --) {
Do();
}
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 17372kb
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: 247ms
memory: 31164kb
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