Codeforces755D PolandBall and Polygan
题目戳这里
我们只需要计算每增加一条线后穿过了几条已有的线即可。为了方便,我们令\(K \le N/2\),并且给每条线一个方向,即\(x\)到\((x+K) \; mod \; N\)。然后我们假设现在我们正在链接\(a\)到\((a+K) \; mod \; N\)这条线,于是他穿过的线就是从\((a-K,a+k)\)(模\(K\)意义下)$这段区间中点射出边的数目,拿个树状数组维护一下即可。
#include<cstdio>
#include<cstdlib>
using namespace std;
typedef long long ll;
#define lowbit(a) (a&-a)
const int maxn = 1000010;
int N,K,now,tree[maxn]; ll ans = 1LL;
inline void ins(int a) { for (++a;a <= N;a += lowbit(a)) ++tree[a]; }
inline ll calc(int a) { int ret = 0; for (++a;a;a -= lowbit(a)) ret += tree[a]; return (ll)ret; }
int main()
{
freopen("755D.in","r",stdin);
freopen("755D.out","w",stdout);
scanf("%d %d",&N,&K); if (N - K < K) K = N-K;
do
{
if (now+K-1<N)
{
ans += calc(now+K-1)-calc(now);
if (now - K < 0) ans += calc(now-1)+calc(N-1)-calc(now-K+N);
else ans += calc(now-1)-calc(now-K);
}
else
{
ans += calc(N-1)-calc(now)+calc(now+K-1-N);
if (now - K < 0) ans += calc(now-1)+calc(N-1)-calc(now-K+N);
else ans += calc(now-1)-calc(now-K);
}
ins(now); now += K; if (now >= N) now -= N;
printf("%lld ",++ans);
}
while (now);
fclose(stdin); fclose(stdout);
return 0;
}
Codeforces755D PolandBall and Polygan的更多相关文章
- codeforces 755C. PolandBall and Forest
C. PolandBall and Forest time limit per test 1 second memory limit per test 256 megabytes input stan ...
- codeforces 755D. PolandBall and Polygon
D. PolandBall and Polygon time limit per test 4 seconds memory limit per test 256 megabytes input st ...
- Codeforces 755F PolandBall and Gifts bitset + 二进制优化多重背包
PolandBall and Gifts 转换成置换群后, 对于最大值我们很好处理. 对于最小值, 只跟若干个圈能否刚好组能 k 有关. 最直观的想法就是bitset优化背包, 直接搞肯定T掉. 我们 ...
- codeforces 755F F. PolandBall and Gifts(贪心+多重背包)
题目链接: F. PolandBall and Gifts time limit per test 1.5 seconds memory limit per test 256 megabytes in ...
- Codeforces 755 F. PolandBall and Gifts 多重背包+贪心
F. PolandBall and Gifts It's Christmas time! PolandBall and his friends will be giving themselves ...
- 【codeforces 755B】PolandBall and Game
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 755A】PolandBall and Hypothesis
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 755D】PolandBall and Polygon
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 755C】PolandBall and Forest
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- BZOJ1509: [NOI2003]逃学的小孩(树的直径)
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1126 Solved: 567[Submit][Status][Discuss] Description ...
- Java - 静态方法的线程安全问题
若该静态方法中有对某个静态属性操作,那么它就不是线程安全的,反之,若只对实例属性操作,那么它就是线程安全的. 补充说明,因为,静态方法不对特定的实例操作,只能访问静态成员.实例方法可对特定的实 ...
- pycharm界面美化,个人喜欢
进入file-setting选项 界面设置主要是在appearance和editor里面.appearance主要是整个pycharm的主题设置,比如文件管理窗口的颜色,其实就是软件本身的主题设置.我 ...
- datatable行内内容太长,有时不自动换行解决方法
加一个css属性即可 style = "word-wrap:break-word;" js代码: "render": function (data, type, ...
- PHP递归操作
对于php的递归操作解释说明,递归基本上是学习每种语言都要会的最基本的操作.来吧,下面是我闲的时候随便写的一个对数组进行遍历操作的一个递归函数. 原理很简单,递归就是在一个函数里面调用自身的一种机制. ...
- python如果想输出原格式的内容,可以加''' ''',占位符使用方式
print('我考了%d分'%20) msg=''' ---------info of %s----------- name: %s age: %d #字符串不能放到%d处 job: %s salar ...
- C语言数组篇(一)一维数组
0. 数组的两种表现形式 一种是常见的a[10]; //初学者常用 另一种是用指针表示的数组. //实际工程使用.常用于参数传递 ...
- python Re库的介绍
re库的贪婪匹配和最小匹配 后面跟着?变为最小匹配
- 16,Flask-Migrate
终于到了Flask-Migrate,之前在学习Flask-SQLAlchemy的时候,Flask支持 makemigration / migrate 吗? 答案在这里该诉你,如果你同时拥有两个三方组件 ...
- 3,MongoDB之数据类型
一.MongoDB 之数据类型 首先我们要先了解一下MongoDB中有什么样的数据类型: Object ID :Documents 自生成的 _id String: 字符串,必须是utf-8 Boo ...