codeforces 461C
这题说的是 给了一张长方形的纸 1*n 然后可以按照不同的做法去折这个纸张 他有两种操作,操作1 给了一个pi 点 然后将左边的纸往右边折,第2种操作是给了一个L 和 R 然后计算出 L和R 之间的纸如果 切成单位长度有多少块, 开一个标记数组记录方向然后枚举将每位的值复制到相对应的地方,然后用树状数组不断地去维护,记得如果切的点在目前的最左区间和最右区间的二分一靠右的地方那么记得折的变成右边方向记得记录一下,然后再同样的用树状数组去维护
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
const int MAX_N = ;
int C[MAX_N],n;
int lowbit(int x){
return x&(-x);
}
int sum(int x){
int ans =;
while(x>){
ans+= C[x];
x-=lowbit(x);
}
return ans;
}
void add(int x, int d){
while(x<=n){
C[x]+=d;
x+=lowbit(x);
}
}
int main()
{
int q,L,R,turn=;
scanf("%d%d",&n,&q);
R = n,L=;
for(int i= ; i<=n; i++)
add(i,);
for(int cc= ; cc< q; ++cc){ int op,a,b;
scanf("%d",&op);
if(op==){
scanf("%d",&a);
int Len = R -L;
if( ( a>Len/ && turn== ) ){
int LEN = Len-a;
a = R-LEN;
for(int loc = ; loc <= LEN; ++loc ){
int E = sum( a+loc ) - sum(a+loc-);
add(a-loc+,E);
}
turn=;
R = a;
continue;
}
if( (a<=Len/ &&turn == ) ){
int LEN = a;
a = R - LEN;
for(int loc = ;loc <= LEN; ++loc){ int E = sum(a+loc) -sum(a+loc-);
add(a-loc+,E);
}
R=a;
continue;
}
if( (a>(Len/)&& turn==)){
int LEN = Len - a;
a = L+LEN;
for(int loc =; loc < LEN ; ++loc){
int E = sum( a - loc ) -sum(a-loc-);
add(a+loc+,E);
}
L=a;
turn=;
continue;
}
if(a<=Len/ && turn == ){
int LEN = a;
a=L+a;
for(int loc = ; loc <LEN; ++ loc){
int E = sum(a-loc) -sum(a-loc -);
add(a+loc+,E);
}
L=a;
continue;
}
}else{
scanf("%d%d",&a,&b);
int ans;
if(turn==){
ans = sum(L+b)-sum(L+a);
}else {
ans = sum(R-a) -sum(R-b);
}
printf("%d\n",ans);
} } return ;
}
codeforces 461C的更多相关文章
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
- CodeForces - 148D Bag of mice
http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
随机推荐
- Doxygen生成C++中文文档配置注意事项
打开对应的Doxyfile,修改如下: 1.OUTPUT_LANGUAGE = Chinese. 2.INPUT_ENCODING = GB2312.
- Laya 位图字体制作(失败...)
参考: 官网教程-位图字体的制作与使用 一.下载字体并安装字体 从站长字体下载了液晶数字字体,将TTF文件拖入C盘windows/Font文件夹,则字体会自动安装 二.下载字体制作工具 Bitmap ...
- Android studio was unable to create a local connection in order...
以管理员身份运行cmd 输入netsh winsock reset 重启电脑
- iOS - WKWebView那些坑
WKWebView 是苹果在 WWDC 2014 上推出的新一代 webView 组件,用以替代 UIKit 中笨重难用.内存泄漏的 UIWebView.WKWebView 拥有60fps滚动刷新率. ...
- 大话FLASH和EEPROM
最近在看代码的时候,遇到了一个使用FLASH模拟EEPROM的情况,看到这个我当时是一脸蒙蔽啊,对于一个有时候连FLASH和EEPROM都分不清的人来说,怎么可能读懂用FLASH来模拟EEPROM呢? ...
- 使用SQL手动创建数据库并创建一个具有该数据库所有权限的用户
$ mysql -u adminusername -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. ...
- HDU 3091 - Necklace - [状压DP]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3091 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- linux:查看以及管理进程
学习笔记内容概要 进程查看的命令:top,ps,pstree 进程管理的命令:kill,nice,renice 查看进程: 一.top工具 top 工具是我们常用的一个查看工具,能实时的查看我们系统的 ...
- Find The Multiple--POJ1426
Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose ...
- router-link params传参
1.router.js配置 需要在路径后定义上要传的属性名 --> /:属性名(query方式不需要) { path: '/CreateProgress/:name1', name: ...