题意:把一个多边形往里面连对角线,然后问每次添加多边形被划分为几个部分

产生的部分就是新加对角线与原有对角线相交条数+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的更多相关文章

  1. codeforces 755D. PolandBall and Polygon

    D. PolandBall and Polygon time limit per test 4 seconds memory limit per test 256 megabytes input st ...

  2. codeforces 755D. PolandBall and Polygon(线段树+思维)

    题目链接:http://codeforces.com/contest/755/problem/D 题意:一个n边形,从1号点开始,每次走到x+k的位置如果x+k>n则到x+k-n的位置,问每次留 ...

  3. CodeForces 755D PolandBall and Polygon ——(xjbg)

    每次连线,起点和终点之间,每一个被点亮的点,这些点都能连出去两条线,因此可以增加的块数+2(1这个点除外,因为只有连出的点没有连进的点),计算起点和终点之间有几个点被点亮即可,然后1这个点特判一下.感 ...

  4. 【codeforces 755D】PolandBall and Polygon

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. Codeforces 755D:PolandBall and Polygon(思维+线段树)

    http://codeforces.com/problemset/problem/755/D 题意:给出一个n正多边形,还有k,一开始从1出发,向第 1 + k 个点连一条边,然后以此类推,直到走完 ...

  6. D. PolandBall and Polygon BIT + 欧拉公式

    http://codeforces.com/contest/755/problem/D // 我也觉得非平面图不能用欧拉公式,但是也能过,不知道为什么.求大佬留言. 这题其实就是平面图,因为它有很多个 ...

  7. 【树状数组】Codeforces Round #755 D. PolandBall and Polygon

    http://codeforces.com/problemset/problem/755/D 每次新画一条对角线的时候,考虑其跨越了几条原有的对角线. 可以用树状数组区间修改点查询来维护多边形的顶点. ...

  8. CF EC 87 div2 1354 C2 Not So Simple Polygon Embedding 计算几何 结论

    LINK:Not So Simple Polygon Embedding 搞了好久终于搞会了. 错误原因 没找到合适算边长的方法 要么就是边长算的时候算错了. 几何学的太差了 最后虽然把十边形的和六边 ...

  9. 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 ...

随机推荐

  1. 「HNOI/AHOI2018」道路

    传送门 Luogu 解题思路 考虑树形 \(\text{DP}\) 设状态 \(dp[u][i][j]\) 表示从首都走到点 \(u\) ,经过 \(i\) 条公路,\(j\) 条铁路的最小不方便值. ...

  2. Java枚举类型enum使用详解

      java的Enum枚举类型终于在j2se1.5出现了.之前觉得它只不过是鸡肋而已,可有可无.毕竟这么多年来,没有它,大家不都过得很好吗?今日看<Thinking in Java>4th ...

  3. 树莓派开启VNC远程桌面

    分类: Raspberry Pi Linux2013-03-12 10:18 4288人阅读 评论(1) 收藏 举报   目录(?)[+]   1.安装VNC sudo apt-get install ...

  4. Servlet 3.0 新特性概述

    Servlet 3.0 新特性概述 Servlet 3.0 作为 Java EE 6 规范体系中一员,随着 Java EE 6 规范一起发布.该版本在前一版本(Servlet 2.5)的基础上提供了若 ...

  5. 用sql删除数据库重复的数据的方法

      /***********************************************两个意义上的重复记录:1.是完全重复的记录,也即所有字段均重复的记录,2.是部分关键字段重复的记录, ...

  6. python --- mysql数据库的操作

    1.pymysql的初使用 import pymysql db_config = { 'host' :'127.0.0.1', 'user':'root', ', , 'database':'test ...

  7. CentOS 6.x 重置root 密码

    1.重启,进入启动界面,快速按e,进入GNU GRUB界面. 2.选择第二项,按e,进行编辑. 3.在末尾输入1或single,回车,返回上一界面,还是选第二项,按b,进入单用户模式. 此时输入命令  ...

  8. oracle11g更改字符集

    一.查看服务器字符集编码三种方式:1)select userenv('language') from dual; -- 推荐2)select * from V$NLS_PARAMETERS;3)sel ...

  9. window下mysql-proxy简单使用

    mysql-proxy是mysql官方提供的mysql中间件服务,上游可接入若干个mysql-client,后端可连接若干个mysql-server.它使用mysql协议,任何使用mysql-clie ...

  10. HDU_4965 Fast Matrix Calculation 2014多校9 矩阵快速幂+机智的矩阵结合律

    一开始看这个题目以为是个裸的矩阵快速幂的题目, 后来发现会超时,超就超在  M = C^(N*N). 这个操作,而C本身是个N*N的矩阵,N最大为1000. 但是这里有个巧妙的地方就是 C的来源其实 ...