Submission #1690914


Source Code Expand

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define L(__) (__ << 1)
#define R(__) (L(__)|1) 
#define LL long long
#define oo (1<<30)
#define N 300005
using namespace std;
int st1[N],top1,st2[N],top2;
int n,w,h,m,z[N],ans,A[4*N],add[4*N];
struct dot{
	int x,y;
	dot(int _x=0,int _y=0){ x=_x,y=_y;}
}a[N],b[N];
bool cmp(const dot &p,const dot &q){ return p.x<q.x||(p.x==q.x&&p.y<q.y);}
int map(int x){ return lower_bound(z+1,z+m+1,x)-z;}
void update(int t){ A[t]=max(A[L(t)],A[R(t)]);}
void build(int t,int l,int r)
{
	int mid=(l+r)>>1; add[t]=0;
	if(l==r){ A[t]=-z[l]; return ;}
	build(L(t),l,mid);
	build(R(t),mid+1,r);
	update(t);
}
void Add(int t,int d){ add[t]+=d,A[t]+=d;}
void push(int t)
{
	if(add[t]==0) return ;
	Add(L(t),add[t]);
	Add(R(t),add[t]);
	add[t]=0;
}
void modify(int t,int l,int r,int l1,int r1,int d)
{
	int mid=(l+r)>>1;
	if(l>r1||r<l1||l1>r1) return ;
	if(l>=l1&&r<=r1) return Add(t,d);
	push(t);
	modify(L(t),l,mid,l1,r1,d);
	modify(R(t),mid+1,r,l1,r1,d);
	update(t);
}
void solve(int n)
{
	int i,mi=(h>>1);
	for(i=1;i<=n;i++) a[i]=b[i];
	sort(a+1,a+n+1,cmp);
	if(a[n].x<w)
		a[++n]=dot(w,0);
	top1=top2=0;
	for(i=1;i<=n;i++) z[i]=a[i].x;
	m=n,z[++m]=0,z[++m]=w;
	sort(z+1,z+m+1);
	for(i=1;i<=n;i++)
		a[i].x=map(a[i].x);
	build(1,1,m);
	if(a[1].x>1)
		modify(1,1,m,1,1,h);
	a[0].x=1;
	for(i=1;i<=n;i++){
		if(a[i].y<=mi){
			modify(1,1,m,a[i].x,a[i].x,h);
			ans=max(ans,A[1]+z[a[i].x]);
			modify(1,1,m,a[st1[top1]].x,a[i].x-1,-a[i].y);
			while(top1&&a[st1[top1]].y<=a[i].y){
				modify(1,1,m,a[st1[top1-1]].x,a[st1[top1]].x-1,a[st1[top1]].y-a[i].y);
				top1--;
			  }
			st1[++top1]=i;
		  }
		else{
			modify(1,1,m,a[i].x,a[i].x,h);
			ans=max(ans,A[1]+z[a[i].x]);
			modify(1,1,m,a[st2[top2]].x,a[i].x-1,a[i].y-h);
			while(top2&&a[st2[top2]].y>=a[i].y){
				modify(1,1,m,a[st2[top2-1]].x,a[st2[top2]].x-1,a[i].y-a[st2[top2]].y);
				top2--;
			  }
			st2[++top2]=i;
		  }
	  }
}
int main()
{
	int i;
	scanf("%d %d %d",&w,&h,&n);
	for(i=1;i<=n;i++)
		scanf("%d %d",&b[i].x,&b[i].y);
	solve(n);
	for(i=1;i<=n;i++) swap(b[i].x,b[i].y);
	swap(w,h);
	solve(n);
	cout<<ans*2;
	return 0;
}

Submission Info

Submission Time
Task C - 1D Reversi
User Wuvin
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2277 Byte
Status WA
Exec Time 5 ms
Memory 12544 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:91:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&w,&h,&n);
                            ^
./Main.cpp:93:33: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&b[i].x,&b[i].y);
                                 ^

Judge Result

Set Name sample All
Score / Max Score 0 / 0 0 / 300
Status
AC × 1
WA × 2
AC × 4
WA × 11
Set Name Test Cases
sample sample_01.txt, sample_02.txt, sample_03.txt
All alternate_01.txt, alternate_02.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, same_01.txt, same_02.txt, sample_01.txt, sample_02.txt, sample_03.txt, small_01.txt, small_02.txt, small_03.txt
Case Name Status Exec Time Memory
alternate_01.txt WA 5 ms 12544 KB
alternate_02.txt WA 5 ms 12544 KB
random_01.txt WA 5 ms 12544 KB
random_02.txt WA 5 ms 12544 KB
random_03.txt WA 5 ms 12544 KB
random_04.txt WA 5 ms 12544 KB
random_05.txt WA 5 ms 12544 KB
same_01.txt AC 5 ms 12544 KB
same_02.txt AC 5 ms 12544 KB
sample_01.txt WA 5 ms 12544 KB
sample_02.txt AC 5 ms 12544 KB
sample_03.txt WA 5 ms 12544 KB
small_01.txt AC 5 ms 12544 KB
small_02.txt WA 5 ms 12544 KB
small_03.txt WA 5 ms 12544 KB