codeforces 755D PolandBall and Polygon(直线分割平面-树状数组优化查询)
来源:互联网 发布:java输入scanner 编辑:程序博客网 时间:2024/05/22 09:43
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.
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long LL;const int maxn = 1e6+10;int a[maxn],n,k;int sum(int x){int res = 0;while(x>0){res+=a[x];x -= x & -x;}return res;}void add(int x){while(x<=n){a[x]+=1;x += x & -x;}}int main(){while(scanf("%d%d",&n,&k)!=EOF){LL ans=1;int s=1,e;memset(a,0,sizeof(a));if(k>(n/2))//注意 k=n-k;for(int i=0;i<n;++i){e = (s+k)%n;if(e==0)e=n;if(s<e)ans += sum(e-1)-sum(s)+1;elseans += sum(n)-sum(s)+sum(e-1)+1;if(i!=n-1)printf("%lld ",ans);elseprintf("%lld\n",ans);add(s);add(e);s=e;}}return 0;}
- codeforces 755D PolandBall and Polygon(直线分割平面-树状数组优化查询)
- Codeforces 755-D. PolandBall and Polygon(树状数组+计算几何)
- Code Forces 755 D PolandBall and Polygon(思维+树状数组)
- 【codeforces 755D】PolandBall and Polygon
- Codeforces 755D-PolandBall and Polygon
- D. PolandBall and Polygon----线段树(树状数组)
- codeforces 755 d PolandBall and Polygon(找规律)
- codeforces-755D-PolandBall and Polygon(数学题)
- 8VC Venture Cup 2017 - Elimination Round D. PolandBall and Polygon 树状数组+几何
- 8VC Venture Cup 2017 - Elimination Round D. PolandBall and Polygon【思维+树状数组】好题
- codeforces 8VC Venture Cup 2017 - Elimination Round D PolandBall and Polygon
- Codeforces 8VC Venture Cup 2017 - Elimination Round D.PolandBall and Polygon
- codeforces 629D-Babaei and Birthday Cake(dp && 线段树或树状数组离散优化)
- Codeforces 629D Babaei and Birthday Cake(树状数组优化dp)
- 【codeforces 755A】PolandBall and Hypothesis
- 【codeforces 755B】PolandBall and Game
- 【codeforces 755C】PolandBall and Forest
- codeforces-755-B PolandBall and Game
- 绘图,数组就是一个大变量,非常特殊的变量而已
- java 代理模式详解之静态代理
- SAS SATA SSD IDE硬盘介绍区别
- 【Cocos\杂谈】Windows下Cocos2d-x 3.14环境搭建
- 回文数
- codeforces 755D PolandBall and Polygon(直线分割平面-树状数组优化查询)
- 【Android】给RecyclerView添加分割线的步骤
- 关于Oracle误操作--数据被Commit后的数据回退恢复(闪回)
- Tomcat(一) Tomcat是什么:Tomcat与Java技术 Tomcat与Web应用 以及 Tomcat基本框架及相关配置
- Tomcat(二) Tomcat实现:Servlet与web.xml介绍 以及 源码分析Tomcat实现细节
- nagios插件之监控日志中index增长情况
- 反思与感悟
- 总结 mysql error 1130 hy000:Host'localhost'解决方案
- Hexo学习(1) Mac中Hexo与GithubPages环境搭建