QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#226386#7105. Pixel Artfzj2007AC ✓254ms19320kbC++142.6kb2023-10-25 21:56:252023-10-25 21:56:25

Judging History

你现在查看的是最新测评结果

  • [2023-10-25 21:56:25]
  • 评测
  • 测评结果:AC
  • 用时:254ms
  • 内存:19320kb
  • [2023-10-25 21:56:25]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x){
	x=0;
	char ch=getchar();
	bool flag=0;
	while(ch>'9'||ch<'0') flag=flag||ch=='-',ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	x=flag?-x:x;
}
template<typename T,typename ...Args>inline void read(T &x,Args &...args){
	read(x),read(args...);
}
template<typename T>inline void prt(T x){
	if(x>9) prt(x/10);
	putchar(x%10+'0');
}
template<typename T>inline void put(T x){
	if(x<0) putchar('-'),x=-x;
	prt(x);
}
template<typename T>inline void put(char ch,T x){
	put(x),putchar(ch);
}
template<typename T,typename ...Args>inline void put(char ch,T x,Args ...args){
	put(ch,x),put(ch,args...);
}
#define N 100005
int n,m,k;
struct node{
	int l,r,id;
	node(int _l=0,int _r=0,int _id=0):l(_l),r(_r),id(_id){}
	inline bool operator<(const node &b)const{
		return l==b.l?r<b.r:l<b.l;
	}
};
vector<node> seg[N];
vector<node> ins[N],del[N]; 
int fa[N];
inline int getf(int x){
	return fa[x]==x?x:fa[x]=getf(fa[x]); 
}
inline bool merge(int x,int y){
	x=getf(x),y=getf(y);
	if(x==y) return 0;
	fa[x]=y;
	return 1;
}
inline void solve(){
	read(n,m,k);
	for(int i=1,a,b,c,d;i<=k;i++){
		read(a,b,c,d),fa[i]=i;
		if(a==c) seg[a].emplace_back(b,d,i);
		else ins[a].emplace_back(b,b,i),del[c+1].emplace_back(b,b,i);
	}
	multiset<node> s;
	long long ans1=0,ans2=0,num=0;
	for(int i=1;i<=n;i++){
		for(auto tmp:seg[i]){
			ans1+=tmp.r-tmp.l+1,ans2++;
			auto itl=s.lower_bound({tmp.l+1,0,0}),itr=s.lower_bound({tmp.r+1,0,0});
			if(itl!=s.begin()) itl--;
			while(itl!=itr){
				if(itl->r<tmp.l){
					itl++;
					continue;				
				}
				ans2-=merge(itl->id,tmp.id);
				itl++;
			}
		}
		for(auto tmp:ins[i]){
			num++,ans2++;
			auto it=s.lower_bound({tmp.l+1,0,0});
			if(it!=s.begin()&&(--it)->r>=tmp.l) ans2-=merge(it->id,tmp.id);
		}
		for(auto tmp:del[i]) num--,s.erase(tmp);
		for(auto tmp:seg[i-1]) s.erase(tmp);
		ans1+=num;
		for(auto tmp:seg[i]){
			auto itl=s.lower_bound({tmp.l,0,0}),itr=s.lower_bound({tmp.r+2,0,0});
			if(itl!=s.begin()) itl--;
			while(itl!=itr){
				if(itl->r<tmp.l-1){
					itl++;
					continue;				
				}
				ans2-=merge(itl->id,tmp.id);
				itl++;
			}
			s.insert(tmp);
		}
		for(auto tmp:ins[i]){
			auto it=s.lower_bound({tmp.l+1,0,0});
			if(it!=s.end()&&it->l==tmp.l+1) ans2-=merge(it->id,tmp.id);
			if(it!=s.begin()&&(--it)->r==tmp.l-1) ans2-=merge(it->id,tmp.id);
			s.insert(tmp);
		}
		put(' ',ans1),put('\n',ans2);
	}
	for(int i=1;i<=n+1;i++) seg[i].clear(),ins[i].clear(),del[i].clear();
}
int T;
int main(){
	read(T);
	while(T--) solve();
	return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 10852kb

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: 254ms
memory: 19320kb

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