Submission #18882845


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
const int max_m=2e5+5;
struct point
{
	int x,y;
}p[max_m];
const int max_h=2e5+5;
const int max_w=2e5+5;
int a[max_h],b[max_w];
struct node
{
	int id,len;
}q[max_h];
bool cmp(node x,node y)
{
	return x.len<y.len;
}
int C[max_h];
inline void modify(int k,int v)
{
	if(k<=0)
		return;
	for(int i=k;i<=2e5;i+=i&(-i))
		C[i]+=v;
}
inline int query(int k)
{
	int res=0;
	for(int i=k;i>0;i-=i&(-i))
		res+=C[i];
	return res;
}
int main()
{
	int h,w,m;
	scanf("%d%d%d",&h,&w,&m);
	for(int i=1;i<=m;++i)
		scanf("%d%d",&p[i].x,&p[i].y);
	for(int i=1;i<=h;++i)
		a[i]=w;
	for(int i=1;i<=w;++i)
		b[i]=h;
	for(int i=1;i<=m;++i)
	{
		a[p[i].x]=min(a[p[i].x],p[i].y-1);
		b[p[i].y]=min(b[p[i].y],p[i].x-1);
	}
	int c=a[1],d=b[1];
	long long ans=0;
	for(int i=1;i<=d;++i)
		ans+=a[i];
	for(int i=1;i<=c;++i)
	{
		q[i].id=i;
		q[i].len=b[i];
	}
	sort(q+1,q+c+1,cmp);
	int len_now=1;
	for(int i=1;i<=c;++i)
	{
		while(len_now<=d&&len_now<=q[i].len)
		{
			modify(a[len_now++],1);
		}
		ans+=q[i].len-query(2e5)+query(q[i].id-1);
	}
	cout<<ans<<endl;
	return 0;
}

Submission Info

Submission Time
Task F - Rook on Grid
User wsyhb
Language C++ (GCC 9.2.1)
Score 600
Code Size 1163 Byte
Status AC
Exec Time 67 ms
Memory 9232 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:37:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   37 |  scanf("%d%d%d",&h,&w,&m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
./Main.cpp:39:8: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   39 |   scanf("%d%d",&p[i].x,&p[i].y);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 29
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
hand_01.txt AC 24 ms 6592 KB
hand_02.txt AC 18 ms 6664 KB
hand_03.txt AC 2 ms 4456 KB
hand_04.txt AC 4 ms 4340 KB
hand_05.txt AC 2 ms 3704 KB
hand_06.txt AC 2 ms 3696 KB
random_01.txt AC 67 ms 9156 KB
random_02.txt AC 46 ms 7452 KB
random_03.txt AC 44 ms 7720 KB
random_04.txt AC 66 ms 9096 KB
random_05.txt AC 64 ms 9232 KB
random_06.txt AC 54 ms 8116 KB
random_07.txt AC 54 ms 8088 KB
random_08.txt AC 19 ms 7556 KB
random_09.txt AC 16 ms 7536 KB
random_10.txt AC 18 ms 7572 KB
random_11.txt AC 35 ms 5232 KB
random_12.txt AC 37 ms 5272 KB
random_13.txt AC 37 ms 5264 KB
random_14.txt AC 35 ms 5248 KB
random_15.txt AC 38 ms 5248 KB
random_16.txt AC 32 ms 5272 KB
random_17.txt AC 34 ms 5268 KB
random_18.txt AC 2 ms 3712 KB
random_19.txt AC 2 ms 3672 KB
random_20.txt AC 2 ms 3712 KB
sample_01.txt AC 7 ms 3564 KB
sample_02.txt AC 2 ms 3676 KB
sample_03.txt AC 21 ms 6780 KB