D. PolandBall and Polygon
time limit per test

4 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

There are only two numbers in the input: n and k (5 ≤ n ≤ 106, 2 ≤ k ≤ n - 2, gcd(n, k) = 1).

Output

You should print n values separated by spaces. The i-th value should represent number of polygon's sections after drawing first i lines.

Examples
input
5 2
output
2 3 5 8 11 
input
10 3
output
2 3 4 6 9 12 16 21 26 31 
Note

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的更多相关文章

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

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

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

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

  3. cf 755D. PolandBall and Polygon

    题意:把一个多边形往里面连对角线,然后问每次添加多边形被划分为几个部分 产生的部分就是新加对角线与原有对角线相交条数+1,用线段树(大雾)维护一下. #include<bits/stdc++.h ...

  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. 【树状数组】Codeforces Round #755 D. PolandBall and Polygon

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

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

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

  8. codeforces 755C. PolandBall and Forest

    C. PolandBall and Forest time limit per test 1 second memory limit per test 256 megabytes input stan ...

  9. Codeforces 755F PolandBall and Gifts bitset + 二进制优化多重背包

    PolandBall and Gifts 转换成置换群后, 对于最大值我们很好处理. 对于最小值, 只跟若干个圈能否刚好组能 k 有关. 最直观的想法就是bitset优化背包, 直接搞肯定T掉. 我们 ...

随机推荐

  1. nginx 502错误

    一些运行在Nginx上的网站有时候会出现“502 Bad Gateway”错误,有些时候甚至频繁的出现.以下是小编搜集整理的一些Nginx 502错误的排查方法,供参考: Nginx 502错误的原因 ...

  2. SD卡读写扇区注意事项(转)

    源:http://blog.163.com/zhaojun_xf/blog/static/30050580201151410635516/ 在调试SD卡时,大家都喜欢使用扇区进行验证.也就是说,一般都 ...

  3. 自己用wireshark 抓了个包,分析了一下

    我自把对应 ip 包的头部拿出来手动分析了一下 :)

  4. PAT (Advanced Level) 1061. Dating (20)

    简单模拟. #include<stdio.h> #include<string.h> ],s2[],s3[],s4[]; ][]={"MON ", &quo ...

  5. Spring创建对象的方式3种方式

    此文为基础回顾,估计是最后一次总结. 项目利用maven进行架构,其基本项目结构为: 其中pom.xml中的内容为: <project xmlns="http://maven.apac ...

  6. Task Cancellation: Parallel Programming

    http://beyondrelational.com/modules/2/blogs/79/posts/11524/task-cancellation-parallel-programming-ii ...

  7. hibernate--多对多双向关联(少用)

    老师知道自己教了哪些学生, 学生也知道教自己的有哪些老师. Teacher.java: package com.bjsxt.hibernate; import java.util.HashSet; i ...

  8. Quick Cocos2dx Http通讯

    服务端:Python 通讯协议:Http 参考文章: 1 用python实现一个基本的http server服务器 http://blog.sina.com.cn/s/blog_416e3063010 ...

  9. 滚动时div的背景图片随之滚动

    在浏览一些网站时发现有一种效果是当滚动时看到某一DIV的背景也会随之滚动,如下: 当滚动时内容位置保持不变,但是内容后面的背景却在随着滚动.随之我通过审查元素看到了其是通过background-pos ...

  10. MariaDB GTID 复制同步

    MariaDB GTID 复制同步 GTID:Global Transaction ID,全局事务ID,在整个主从复制架构中任何两个事物ID是不能相同的.全局事务ID是Mster服务器生成一个128位 ...