cf 755D. PolandBall and Polygon
题意:把一个多边形往里面连对角线,然后问每次添加多边形被划分为几个部分
产生的部分就是新加对角线与原有对角线相交条数+1,用线段树(大雾)维护一下。
#include<bits/stdc++.h>
#define LL long long
#define N 100005
#define lowbit(x) x&(-x)
using namespace std;
inline LL ra()
{
LL x=,f=; char ch=getchar();
while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
return x*f;
}
LL n,k;
struct node{
LL tag,sum,l,r;
}t[N<<];
LL T,ans=;
void build(LL k, LL l, LL r)
{
t[k].l=l; t[k].r=r;
if (l==r) return;
LL mid=l+r>>;
build(k<<,l,mid); build(k<<|,mid+,r);
}
void update(LL k)
{
t[k].sum=t[k<<].sum+t[k<<|].sum;
}
void pushdown(LL k)
{
LL tmp=t[k].tag; t[k].tag=;
t[k<<].tag+=tmp; t[k<<|].tag+=tmp;
t[k<<].sum+=(t[k<<].r-t[k<<].l+)*tmp;
t[k<<|].sum+=(t[k<<|].r-t[k<<|].l+)*tmp;
}
void change(LL k, LL x, LL y, LL val)
{
if (x>y || y>n) return;
LL l=t[k].l,r=t[k].r;
if (l==x && y==r)
{
t[k].tag+=val;
t[k].sum+=(r-l+)*val;
return;
}
if (t[k].tag) pushdown(k);
LL mid=l+r>>;
if (y<=mid) change(k<<,x,y,val);
else if (x>mid) change(k<<|,x,y,val);
else{
change(k<<,x,mid,val);
change(k<<|,mid+,y,val);
}
update(k);
}
LL ask(LL k, LL x, LL y)
{
if (x>y || y>n) return ;
LL l=t[k].l,r=t[k].r;
if (x==l && y==r) return t[k].sum;
if (t[k].tag) pushdown(k);
LL mid=l+r>>;
if (y<=mid) return ask(k<<,x,y);
else if (x>mid) return ask(k<<|,x,y);
else return ask(k<<,x,mid)+ask(k<<|,mid+,y);
}
int main()
{
LL last=,aim;
T=n=ra(); k=ra();
if (k>n/) k=n-k;
build(,,n);
while (T--)
{
LL aim=(last+k-)%n+;
if (aim>last)
{
ans+=ask(,last+,aim-)+;
change(,last,last,);
change(,aim,aim,);
}
else
{
ans+=ask(,last+,n)+ask(,,aim-)+;
change(,last,last,); change(,aim,aim,);
}
last=aim;
printf("%I64d ",ans);
// cout<<ask(2); system("pause");
}
return ;
}
cf 755D. PolandBall and Polygon的更多相关文章
- codeforces 755D. PolandBall and Polygon
D. PolandBall and Polygon time limit per test 4 seconds memory limit per test 256 megabytes input st ...
- codeforces 755D. PolandBall and Polygon(线段树+思维)
题目链接:http://codeforces.com/contest/755/problem/D 题意:一个n边形,从1号点开始,每次走到x+k的位置如果x+k>n则到x+k-n的位置,问每次留 ...
- CodeForces 755D PolandBall and Polygon ——(xjbg)
每次连线,起点和终点之间,每一个被点亮的点,这些点都能连出去两条线,因此可以增加的块数+2(1这个点除外,因为只有连出的点没有连进的点),计算起点和终点之间有几个点被点亮即可,然后1这个点特判一下.感 ...
- 【codeforces 755D】PolandBall and Polygon
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces 755D:PolandBall and Polygon(思维+线段树)
http://codeforces.com/problemset/problem/755/D 题意:给出一个n正多边形,还有k,一开始从1出发,向第 1 + k 个点连一条边,然后以此类推,直到走完 ...
- D. PolandBall and Polygon BIT + 欧拉公式
http://codeforces.com/contest/755/problem/D // 我也觉得非平面图不能用欧拉公式,但是也能过,不知道为什么.求大佬留言. 这题其实就是平面图,因为它有很多个 ...
- 【树状数组】Codeforces Round #755 D. PolandBall and Polygon
http://codeforces.com/problemset/problem/755/D 每次新画一条对角线的时候,考虑其跨越了几条原有的对角线. 可以用树状数组区间修改点查询来维护多边形的顶点. ...
- CF EC 87 div2 1354 C2 Not So Simple Polygon Embedding 计算几何 结论
LINK:Not So Simple Polygon Embedding 搞了好久终于搞会了. 错误原因 没找到合适算边长的方法 要么就是边长算的时候算错了. 几何学的太差了 最后虽然把十边形的和六边 ...
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
随机推荐
- string简单成员函数的实现
原文:https://blog.csdn.net/zcyzsy/article/details/52146124 #include<iostream> using namespace st ...
- [Hello 2020] C. New Year and Permutation (组合数学)
[Hello 2020] C. New Year and Permutation (组合数学) C. New Year and Permutation time limit per test 1 se ...
- POJ 2386 Lake Counting 八方向棋盘搜索
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 53301 Accepted: 26062 D ...
- Mybatis注解开发单表CRUD
Mybatis注解开发单表CRUD mybatis注解开发和xml开发不可兼容,要么全部使用注解,要么全部使用xml,个人建议注解,简单. 当实体类属性名称和数据库表属性名称一致时:无需配置Resul ...
- ThinkPHP 3.2 生成静态页面
1:在根目录下的全局index.php中加下面这行: define('HTML_PATH', './htm');//生成静态页面的文件位置 2:在项目的配置文件config.php中加下面这行: 'H ...
- S7-300过程映像区详解
一.概念 W过程镜像区输入字 PIW立即输入区字 PIW不用等系统刷新,立即读入 IW等待系统刷新后读入 二.PIW/IW,PQW/QW 引用西门子论坛一位大侠的比方加深理解: ...
- Liveness 探测【转】
Liveness 探测让用户可以自定义判断容器是否健康的条件.如果探测失败,Kubernetes 就会重启容器. 还是举例说明,创建如下 Pod: 启动进程首先创建文件 /tmp/healthy,30 ...
- java随记 2月16
1.a=a+b 等于 a+=b ,且a+=b隐含强制类型转换 2.^ 表示异或 两个二进制同号为假,异号为真 即 0^0=0,1^1=0,0^1=1 3.三元运算 布尔表达式 ?表达式 ...
- MyBatis Generator 下划线转驼峰命名
MyBatis Generator配置文件--指定生成实体类使用实际的表列名作为实体类的属性名 table标签下的设置属性useActualColumnNames用于指定生成实体类时是否使用实际的列名 ...
- 049、Java中使用switch判断,不加入break时的操作
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...