QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#273801 | #7105. Pixel Art | ikaurov# | AC ✓ | 633ms | 28484kb | C++20 | 4.5kb | 2023-12-03 04:19:26 | 2023-12-03 04:19:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef long double ld;
const ld PI = acosl(-1);
const ll mod7 = 1e9 + 7;
const ll mod9 = 998244353;
const ll INF = 2 * 1024 * 1024 * 1023;
const char nl = '\n';
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define all(v) v.begin(),v.end()
#pragma GCC optimize("O2")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update>;
ll l, r, k, n, m, p, q, u, v, w, x, y, z;
string s, t;
vi d4x = {1, 0, -1, 0};
vi d4y = {0, 1, 0, -1};
vi d8x = {1, 0, -1, 0, 1, 1, -1, -1};
vi d8y = {0, 1, 0, -1, 1, -1, 1, -1};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//////////////////// LIBRARY CODE ////////////////////
struct DSU {
vector<int> e;
DSU(int N) {
e = vector<int>(N, -1);
}
// get representive component (uses path compression)
int get(int x) { return e[x] < 0 ? x : e[x] = get(e[x]); }
bool same_set(int a, int b) { return get(a) == get(b); }
int size(int x) { return -e[get(x)]; }
bool unite(int x, int y) { // union by size, merge y into x
x = get(x), y = get(y);
if (x == y) return false;
if (e[x] > e[y]) swap(x, y);
e[x] += e[y]; e[y] = x;
return true;
}
};
///////////////////////////////////////////////////////
vector<vi> hor[100010];
vector<vi> vert[100010];
int check(int x, int y) {
auto ptr = lower_bound(all(hor[x]), vi{y, (int)1e9, (int)1e9});
if(ptr != hor[x].begin()) {
ptr--;
if((*ptr)[1] >= y) return (*ptr)[2];
}
ptr = lower_bound(all(vert[y]), vi{x, (int)1e9, (int)1e9});
if(ptr != vert[y].begin()) {
ptr--;
if((*ptr)[1] >= x) return (*ptr)[2];
}
return -1;
}
bool multiTest = 1;
void solve(int tt) {
cin >> n >> m >> k;
vector<vi> lines;
set<int> cols;
vi d2(n+10, 0);
vi d1(n+10, 0);
vi newComponent(n+10, 0);
forn(i, k) {
ll x1, x2, y1, y2;
cin >> x1 >> y1 >> x2 >> y2;
lines.push_back({x1, y1, x2, y2});
if(x1 == x2) {
hor[x1].push_back({y1, y2, i});
newComponent[x1]++;
d1[x1] += y2 + 1 - y1;
}
else {
vert[y1].push_back({x1, x2, i});
newComponent[x1]++;
d2[x1]++;
d2[x2+1]--;
cols.insert(y1);
}
}
for(int i = 1; i <= n; i++) {
sort(all(hor[i]));
}
for(int z : cols) {
sort(all(vert[z]));
}
// for(int i = 1; i <= n; i++) {
// for(int j = 1; j <= m; j++) cout << check(i, j) << ' ';
// cout << nl;
// }
vector<pii> edges[n+10];
forn(i, k) {
forn(dir, 4) {
int newX = lines[i][0] + d4x[dir];
int newY = lines[i][1] + d4y[dir];
if(newX <= 0 || newX > n || newY <= 0 || newY > m) continue;
int spot = check(newX, newY);
if(spot == -1 || spot == i) continue;
int requiredRow = max(newX, lines[i][0]);
edges[requiredRow].push_back({i, spot});
}
forn(dir, 4) {
int newX = lines[i][2] + d4x[dir];
int newY = lines[i][3] + d4y[dir];
if(newX <= 0 || newX > n || newY <= 0 || newY > m) continue;
int spot = check(newX, newY);
if(spot == -1 || spot == i) continue;
int requiredRow = max(newX, lines[i][0]);
edges[requiredRow].push_back({i, spot});
}
}
// for(int i = 1; i <= 3; i++) {
// cout << i << nl;
// for(auto[y, z] : edges[i]) cout << y << ' ' << z << nl;
// }
ll curAns1 = 0;
ll curVert = 0;
ll curAns2 = 0;
DSU graphDSU(k+10);
for(int i = 1; i <= n; i++) {
curAns1 += d1[i];
curVert += d2[i];
curAns1 += curVert;
curAns2 += newComponent[i];
for(auto [y, z] : edges[i]) {
if(graphDSU.same_set(y, z)) continue;
curAns2--;
graphDSU.unite(y, z);
}
cout << curAns1 << ' ' << curAns2 << nl;
}
for(int i = 1; i <= n; i++) hor[i].clear();
for(int z : cols) vert[z].clear();
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(14);
int t = 1;
if (multiTest) cin >> t;
for (int ii = 0; ii < t; ii++) {
solve(ii);
}
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 8256kb
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: 633ms
memory: 28484kb
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