QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#166066 | #7105. Pixel Art | ucup-team045 | WA | 190ms | 22148kb | C++20 | 2.8kb | 2023-09-06 00:37:59 | 2023-09-06 00:38:00 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<array>
using namespace std;
using LL = long long;
int p[1000005];
int find(int x){
return p[x] == x ? x : p[x] = find(p[x]);
}
bool merge(int x, int y){
x = find(x), y = find(y);
if (x == y) return false;
p[x] = y;
return true;
}
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
vector<int> id(1000005), c(1000005);
int T;
cin >> T;
while(T--){
int n, m, k;
cin >> n >> m >> k;
vector<vector<pair<int, int> > > pos(n + 2);
vector<vector<int> > add(n + 2), del(n + 2);
vector<LL> s(n + 2);
for(int i = 0; i < k; i++){
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if (x1 == x2){
pos[x1].push_back({y1, y2});
s[x1] += y2 - y1 + 1;
s[x1 + 1] -= y2 - y1 + 1;
}
else{
add[x1].push_back(y1);
del[x2 + 1].push_back(y1);
s[x1] += 1;
s[x2 + 1] -= 1;
}
}
for(int i = 1; i <= n; i++) s[i] += s[i - 1];
for(int i = 1; i <= n; i++) s[i] += s[i - 1];
int conn = 0, idx = 0;
vector<array<int, 3> > last;
for(int i = 1; i <= n; i++){
for(auto x : add[i]){
++c[x];
if (!id[x]){
id[x] = ++idx;
conn += 1;
p[idx] = idx;
}
}
for(auto x : del[i]){
if (--c[x] == 0){
id[x] = 0;
}
}
sort(pos[i].begin(), pos[i].end());
int j = -1;
vector<array<int, 3> > cur;
for(auto [l, r] : pos[i]){
++idx;
p[idx] = idx;
conn += 1;
if (j >= 0 && j < last.size()){
auto [L, R, id] = last[j];
if (max(L, l) <= min(R, r)){
conn -= merge(idx, id);
}
}
while(j + 1 < last.size() && last[j + 1][0] <= r){
auto [L, R, id] = last[++j];
if (max(L, l) <= min(R, r)){
conn -= merge(idx, id);
}
}
if (id[l - 1]) conn -= merge(idx, id[l - 1]);
if (id[r + 1]) conn -= merge(idx, id[r + 1]);
cur.push_back({l, r, idx});
}
last.swap(cur);
cout << s[i] << ' ' << conn << '\n';
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 10780kb
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: -100
Wrong Answer
time: 190ms
memory: 22148kb
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 51 50 50 150 100 200 100 2 1 4 0 6 0 8 0 10 0 12 0 14 0 16 0 18 0 20 0 22 0 24 0 26 0 28 0 30 0 32 0 34 0 36 0 38 0 40 0 42 0 44 0 46 0 48 0 50 0 52 0 54 0 56 0 58 0 60 0 62 0 64 0 66 0 68 0 70 0 72 0 74 0 76 0 78 0 80 0 82 0 84 0 86 0 88 0 90 0 92 0 94 0...
result:
wrong answer 10th lines differ - expected: '200 1', found: '200 51'