QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#162347#7105. Pixel ArtzhouhuanyiAC ✓658ms93928kbC++142.9kb2023-09-03 10:38:362023-09-04 04:31:20

Judging History

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

  • [2023-09-04 04:31:20]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:658ms
  • 内存:93928kb
  • [2023-09-03 10:38:37]
  • 评测
  • 测评结果:100
  • 用时:636ms
  • 内存:93944kb
  • [2023-09-03 10:38:36]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<set>
#include<vector>
#define N 500000
using namespace std;
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
struct reads
{
	int r1,c1,r2,c2,num;
};
struct lines
{
	int l,r,num;
	bool operator < (const lines &t)const
	{
		return r<t.r;
	}
};
set<lines>s[N+1];
set<lines>s2[N+1];
int T,n,m,k,scnt,cnt[N+1],st[N+1],rt[N+1];
bool vis[N+1];
vector<reads>p[N+1];
vector<int>E[N+1];
int find(int x)
{
	if (rt[x]==x) return x;
	return rt[x]=find(rt[x]);
}
void unionn(int x,int y)
{
	rt[x]=y;
	return;
}
void adder(int x,int l,int r,int c)
{
	s[x].insert((lines){l,r,c});
	return;
}
void adder2(int x,int l,int r,int c)
{
	s2[x].insert((lines){l,r,c});
	return;
}
int query(int x,int y)
{
	if (x<0||x>n||y<0||y>m) return -1;
	auto it=s[x].lower_bound((lines){0,y,0});
	if (it!=s[x].end()&&(*it).l<=y) return (*it).num;
	it=s2[y].lower_bound((lines){0,x,0});
	if (it!=s2[y].end()&&(*it).l<=x) return (*it).num;
	return -1;
}
int main()
{
	int r1,c1,r2,c2,x,y;
	T=read();
	while (T--)
	{
		n=read(),m=read(),k=read(),scnt=0;
		for (int i=1;i<=n;++i) p[i].clear(),s[i].clear(),cnt[i]=st[i]=0;
		for (int i=1;i<=m;++i) s2[i].clear();
		for (int i=1;i<=k;++i)
		{
			r1=read(),c1=read(),r2=read(),c2=read(),p[min(r1,r2)].push_back((reads){r1,c1,r2,c2,i}),rt[i]=i,E[i].clear(),vis[i]=0;
			if (r1==r2) cnt[r1]+=c2-c1+1;
			else st[r1]++,st[r2+1]--;
		}
		for (int i=1;i<=n;++i) st[i]+=st[i-1],cnt[i]+=st[i];
		for (int i=1;i<=n;++i) cnt[i]+=cnt[i-1];
		for (int i=1;i<=n;++i)
			for (int j=0;j<p[i].size();++j)
			{
				if (p[i][j].r1==p[i][j].r2) adder(p[i][j].r1,p[i][j].c1,p[i][j].c2,p[i][j].num);
				else adder2(p[i][j].c1,p[i][j].r1,p[i][j].r2,p[i][j].num);
			}
		for (int i=1;i<=n;++i)
			for (int j=0;j<p[i].size();++j)
			{
				for (int op=-1;op<=1;++op)
					for (int op2=-1;op2<=1;++op2)
						if (abs(op)+abs(op2)==1&&query(p[i][j].r1+op,p[i][j].c1+op2)!=-1&&p[i][j].num!=query(p[i][j].r1+op,p[i][j].c1+op2))
						{
							x=p[i][j].num,y=query(p[i][j].r1+op,p[i][j].c1+op2);
							if (x<y) swap(x,y);
							E[x].push_back(y),E[y].push_back(x);
						}
				for (int op=-1;op<=1;++op)
					for (int op2=-1;op2<=1;++op2)
						if (abs(op)+abs(op2)==1&&query(p[i][j].r2+op,p[i][j].c2+op2)!=-1&&p[i][j].num!=query(p[i][j].r2+op,p[i][j].c2+op2))
						{
							x=p[i][j].num,y=query(p[i][j].r2+op,p[i][j].c2+op2);
							if (x<y) swap(x,y);
							E[x].push_back(y),E[y].push_back(x);
						}
			}
		for (int i=1;i<=n;++i)
		{
			for (int j=0;j<p[i].size();++j)
			{
				scnt++;
				for (int k=0;k<E[p[i][j].num].size();++k)
					if (find(E[p[i][j].num][k])!=find(p[i][j].num)&&vis[E[p[i][j].num][k]])
						unionn(find(E[p[i][j].num][k]),find(p[i][j].num)),scnt--;
				vis[p[i][j].num]=1;
			}
			printf("%d %d\n",cnt[i],scnt);
		}
	}
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 80564kb

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: 658ms
memory: 93928kb

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