QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#187839 | #7105. Pixel Art | UrgantTeam# | WA | 285ms | 20368kb | C++23 | 4.7kb | 2023-09-25 02:01:51 | 2023-09-25 02:01:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int const maxn = 1e5 + 5;
vector < pair < pair < int, int >, int > > in[maxn];
int p[maxn], sz[maxn];
vector < pair < int, int > > adds[maxn], del[maxn];
ll b[maxn], c[maxn];
int get(int v) {
if (p[v] == v) return v;
p[v] = get(p[v]);
return p[v];
}
int add(int u, int v) {
u = p[u], v = p[v];
if (u == v) return 0;
if (sz[u] < sz[v]) p[u] = v;
else if (sz[u] > sz[v]) p[v] = u;
else p[u] = v, sz[v]++;
return 1;
}
main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#endif // HOME
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n, m, k, r1, c1, r2, c2;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) in[i] = {}, b[i] = 0, c[i] = 0, adds[i] = {}, del[i] = {};
for (int i = 1; i <= k; i++) p[i] = i, sz[i] = 0;
for (int i = 1; i <= k; i++) {
cin >> r1 >> c1 >> r2 >> c2;
if (r1 == r2) {
b[r1] += (c2 - c1 + 1);
in[r1].push_back({{c1, c2}, i});
} else {
c[r1]++;
c[r2 + 1]--;
adds[r1].push_back({c1, i});
del[r2 + 1].push_back({c1, i});
}
}
int cmp = 0;
set < pair < pair < int, int >, int > > Q;
set < pair < int, int > > h;
ll curr = 0, add_all = 0;
for (int i = 1; i <= n; i++) {
cmp += in[i].size();
cmp += adds[i].size();
sort(in[i].begin(), in[i].end());
int l = 0;
vector < pair < pair < int, int >, int > > cur;
while (l < in[i].size()) {
int r = l, cur_r = in[i][l].first.second;
while (r < in[i].size() && in[i][r].first.first <= cur_r + 1) {
cmp -= add(in[i][l].second, in[i][r].second);
cur_r = max(cur_r, in[i][r].first.second);
r++;
}
cur.push_back({{in[i][l].first.first, cur_r}, in[i][l].second});
l = r;
}
in[i] = cur;
int l_ptr = 0, r_ptr = 0;
set < pair < int, int > > now_del;
for (auto key : del[i]) {
h.erase(key);
now_del.insert(key);
}
for (auto key : adds[i]) {
auto it = h.upper_bound({key.first + 1, -1});
if (it != h.end() && (*it).first == key.first + 1) {
cmp -= add(key.second, (*it).second);
}
if (it != h.begin()) {
it--;
if ((*it).first == key.first - 1) {
cmp -= add(key.second, (*it).second);
}
}
it = now_del.lower_bound({key.first, -1});
if (it != now_del.end() && (*it).first == key.first) {
cmp -= add(key.second, (*it).second);
}
h.insert(key);
pair < pair < int, int >, int > tmp = {{key.first + 1, -1}, -1};
int itt = lower_bound(in[i - 1].begin(), in[i - 1].end(), tmp) - in[i - 1].begin() - 1;
if (itt >= 0 && in[i - 1][itt].first.first <= key.first && key.first <= in[i - 1][itt].first.second) {
cmp -= add(in[i - 1][itt].second, key.second);
}
}
for (auto key : in[i]) {
while (l_ptr < in[i - 1].size() && in[i - 1][l_ptr].first.second < key.first.first) l_ptr++;
while (r_ptr < in[i - 1].size() && in[i - 1][r_ptr].first.first <= key.first.second) r_ptr++;
for (int j = l_ptr; j < r_ptr; j++) cmp -= add(key.second, in[i - 1][j].second);
int L = key.first.first, R = key.first.second;
auto it = h.lower_bound({R + 1, -1});
if (it != h.end() && (*it).first == R + 1) cmp -= add(key.second, (*it).second);
it = h.lower_bound({L, -1});
if (it != h.begin()) {
it--;
if ((*it).first == L - 1) cmp -= add(key.second, (*it).second);
}
it = now_del.lower_bound({L, -1});
while (it != now_del.end() && (*it).first <= R) {
cmp -= add((*it).second, key.second);
it++;
}
}
add_all += c[i];
curr += b[i] + add_all;
cout << curr << " " << cmp << '\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 10572kb
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: 285ms
memory: 20368kb
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:
wrong answer 10244th lines differ - expected: '156 6', found: '156 5'