QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#160311 | #7105. Pixel Art | ucup-team1191# | RE | 1ms | 3556kb | C++20 | 5.9kb | 2023-09-02 20:04:32 | 2023-09-02 20:04:33 |
Judging History
answer
/*
author: Maksim1744
created: 02.09.2023 14:45:16
*/
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sum(a) ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a) (*min_element((a).begin(), (a).end()))
#define maxe(a) (*max_element((a).begin(), (a).end()))
#define mini(a) ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a) ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
template<typename T> vector<T>& operator-- (vector<T> &v){for (auto& i : v) --i; return v;}
template<typename T> vector<T>& operator++ (vector<T> &v){for (auto& i : v) ++i; return v;}
template<typename T> istream& operator>>(istream& is, vector<T> &v){for (auto& i : v) is >> i; return is;}
template<typename T> ostream& operator<<(ostream& os, vector<T> v){for (auto& i : v) os << i << ' '; return os;}
template<typename T, typename U> pair<T,U>& operator-- (pair<T, U> &p){--p.first; --p.second; return p;}
template<typename T, typename U> pair<T,U>& operator++ (pair<T, U> &p){++p.first; ++p.second; return p;}
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U> &p){is >> p.first >> p.second; return is;}
template<typename T, typename U> ostream& operator<<(ostream& os, pair<T, U> p){os << p.first << ' ' << p.second; return os;}
template<typename T, typename U> pair<T,U> operator-(pair<T,U> a, pair<T,U> b){return mp(a.first-b.first, a.second-b.second);}
template<typename T, typename U> pair<T,U> operator+(pair<T,U> a, pair<T,U> b){return mp(a.first+b.first, a.second+b.second);}
template<typename T, typename U> void umin(T& a, U b){if (a > b) a = b;}
template<typename T, typename U> void umax(T& a, U b){if (a < b) a = b;}
#ifdef HOME
#define SHOW_COLORS
#include "/mnt/c/Libs/tools/print.cpp"
#else
#define show(...) void(0)
#define debugf(fun) fun
#define debugv(var) var
#define mclock void(0)
#define shows void(0)
#define debug if (false)
#define OSTREAM(...) ;
#define OSTREAM0(...) ;
#endif
struct Palka {
int r1, r2;
int c1, c2;
};
struct DSU {
vector<int> rk;
vector<int> p;
int comps;
int n;
DSU(int n = 1) : n(n) {
reset(n);
}
void reset(int n) {
comps = n;
p.resize(n);
iota(p.begin(), p.end(), 0);
rk.assign(n, 1);
}
int par(int v) {
return v == p[v] ? v : p[v] = par(p[v]);
}
bool un(int u, int v) {
u = par(u);
v = par(v);
if (u == v) return false;
if (rk[u] > rk[v]) swap(u, v);
p[u] = v;
rk[v] += rk[u];
--comps;
return true;
}
bool check(int u, int v) {
return par(u) == par(v);
}
};
void test_case(int test) {
int n, m, k;
cin >> n >> m >> k;
vector<Palka> palki(k);
for (int i = 0; i < k; ++i) {
auto& p = palki[i];
cin >> p.r1 >> p.c1 >> p.r2 >> p.c2;
--p.r1; --p.c1; --p.r2; --p.c2;
}
sort(palki.begin(), palki.end(), [](const auto& a, const auto& b) {
return a.r1 < b.r2;
});
DSU d(k);
set<pair<pair<int, int>, int>> st;
vector<int> ans_comps;
int ind = 0;
vector<vector<pair<pair<int, int>, int>>> dl(n + 1);
for (int i = 0; i < n; ++i) {
shows;
show(i);
vector<pair<pair<int, int>, int>> todo;
while (ind < k && palki[ind].r1 == i) {
const auto& p = palki[ind];
auto it = st.lower_bound({mp(p.c1, -1), -1});
if (it != st.begin() && prev(it)->first.second >= p.c1) --it;
while (it != st.end()) {
if (it->first.first > p.c2) break;
d.un(ind, it->second);
++it;
}
todo.eb(mp(p.c1, p.c2), ind);
dl[p.r2 + 1].eb(mp(p.c1, p.c2), ind);
++ind;
}
show(st, d.comps);
for (auto s : dl[i])
st.erase(s);
show(st, d.comps);
for (auto pr : todo) {
const auto& p = palki[pr.second];
auto it = st.lower_bound({mp(p.c1, -1), -1});
if (it != st.end() && it->first.first == p.c2 + 1)
d.un(it->second, ind);
if (it != st.begin() && prev(it)->first.second == p.c1 - 1)
d.un(prev(it)->second, ind);
}
show(st, d.comps);
sort(todo.begin(), todo.end(), [&](auto a, auto b) {
return a.first.first < b.first.first;
});
for (int i = 0; i + 1 < todo.size(); ++i)
if (todo[i].first.second + 1 == todo[i + 1].first.first)
d.un(todo[i].second, todo[i + 1].second);
show(st, d.comps);
for (auto p : todo)
st.insert(p);
show(st, d.comps);
ans_comps.pb(d.comps - (k - ind));
}
vector<ll> sz(n + 1);
for (auto p : palki) {
if (p.r1 == p.r2) continue;
sz[p.r1]++;
sz[p.r2 + 1]--;
}
for (int i = 1; i < sz.size(); ++i)
sz[i] += sz[i - 1];
for (auto p : palki) {
if (p.r1 != p.r2) continue;
sz[p.r1] += p.c2 - p.c1 + 1;
}
for (int i = 1; i < sz.size(); ++i)
sz[i] += sz[i - 1];
for (int i = 0; i < n; ++i) {
cout << sz[i] << ' ' << ans_comps[i] << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int T;
cin >> T;
for (int test = 1; test <= T; ++test) {
test_case(test);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3556kb
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
Runtime Error
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 ...