QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#209561 | #7105. Pixel Art | PetroTarnavskyi# | WA | 423ms | 29828kb | C++17 | 2.9kb | 2023-10-10 15:49:04 | 2023-10-10 15:49:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
struct DSU
{
int n;
VI p;
VI sz;
void init(int _n)
{
n = _n;
sz.assign(n, 1);
p.resize(n);
iota(ALL(p), 0);
}
int find(int v)
{
if(v == p[v])
return v;
return p[v] = find(p[v]);
}
bool unite(int u, int v)
{
u = find(u);
v = find(v);
if(u == v)
return false;
if(sz[u] > sz[v])
swap(u, v);
p[u] = v;
sz[v] += sz[u];
return true;
}
}D;
const int N = 1 << 17;
int r[N][2], c[N][2];
set<PII> xi;
int comp = 0;
void uni(int x, int i)
{
auto it = xi.lower_bound(MP(x, -1));
if(it != xi.begin() && prev(it)->F == x - 1)
{
if(D.unite(i, prev(it)->S))
comp--;
}
it = xi.upper_bound(MP(x, N));
if(it != xi.end() && it->F == x + 1)
{
if(D.unite(i, it->S))
comp--;
}
}
set<PII> lines[N];
void uniX(int row, int x, int i)
{
auto it = lines[row].lower_bound(MP(x, -1));
if(it == lines[row].end())
return;
int j = it->S;
if(c[j][0] <= x && x <= c[j][1])
{
if(D.unite(i, j))
comp--;
}
}
VI startVert[N], endVert[N], Hor[N];
void solve()
{
int n, m, k;
cin >> n >> m >> k;
FOR(i, 0, k)
{
FOR(t, 0, 2)
cin >> r[i][t] >> c[i][t];
if(c[i][0] != c[i][1])
{
Hor[r[i][0]].PB(i);
lines[r[i][0]].insert(MP(c[i][1], i));
}
else
{
startVert[r[i][0]].PB(i);
endVert[r[i][1]].PB(i);
}
}
D.init(k);
LL sum = 0;
FOR(i, 1, n + 1)
{
for(int id : startVert[i])
{
comp++;
uniX(i - 1, c[id][0], id);
uni(c[id][0], id);
xi.insert(MP(c[id][0], id));
}
sum += SZ(xi);
for(int id : Hor[i - 1])
{
uniX(i, c[id][0], id);
uniX(i, c[id][1], id);
}
for(int id : Hor[i])
{
comp++;
uni(c[id][0], id);
uni(c[id][1], id);
uniX(i - 1, c[id][0], id);
uniX(i - 1, c[id][1], id);
sum += c[id][1] - c[id][0] + 1;
xi.insert(MP(c[id][0], id));
xi.insert(MP(c[id][1], id));
}
for(int id : Hor[i])
{
xi.erase(MP(c[id][0], id));
xi.erase(MP(c[id][1], id));
}
for(int id : endVert[i])
{
xi.erase(MP(c[id][0], id));
uniX(i + 1, c[id][0], id);
}
cout << sum << " " << comp << "\n";
}
xi.clear();
comp = 0;
FOR(i, 0, n + 1)
{
startVert[i].clear();
endVert[i].clear();
Hor[i].clear();
lines[i].clear();
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(15);
int t;
cin >> t;
while(t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 19132kb
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: 423ms
memory: 29828kb
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 0 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 9th lines differ - expected: '100 50', found: '100 0'