QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#261853 | #7105. Pixel Art | ricofx | AC ✓ | 409ms | 15616kb | C++17 | 1.9kb | 2023-11-23 12:01:31 | 2023-11-23 12:01:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 998244353;
const int N = 1e5 + 5;
int n, m, k, fa[N], C1[N], C2[N];
ll ans1, ans2, cnt;
vector<int> add[N], del[N];
int find(int x) {
return x == fa[x] ? x : fa[x] = find(fa[x]);
}
void merge(int u, int v) {
u = find(u), v = find(v);
if (u == v) return;
fa[u] = v;
ans2--;
}
void solve() {
cin >> n >> m >> k;
map<pair<int, int>, int> mp;
ans1 = ans2 = cnt = 0;
for (int i = 1; i <= n + 1; i++) add[i].clear(), del[i].clear();
iota(fa + 1, fa + k + 1, 1);
for (int i = 1; i <= k; i++) {
int r1, c1, r2, c2;
cin >> r1 >> c1 >> r2 >> c2;
C1[i] = c1, C2[i] = c2;
add[r1].push_back(i);
del[r2 + 1].push_back(i);
}
for (int i = 1; i <= n; i++) {
for (int idx : add[i]) {
int l = C1[idx], r = C2[idx];
auto it = mp.lower_bound({l, 0});
if (it != mp.begin()) it = prev(it);
while (it != mp.end() && it->first.first <= r) {
if (it->first.second >= l) merge(it->second, idx);
++it;
}
}
for (int idx : del[i]) {
int l = C1[idx], r = C2[idx];
cnt -= r - l + 1;
mp.erase({l, r});
}
for (int idx : add[i]) {
int l = C1[idx], r = C2[idx];
mp[{l, r}] = idx;
auto it = mp.find({l, r});
if (it != mp.begin() && prev(it)->first.second == l - 1) merge(prev(it)->second, idx);
if (next(it) != mp.end() && next(it)->first.first == r + 1) merge(next(it)->second, idx);
cnt += r - l + 1;
}
ans1 += cnt, ans2 += add[i].size();
cout << ans1 << ' ' << ans2 << '\n';
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int T = 1;
cin >> T;
while (T--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9572kb
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: 409ms
memory: 15616kb
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