这题说的是 给了一张长方形的纸 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的更多相关文章

  1. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  2. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  3. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  4. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  5. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  6. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  7. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  8. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

  9. CodeForces - 148D Bag of mice

    http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...

随机推荐

  1. 【读书笔记】socket描述符选项[SOL_SOCKET]

    #include <sys/socket.h>    int setsockopt( int socket, int level, int option_name,             ...

  2. C# 压缩文件 ICSharpCode.SharpZipLib.dll

    效果: 代码只能压缩文件夹里面的文件,不能压缩文件夹. 压缩前: 压缩后: 代码: 需要引用ICSharpCode.SharpZipLib.dll public ActionResult Index( ...

  3. [SQL] 用SQL语句检查CPU和磁盘空间

    在MS Sql Server中可以能过以下的方法查询出磁盘空间的使用情况及各数据库数据文件及日志文件的大小及使用利用率: 1.查询各个磁盘分区的剩余空间:Exec master.dbo.xp_fixe ...

  4. 如何使用Jquery 引入css文件

    如何使用Jquery 引入css文件: $("head").append("<link>");var toolbarCss = $("he ...

  5. 无向连通图求割边(桥)hdu4738,hdu3849

    点击打开链接 题目链接:   hdu 4738 题目大意:   曹操有N个岛,这些岛用M座桥连接起来 每座桥有士兵把守(也可能没有) 周瑜想让这N个岛不连通,但只能炸掉一座桥 并且炸掉一座桥需要派出不 ...

  6. Jmeter与Jenkins结合进行Web接口测试

    纯通过Jmeter的界面进行Web的接口测试,效率低下.为此将Jmeter的接口测试与Jenkins联合,实现持续集成.配置完成后,只需修改运行的Jmeter脚本即可,运行结束后测试结果发送到指定邮箱 ...

  7. bootstrap中点击左边展开

    <div id="sideNav" href=""><i class="material-icons dp48 glyphicon- ...

  8. OpenCV学习笔记之CXCORE篇

    转自blog.csdn.net/bbzz2/article/details/50764209

  9. 《机器学习实践》程序清单3-7 plotTree函数

    这个plotTree函数,比较聪明,比较简化,比较抽象,作者一定是逐步优化和简化到这个程度的.我是花了小两天时间,断断续续看明白的,还是在参考了另一篇文章以后.这里是链接http://www.cnbl ...

  10. PAT-GPLT L1-039 - 古风排版 - [字符串输入输出]

    题目链接:https://www.patest.cn/contests/gplt/L1-039 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standar ...