QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#176739 | #7105. Pixel Art | pengpeng_fudan | RE | 0ms | 15328kb | C++14 | 2.0kb | 2023-09-11 23:01:44 | 2023-09-11 23:01:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
using ll=long long;
int fa[100010];
int l[100010],r[100010];
int get(int x){return x==fa[x]?x:fa[x]=get(fa[x]);}
void merge(int x,int y){
x=get(x),y=get(y);
fa[x]=y;
}
struct node{
int l,num;
bool operator<(node a)const{
return l<a.l;
}
};
set<node> st[100010];
vector<int> ve[100010][2];
vector<int> ln[100010];
int ln_num[100010];
int bla=0,len=0,stk=0;
int n,m,k;
void ope(int x,int num){
if(x!=0&&ln_num[x-1]&&get(ln_num[x-1])!=get(num)){stk--;merge(ln_num[x-1],num);}
if(x!=m&&ln_num[x+1]&&get(ln_num[x+1])!=get(num)){stk--;merge(ln_num[x+1],num);}
}
void ope_hi(int x,int y){
if(x==1) return ;
auto m=prev(st[x-1].lower_bound({l[y]}));auto n=st[x-1].upper_bound({r[y]});
while(1){
if(m==n) break;
if(r[m->num]>=l[y]){
if(get(m->num)!=get(y)){
stk--;
merge(m->num,y);
}
}
m++;
}
}
void solve() {
bla=len=stk=0;
cin>>n>>m>>k;
for(int i=1;i<=n;i++){
st[i].clear();
ln[i].clear(),ve[i][0].clear(),ve[i][1].clear();
}
fill(ln_num+1,ln_num+m+1,0);
int a,b,c,d;
for(int i=1;i<=k;i++){
fa[i]=i;
cin>>a>>b>>c>>d;
if(a==c){
l[i]=b,r[i]=d;
ln[a].push_back(i);
st[a].insert({b,i});
}
else{
l[i]=r[i]=b;
ve[a][0].push_back(i);
ve[c][1].push_back(i);
}
}
//cout<<st[1].lower_bound({2})->l<<'\n';
for(int i=1;i<=n;i++){
for(auto j:ve[i][0]){
len++;stk++;
ln_num[l[j]]=j;
ope(l[j],j);
ope_hi(i,j);
}
int pre=0;
for(auto j:st[i]){
stk++;
bla+=r[j.num]-l[j.num]+1;
ope_hi(i,j.num);
ope(l[j.num],j.num);
ope(r[j.num],j.num);
if(pre!=0&&r[pre]==l[j.num]-1){
if(get(pre)!=get(j.num)){
stk--;
merge(pre,j.num);
}
}
pre=j.num;
}
bla+=len;
cout<<bla<<' '<<stk<<'\n';
for(auto j:ve[i][1]){
len--;
ln_num[l[j]]=0;
st[i].insert({l[j],j});
}
}
}
int main() {
ios::sync_with_stdio(0),cin.tie(0);
int _ = 1;
cin >> _;
while(_--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 15328kb
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 ...