QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#169378 | #7105. Pixel Art | kjhhjki# | AC ✓ | 406ms | 72260kb | C++20 | 2.0kb | 2023-09-09 13:23:45 | 2023-09-09 13:23:47 |
Judging History
answer
#include <bits/stdc++.h>
#define MAXN 1100006
#define For(I,A,B) for(int I = A; I <= B; ++I)
#define foR(I,A,B) for(int I = A; I >= B; --I)
using namespace std;
typedef long long _ll;
typedef pair<int,int> pii;
int tot,pre[MAXN];
int find(int x) { return pre[x] == x ? x : pre[x] = find(pre[x]); }
void merge(int x,int y)
{
x = find(x); y = find(y);
if(x == y) return;
pre[x] = y; --tot;
}
vector<int> add[MAXN],del[MAXN];
_ll T,n,m,k,ans,res,r1[MAXN],r2[MAXN],c1[MAXN],c2[MAXN];
void solve()
{
cin >> n >> m >> k; res = ans = tot = 0; map<pii,int> mp;
For(i,1,n+1) add[i].clear(), del[i].clear();
For(i,1,k)
{
pre[i] = i;
cin >> r1[i] >> c1[i] >> r2[i] >> c2[i];
add[r1[i]].push_back(i); del[r2[i]+1].push_back(i);
}
For(i,1,n)
{
for(auto id : add[i])
{
auto it = mp.lower_bound(pii(c1[id],0));
if(it != mp.begin()) --it;
while(it != mp.end() && it->first.first <= c2[id])
{
if(it->first.second >= c1[id]) merge(it->second,id);
++it;
}
}
for(auto id : del[i])
res -= c2[id] - c1[id] + 1, mp.erase(pii(c1[id],c2[id]));
for(auto id : add[i])
{
res += c2[id] - c1[id] + 1;
mp[pii(c1[id],c2[id])] = id;
auto it = mp.find(pii(c1[id],c2[id]));
if(it != mp.begin())
{
--it;
if(it->first.second >= c1[id]-1) merge(it->second,id);
++it;
}
if(it != mp.end())
{
++it;
if(it != mp.end() && it->first.first <= c2[id]+1)
merge(it->second,id);
}
}
cout << (ans += res) << ' ' << (tot += add[i].size()) << '\n';
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> T;
while(T--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 8ms
memory: 64996kb
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: 0
Accepted
time: 406ms
memory: 72260kb
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:
ok 355756 lines
Extra Test:
score: 0
Extra Test Passed