QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#425051 | #7105. Pixel Art | HHH666 | WA | 2ms | 9276kb | C++14 | 3.2kb | 2024-05-29 21:46:29 | 2024-05-29 21:46:29 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define i1 __int128
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define ep emplace
#define eb emplace_back
#define all(v) v.begin(), v.end()
using namespace std;
template<typename types>
void read(types &x) {
x = 0; char c = getchar(); int f = 1;
while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); }
while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
x *= f; return;
}
void read() {}
template<typename types, typename... Args>
void read(types &x, Args&... args) {
read(x), read(args...);
return;
}
template<typename types>
void write(types x) {
if (x < 0) putchar('-'), x = -x;
types k = x / 10;
if (k) write(k);
putchar(x - k * 10 + '0');
return;
}
void print() { puts(""); }
template<typename types, typename... Args>
void print(types x, Args... args) {
write(x), putchar(' '), print(args...);
return;
}
const int MAXN = 1e5 + 10;
int n, m, k;
struct Segment {
int l, r, id;
Segment(int l, int r, int id) : l(l), r(r), id(id) {}
bool operator < (const Segment &x) const {
return l < x.l;
}
};
vector<Segment> seg[MAXN], del[MAXN];
set<Segment> s;
ll sum[MAXN];
int pa[MAXN];
int mx[MAXN];
auto getit(int l, int r) {
auto itl = prev(s.upper_bound(Segment(l, 0, 0)));
auto itr = s.upper_bound(Segment(r, 0, 0));
if (itl -> r < l) ++itl;
return mp(itl, itr);
}
int find(int x) { return x == pa[x] ? x : pa[x] = find(pa[x]); }
bool merge(int x, int y) {
x = find(x), y = find(y);
if (x == y) return false;
pa[x] = y, mx[y] = max(mx[y], mx[x]); return true;
}
void solve() {
read(n, m, k);
s.clear();
for (int i = 1; i <= n; ++i) seg[i].clear(), del[i].clear(), sum[i] = 0;
for (int i = 1; i <= k; ++i) mx[i] = 0;
iota(pa + 1, pa + k + 1, 1);
for (int i = 1; i <= k; ++i) {
int x1, y1, x2, y2; read(x1, y1, x2, y2);
mx[i] = x2;
seg[x1].eb(y1, y2, i);
del[x2 + 1].eb(y1, y2, i);
sum[x1] += (y2 - y1 + 1);
sum[x2 + 1] -= (y2 - y1 + 1);
}
ll tot = 0;
int ex = 0, now = 0;
s.ep(-1, -1, -1), s.ep(m + 10, m + 10, -1);
for (int i = 1; i <= n; ++i) {
sum[i] += sum[i - 1];
tot += sum[i];
for (auto j : seg[i]) {
set<Segment>::iterator itl, itr; tie(itl, itr) = getit(j.l, j.r);
for (auto it = itl; it != itr; ++it)
now -= merge(it -> id, j.id);
}
for (auto j : del[i])
if (mx[find(j.id)] == i - 1) ++ex, --now, mx[find(j.id)] = INT_MAX;
for (auto j : del[i]) s.erase(s.lower_bound(j));
for (auto j : seg[i]) s.ep(j), ++now;
for (auto j : seg[i]) {
auto it = s.lower_bound(j);
if (prev(it) -> r + 1 == it -> l) now -= merge(prev(it) -> id, it -> id);
if (it -> r + 1 == next(it) -> l) now -= merge(it -> id, next(it) -> id);
}
print(tot, ex + now);
}
return;
}
int main() {
int t; read(t);
while (t--) solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 9276kb
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:
wrong answer 1st lines differ - expected: '2 1', found: '2 1 '