codeforces 755D. PolandBall and Polygon
4 seconds
256 megabytes
standard input
standard output
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the following process n times, starting from the vertex 1:
Assume you've ended last operation in vertex x (consider x = 1 if it is the first operation). Draw a new segment from vertex x to k-th next vertex in clockwise direction. This is a vertexx + k or x + k - n depending on which of these is a valid index of polygon's vertex.
Your task is to calculate number of polygon's sections after each drawing. A section is a clear area inside the polygon bounded with drawn diagonals or the polygon's sides.
There are only two numbers in the input: n and k (5 ≤ n ≤ 106, 2 ≤ k ≤ n - 2, gcd(n, k) = 1).
You should print n values separated by spaces. The i-th value should represent number of polygon's sections after drawing first i lines.
5 2
2 3 5 8 11
10 3
2 3 4 6 9 12 16 21 26 31
The greatest common divisor (gcd) of two integers a and b is the largest positive integer that divides both a and b without a remainder.
For the first sample testcase, you should output "2 3 5 8 11". Pictures below correspond to situations after drawing lines.
题目大意:一个n边形,从1号点开始,每次走到(x+k-1)%n+1位置,问每次留下来的路径把这个多边形划分成了几个部分。2 ≤ k ≤ n - 2, gcd(n, k) = 1,可以发现一定每个点一定经过一次,插入边的时候对应的点对应了一个区间,两条直线不相交(贡献答案)当且仅当他们的区间无交集,因为一个点只对应一个区间(只考虑出去的那个),用树状数组维护一下即可。
有个细节:如果2k>n,那么把k转化一下为n-k就可以了。(以为这个细节很显然,然后就没去hack,结果本来房间里10个对的然后就只剩3个没fst,MDZZ)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
#define maxn 1000010
#define llg long long
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,cs[maxn],k,x,y,ans,c[maxn]; llg lowbit(llg x) {return x&-x;}
void add(llg w,llg v)
{
while (w<=n)
{
c[w]+=v; w+=lowbit(w);
}
}
llg sum(llg w)
{
llg ans=;
while (w>)
{
ans+=c[w]; w-=lowbit(w);
}
return ans;
} llg work(llg x,llg y)
{ llg l=y,r=y+n-k-k;
if (r>n)
{
r-=n;
return sum(n)-sum(l-)+sum(r);
}
else return sum(r)-sum(l-);
} int main()
{
yyj("D");
cin>>n>>k;
if (k>n/) k=n-k;
x=;
ans=;// add(1,1);
for (llg i=;i<=n;i++)
{
y=x+k;
if (y>n) y-=n;
ans+=i-work(x,y);
add(x,);
x=y;
printf("%lld ",ans);
}
return ;
}
codeforces 755D. PolandBall and Polygon的更多相关文章
- 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这个点特判一下.感 ...
- cf 755D. PolandBall and Polygon
题意:把一个多边形往里面连对角线,然后问每次添加多边形被划分为几个部分 产生的部分就是新加对角线与原有对角线相交条数+1,用线段树(大雾)维护一下. #include<bits/stdc++.h ...
- 【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 个点连一条边,然后以此类推,直到走完 ...
- 【树状数组】Codeforces Round #755 D. PolandBall and Polygon
http://codeforces.com/problemset/problem/755/D 每次新画一条对角线的时候,考虑其跨越了几条原有的对角线. 可以用树状数组区间修改点查询来维护多边形的顶点. ...
- D. PolandBall and Polygon BIT + 欧拉公式
http://codeforces.com/contest/755/problem/D // 我也觉得非平面图不能用欧拉公式,但是也能过,不知道为什么.求大佬留言. 这题其实就是平面图,因为它有很多个 ...
- codeforces 755C. PolandBall and Forest
C. PolandBall and Forest time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces 755F PolandBall and Gifts bitset + 二进制优化多重背包
PolandBall and Gifts 转换成置换群后, 对于最大值我们很好处理. 对于最小值, 只跟若干个圈能否刚好组能 k 有关. 最直观的想法就是bitset优化背包, 直接搞肯定T掉. 我们 ...
随机推荐
- oracle数据库兼容mysql的差异写法
1.sysdate改为sysdate(),或者now(); 2.nvl(expr1,expr2) 改为IFNULL(expr1,expr2) nvl2(expr1,expr2,expr3)改为 IF( ...
- FusionCharts导出图表常见问题(FAQ)汇总---FusionCharts常见问题大全
在前面几篇文章中,我们介绍了FusionCharts生成Flash图表常见问题FAQ以及使用中的一些常见报错及调试/解决方法.本文继续介绍FusionCharts导出图表时的一些常见问题(FAQ). ...
- C#对象序列化笔记
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...
- MyBatis基础用法(一)
<select id="getErrorTimes" resultType="Integer"> SELECT ErrorTimes FROM `e ...
- eclipse的插件
jode_1.0.6(Java Optimize and Decompile Environment ) 非常好用的Eeclipse的反编译插件,随时点击,随时查看源代码,但他的官方下载的都是核心源码 ...
- C#+QI的例子
COM中,和我们打交道的是接口,也就是说类对我们是隐形的,那么我们要做开发,要使用这些功能,我们只能通过接口,通过接口暴露出来的方法,COM是一种服务器端/客户端架构,服务器端定义了操作的法,客户端通 ...
- HTTP协议详解 转自小坦克
-- 此文章是转载小坦克的;直接复制文章的目的是因为原文章地址经常被重置,找不到原来的文章.小坦克博客园主页:https://home.cnblogs.com/u/TankXiao/ 当今web程序的 ...
- PAT (Advanced Level) 1016. Phone Bills (25)
简单模拟题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm& ...
- POJ 2482 Stars in Your Window
线段树+离散化+扫描线 AC之后,又认真读了一遍题目,好文章. #include<cstdio> #include<map> #include<algorithm> ...
- 转发:Xcode插件
古人云“工欲善其事必先利其器”,打造一个强大的开发环境,是立即提升自身战斗力的绝佳途径!以下是搜集的一些有力的XCode插件. 1.全能搜索家CodePilot 2.0 你要找的是文件?是文件夹? ...