[杂题 模拟] BZOJ 1182 [Croatian2009]PLAHTE
来源:互联网 发布:mac windows 双系统 编辑:程序博客网 时间:2024/06/06 00:29
直接把所有矩形对应的加速度累加就好了
#include<cstdio>#include<cstdlib>#include<algorithm>using namespace std;typedef long long ll;inline char nc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}inline void read(int &x){ char c=nc(),b=1; for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1; for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;}const int N=1000005;int x1,y1,x2,y2;inline ll square(int t){ ll x=min(t,x2)-max(-t,x1)+1,y=min(t,y2)-max(-t,y1)+1; return (x<=0 || y<=0)?0:x*y;}int a[N],a2[N],a4[N],b[N];inline void modify(int t1,int t2){ ll p0=square(t1-1),p1=square(t1),p2=square(t1+1); a[t1]+=p1-p0; a[t2]-=p1-p0; if (t2>t1+1){ ll v=p2-2*p1+p0; a[t2]-=v*(t2-t1); if(v==2) a2[t1]++,a2[t2]--; if(v==4) a4[t1]++,a4[t2]--; }}int n,Q;int main(){ int q[20]; freopen("t.in","r",stdin); freopen("t.out","w",stdout); read(n); for (int i=1;i<=n;i++){ read(x1); read(y1); read(x2); read(y2); for (int d=-1,cnt=0;d<=1;d++){ q[++cnt]=abs(x1+d),q[++cnt]=abs(x2+d); q[++cnt]=abs(y1+d),q[++cnt]=abs(y2+d); } sort(q+1,q+12+1); for (int i=2;i<=12;i++) modify(q[i-1],q[i]); } read(Q); int Mx=0; for (int i=1;i<=Q;i++) read(x1),b[x1]=1,Mx=max(Mx,x1); ll res=0,add=0,k2=0,k4=0; for (int i=0;i<=Mx;i++){ res+=add+=a[i]; add+=2*(k2+=a2[i])+4*(k4+=a4[i]); if (b[i]) printf("%lld\n",res); } return 0;}
0 0
- [杂题 模拟] BZOJ 1182 [Croatian2009]PLAHTE
- BZOJ1182 Croatian2009 PLAHTE
- [贪心 模拟 + 二分答案 DP] BZOJ 1181 [CROATIAN2009]IZBROI选举
- bzoj 1180: [CROATIAN2009]OTOCI
- BZOJ 1180: [CROATIAN2009]OTOCI
- BZOJ 1180: [CROATIAN2009]OTOCI
- bzoj 1180 [CROATIAN2009]OTOCI - LCT
- 【BZOJ 1180】[CROATIAN2009]OTOCI LCT
- BZOJ 1180 CROATIAN2009 OTOCI Link-Cut-Tree
- BZOJ 1180: [CROATIAN2009]OTOCI|动态树
- bzoj 1180: [CROATIAN2009]OTOCI link cut tree
- BZOJ 1180: [CROATIAN2009]OTOCI (LCT题解)
- BZOJ 1180 [CROATIAN2009]OTOCI Link Cut Trees
- BZOJ 1088 水模拟
- bzoj 4029 定价|模拟
- [NOI2016模拟5.14]BZOJ
- BZOJ 3680 模拟退火
- BZOJ 3680 模拟退火
- 机器学习领域著名的期刊与会议
- error processing package libapache2-mod-php5 (–configure)
- CoreText(图文混排)详解+Demo
- c++模拟实现string
- Unity3D学习(4)之分离动作管理器的3D版牧师与魔鬼
- [杂题 模拟] BZOJ 1182 [Croatian2009]PLAHTE
- 《编程之法》:荷兰国旗
- Centos 7 安装 Xen
- 判断一个数是否为素数(反证法)
- WebMagic写的网络爬虫
- [ZJOI2815]灾难 建树+动态LCA+树上dp
- org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: XXX的解决方案
- 什么是硬件加速?GPU
- 常见的排序算法