QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#161200#7105. Pixel Artucup-team1732#WA 453ms18972kbC++143.4kb2023-09-02 22:58:472023-09-02 22:58:48

Judging History

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

  • [2023-09-02 22:58:48]
  • 评测
  • 测评结果:WA
  • 用时:453ms
  • 内存:18972kb
  • [2023-09-02 22:58:47]
  • 提交

answer

// created:  Sep/02/2023 22:19:28
#include<cstdio>
#include<vector>
#include<set>
#define F(i,l,r) for(int i=l,i##_end=r;i<i##_end;++i)
using namespace std;
template<typename T>void readmain(T &x)
{
	bool neg=false;
	unsigned int c=getchar();
	for(;(c^48)>9;c=getchar())if(c=='-')neg=true;
	for(x=0;(c^48)<10;c=getchar())x=(x<<3)+(x<<1)+(c^48);
	if(neg)x=-x;
}
template<typename T>T& read(T &x){readmain(x);return x;}
template<typename T,typename ...Tr>void read(T &x,Tr&... r){readmain(x);read(r...);}
constexpr int N=1e5+5,INF=0x3f3f3f3f;
int tt,n,m,k,x[N],l[N],r[N],f[N];
int find(int u){return f[u]==u?u:f[u]=find(f[u]);}
vector<int> a[N],b0[N],b1[N];
set<pair<int,int>> s,t;
int main()
{
	read(tt);
	while(tt--)
	{
		read(n,m,k);
		F(i,0,k)
		{
			int r1,c1,r2,c2;read(r1,c1,r2,c2);--r1,--c1,--r2,--c2;
			if(r1==r2)
			{
				x[i]=r1;
				l[i]=c1,r[i]=c2+1;
				a[r1].emplace_back(i);
			}
			else
			{
				x[i]=c1;
				l[i]=r1,r[i]=r2+1;
				b0[l[i]].emplace_back(i);
				b1[r[i]].emplace_back(i);
			}
			f[i]=i;
		}
		int ans=0;
		long long sum=0,cur=0;
		s.clear();
		F(i,0,n)
		{
			cur+=b0[i].size()-b1[i].size();
			sum+=cur;
			ans+=(int)b0[i].size()+(int)a[i].size();
			for(int j:a[i])sum+=r[j]-l[j];
			if(i)
			{
				for(int j:a[i])
				{
					auto il=t.lower_bound({l[j],-INF});
					auto ir=t.lower_bound({r[j],-INF});
					for(auto it=il;it!=ir;++it)
					{
						int v=it->second;
						if(find(j)!=find(v))--ans,f[find(j)]=find(v);
					}
				}
			}
			for(int j:b0[i])
			{
				auto it=t.lower_bound({x[j],-INF});
				if(it!=t.end())
				{
					int v=it->second;
					if(x[j]==x[v]&&find(j)!=find(v))--ans,f[find(j)]=find(v);
				}
			}
			for(int j:b0[i])t.emplace(x[j],j);
			for(int j:b1[i])t.erase({x[j],j});
			for(int j:a[i])
			{
				auto it=t.lower_bound({l[j],0});
				if(it!=t.begin())
				{
					int v=prev(it)->second;
					if(x[v]==l[j]-1&&find(j)!=find(v))--ans,f[find(j)]=find(v);
				}
				if(it!=t.end())
				{
					int v=it->second;
					if(x[v]==r[j]&&find(j)!=find(v))--ans,f[find(j)]=find(v);
				}
			}
			for(int j:b0[i])
			{
				auto it=t.find({x[j],j});
				if(it!=t.begin())
				{
					int v=prev(it)->second;
					if(x[v]==x[j]-1&&find(j)!=find(v))--ans,f[find(j)]=find(v);
				}
				if(next(it)!=t.end())
				{
					int v=next(it)->second;
					if(x[v]==x[j]+1&&find(j)!=find(v))--ans,f[find(j)]=find(v);
				}
			}
			if(!a[i].empty())for(auto it=a[i].begin();next(it)!=a[i].end();++it)
			{
				if(r[*it]==l[*next(it)])
				{
					int u=*it,y=*next(it);
					if(find(u)!=find(y))--ans,f[find(u)]=find(y);
				}
			}
			if(i)
			{
				for(int j:b0[i])
				{
					auto it=s.lower_bound({x[j],INF});
					if(it!=s.begin())
					{
						--it;
						int v=it->second;
						if(x[j]<r[v]&&find(j)!=find(v))--ans,f[find(j)]=find(v);
					}
				}
				for(int j:a[i])
				{
					auto it=s.lower_bound({l[j],INF});
					if(it!=s.begin())
					{
						int v=prev(it)->second;
						if(l[j]<r[v]&&find(j)!=find(v))--ans,f[find(j)]=find(v);
					}
				}
				for(int j:a[i-1])
				{
					auto it=s.lower_bound({l[j],INF});
					if(it!=s.begin())
					{
						int v=prev(it)->second;
						if(l[j]<r[v]&&find(j)!=find(v))--ans,f[find(j)]=find(v);
					}
				}
			}
			s.clear();
			for(int j:a[i])s.emplace(l[j],j);
			printf("%lld %d\n",sum,ans);
		}
		F(i,0,n+1)a[i].clear(),b0[i].clear(),b1[i].clear();
	}
	return 0;
}

详细

Test #1:

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

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: 453ms
memory: 18972kb

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 114th lines differ - expected: '5 5', found: '5 3'