QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#164240 | #7105. Pixel Art | physics0523 | WA | 626ms | 25368kb | C++23 | 4.1kb | 2023-09-04 20:51:51 | 2023-09-04 20:51:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using pi=pair<int,int>;
struct UnionFind {
vector<int> data;
UnionFind(int size) : data(size, -1) { }
bool unionSet(int x, int y) {
x = root(x); y = root(y);
if (x != y) {
if (data[y] < data[x]) swap(x, y);
data[x] += data[y]; data[y] = x;
}
return x != y;
}
bool findSet(int x, int y) {
return root(x) == root(y);
}
int root(int x) {
return data[x] < 0 ? x : data[x] = root(data[x]);
}
int size(int x) {
return -data[root(x)];
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while(t>0){
t--;
int n,m,k;
cin >> n >> m >> k;
vector<long long> rw(n+1,0);
set<vector<int>> sh;
set<vector<int>> sv;
vector<int> p(k),q(k),r(k),s(k);
vector<vector<int>> mem(n+1);
for(int i=0;i<k;i++){
int a,b,c,d;
cin >> a >> b >> c >> d;
a--;b--;c--;d--;
p[i]=a;
q[i]=b;
r[i]=c;
s[i]=d;
if(a==c){
rw[a]+=(d-b+1);
rw[a+1]-=(d-b+1);
sh.insert({a,b,c,d,i});
}
else{
rw[a]++;
rw[c+1]--;
sv.insert({b,a,d,c,i});
}
mem[a].push_back(i);
}
vector<vector<int>> vh,vv;
for(auto &nx : sh){vh.push_back(nx);}
for(auto &nx : sv){vv.push_back(nx);}
vector<vector<pair<int,int>>> unq(n+1);
for(auto &tg : vv){
// Vertical - Vertical
auto it=sv.lower_bound({tg[0]+1,tg[1],-1,-1,-1});
if(it!=sv.begin()){it--;}
while(it!=sv.end()){
vector<int> cur=(*it);
if(cur[0]>tg[0]+1){break;}
if(cur[0]<tg[0]+1){it++;continue;}
if(tg[3]<cur[1]){break;}
if(cur[3]<tg[1]){it++;continue;}
int upmost=max(cur[1],tg[1]);
unq[upmost].push_back({cur[4],tg[4]});
it++;
}
// Vertical - Horizontal
int x,y;
x=tg[1]-1;
y=tg[0];
{
auto it=sh.lower_bound({x,y+1,-1,-1,-1});
if(it!=sh.begin()){it--;}
if(it!=sh.end()){
vector<int> cur=(*it);
if(cur[0]==x && cur[1]<=y && y<=cur[3]){
unq[tg[1]].push_back({cur[4],tg[4]});
}
}
}
x=tg[3]+1;
y=tg[2];
{
auto it=sh.lower_bound({x,y+1,-1,-1,-1});
if(it!=sh.begin()){it--;}
if(it!=sh.end()){
vector<int> cur=(*it);
if(cur[0]==x && cur[1]<=y && y<=cur[3]){
unq[tg[3]+1].push_back({cur[4],tg[4]});
}
}
}
}
for(auto &tg : vh){
// Horizontal - Horizontal
auto it=sh.lower_bound({tg[0]+1,tg[1],-1,-1,-1});
if(it!=sh.begin()){it--;}
while(it!=sh.end()){
vector<int> cur=(*it);
if(cur[0]>tg[0]+1){break;}
if(cur[0]<tg[0]+1){it++;continue;}
if(tg[3]<cur[1]){break;}
if(cur[3]<tg[1]){it++;continue;}
int upmost=max(cur[0],tg[0]);
unq[upmost].push_back({cur[4],tg[4]});
it++;
}
// Horizontal - Vertical
int x,y;
x=tg[1]-1;
y=tg[0];
{
auto it=sv.lower_bound({x,y+1,-1,-1,-1});
if(it!=sv.begin()){it--;}
if(it!=sv.end()){
vector<int> cur=(*it);
if(cur[0]==x && cur[1]<=y && y<=cur[3]){
unq[tg[0]].push_back({cur[4],tg[4]});
}
}
}
x=tg[3]+1;
y=tg[2];
{
auto it=sv.lower_bound({x,y+1,-1,-1,-1});
if(it!=sv.begin()){it--;}
if(it!=sv.end()){
vector<int> cur=(*it);
if(cur[0]==x && cur[1]<=y && y<=cur[3]){
unq[tg[0]].push_back({cur[4],tg[4]});
}
}
}
}
long long r1=0;
int r2=0;
UnionFind uf(k);
for(int i=0;i<n;i++){
if(i){rw[i]+=rw[i-1];}
r1+=rw[i];
cout << r1 << " ";
r2+=mem[i].size();
for(auto &nx : unq[i]){
if(!uf.findSet(nx.first,nx.second)){
r2--;
uf.unionSet(nx.first,nx.second);
}
}
cout << r2 << "\n";
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3596kb
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: 626ms
memory: 25368kb
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 10124th lines differ - expected: '100 1', found: '100 50'