D:首先考虑如果给定白棋位置,如何判断胜负。黑棋获胜需要四个方向都有能贴上白棋的棋子。由于每一轮都必须移动,显然先对平面黑白染色一下,只有与白棋所在格异色的黑棋才需要考虑。考虑让一个黑棋去贴上白棋某个方向,那么能贴上的条件是该方向坐标之差>另一方向坐标之差。因为如果其往这边逃的话,这样才有足够的时间冲过去拦住。若往其他方向逃,只要模仿其动作即可,处于逃跑方向的棋子会对其作出制裁。

  可以发现每个黑棋对每个位置的白棋都只有一种能将其锁死的方向,四个方向的分界线形成一个X形。于是现在要数的是被任意四个黑棋的不同方向包含的白棋数量。

  斜着的东西很难考虑,把坐标系旋转一下45°,分界线就变成了一个十字形,就看起来非常舒服了。这样的话扫描线扫过去,维护线两边的黑棋纵坐标上下界,两边上界取min下界取max即可得到该直线上的被锁死的白棋纵坐标上下界。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 100010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,u,v,mx[N],mn[N];
ll ans;
struct data
{
int x,y;
bool operator <(const data&a) const
{
return x<a.x;
}
}a[N],b[N];
void solve(data *a,int n)
{
for (int i=1;i<=n;i++)
{
int x=a[i].x,y=a[i].y;
a[i].x=y-x,a[i].y=x+y;
}
sort(a+1,a+n+1);
//for (int i=1;i<=n;i++) cout<<a[i].x<<' '<<a[i].y<<endl;
mx[n+1]=-N,mn[n+1]=N;
for (int i=n;i>=1;i--) mx[i]=max(mx[i+1],a[i].y),mn[i]=min(mn[i+1],a[i].y);
int MX=-N,MN=N;
int cur=0;
for (int i=a[1].x;i<=a[n].x;i++)
{
while (cur<n&&i==a[cur+1].x) cur++,MX=max(MX,a[cur].y),MN=min(MN,a[cur].y);
ans+=max(min(MX,mx[cur+1])-max(MN,mn[cur+1]),0);
}
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("d.in","r",stdin);
freopen("d.out","w",stdout);
#endif
n=read();
for (int i=1;i<=n;i++)
{
int x=read(),y=read();
if ((x+y)%2) a[++u].x=x,a[u].y=y;
else b[++v].x=x,b[v].y=y;
}
solve(a,u);solve(b,v);
cout<<ans/4;
return 0;
//NOTICE LONG LONG!!!!!
}

  E:将每个限制存储在其右端点上,记录最靠右的li,0、li,1表示li,j到i至少要有一个j。设f[i][0/1]为第i位是0/1且满足所有右端点在i及i之前的限制的序列数量。转移考虑枚举最后一段连续0/1有多长,不妨考虑0,即有f[i][0]=Σf[j][1] (j>=max{lj~i,1})。前缀和一下,二分一下转移的最远点(直接移动指针难以更新max{l}),即可做到O(klogk)。

  注意到当一个点不存在限制时,f[i][0]=f[i][1]=f[i-1][0]+f[i-1][1]。如果连续一段没有限制,dp值会构成公比2的等比数列。于是考虑离散化后dp。然后应该和上面的dp没有什么太大的区别。

  可是为什么想想就很难写啊。咕咕咕。有缘再补(?)

Codeforces Round #468 Div. 1的更多相关文章

  1. Codeforces Round #468 Div. 2题解

    A. Friends Meeting time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  2. Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)B. World Cup

    The last stage of Football World Cup is played using the play-off system. There are n teams left in ...

  3. Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)

    A.B都是暴力搞一搞. A: #include<bits/stdc++.h> #define fi first #define se second #define mk make_pair ...

  4. codeforces 930b//Game with String// Codeforces Round #468 (Div. 1)

    题意:一个串,右循环移位后,告诉你第一个字母,还能告诉你一个,问你能确定移位后的串的概率. 用map记录每个字母出现的位置.对于每个字母,用arr[j][k]记录它的所有出现位置的后j位是字母k的个数 ...

  5. Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)D. Peculiar apple-tree

    In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity ...

  6. Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)C. Laboratory Work

    Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some v ...

  7. Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)A. Friends Meeting

    Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the ...

  8. Codeforces Round #468 (Div. 2 )D. Peculiar apple-tree_BFS

    题目简单,不多解释. Code: #include<cstdio> #include<queue> using namespace std; const int maxn = ...

  9. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

随机推荐

  1. React 与 React Native 底层共识:React 是什么

    此系列文章将整合我的 React 视频教程与 React Native 书籍中的精华部分,给大家介绍 React 与 React Native 结合学习的方法,此小节主要介绍 React 的底层原理与 ...

  2. websockect外网无法访问问题

    项目在测试环境可以正常使用websockect,然而把项目发布到公网上却无法使用问题. 有几种解决方案,1.防火墙未加入入站规则,否则没有权限连接到外网. 方法:控制面板--window防火墙---高 ...

  3. Go源码编译安装

    参考文档1:https://www.cnblogs.com/majianguo/p/7258975.html 参考文档2:http://www.loongson.cn/news/company/456 ...

  4. 20分钟 看图手写的table

    <html><body><table width="100%" border="1" cellspacing="0&qu ...

  5. 上传图片(photoClip)

    首先我们需要引入4个js包(这4个包总共106.6KB) <script src="__STATIC__/hammer.min.js" ></script> ...

  6. Docker实现运行tomcat并部署项目war包,并实现挂载目录

    之前写的有点乱,现在再来整理一下docker的简单部署运行 借鉴博客:https://blog.csdn.net/qq_32351227/article/details/78673591 一.dock ...

  7. 给定一个数组,求如果排序之后,相邻两数的最大差值,要求时间复杂度为O(N),且要求不能用非基于比较的排序

    题目: 给定一个数组,求如果排序之后,相邻两数的最大差值,要求时间复杂度为O(N),且要求不能用非基于比较的排序 public static int maxGap(int nums[]) { if ( ...

  8. django migrate报错(提前删除表等)

    python3 manage.py makemigrations python3 manage.py migrate ##报错 改为##更改migrates的状态 python3 manage.py ...

  9. centso7 安装redmine

    一.安装rvm ###安装rvm gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D3 ...

  10. centos7根分区扩容(亲测有效)

    root@haojftest:~# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/centos_test2-root 28G 14G 15G % / devtmpfs ...