这题说的是 给了一张长方形的纸 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. PostgreSQL索引介绍

    h1, h2, h3, h4, h5, h6, p, blockquote { margin: 5px; padding: 5; } body { font-family: "Helveti ...

  2. CentOS 配置Rails开发环境

    1 安装mysql yum install -y mysql mysql-server 启动mysql $ /etc/init.d/mysqld start 设置root密码,删除test数据库等 / ...

  3. VS NuGet加载本地程序包

    NuGet是VS中非常实用的一个工具,我们可以通过它在线安装想要的程序包,只要右键点击解决方案中的项目的引用,在弹出的菜单中选择“管理NuGet程序包”,然后就可以通过在线搜索找到想要添加的程序包,下 ...

  4. -bash: locate: command not found

    部分版本的linux系统使用locate快速查找某文件路径会报以下错误: -bash: locate: command not found 其原因是没有安装mlocate这个包 安装:yum  -y ...

  5. 图论-桥/割点/双连通分量/缩点/LCA

    基本概念: 1.割点:若删掉某点后,原连通图分裂为多个子图,则称该点为割点. 2.割点集合:在一个无向连通图中,如果有一个顶点集合,删除这个顶点集合,以及这个集合中所有顶点相关联的边以后,原图变成多个 ...

  6. HDU 3903 Trigonometric Function(数学定理)

    Trigonometric Function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Oth ...

  7. SequenceFile实例操作

    HDFS API提供了一种二进制文件支持,直接将<key,value>对序列化到文件中,该文件格式是不能直接查看的,可以通过hadoop  dfs -text命令查看,后面跟上Sequen ...

  8. Python3.6.3中,functools似乎不能用

    用pip install安装时报编码错误: return s.decode(sys.__stdout__.encoding) UnicodeDecodeError: 'utf-8' codec can ...

  9. matplotlib的下载和安装方法

    官网:http://matplotlib.org/ Installation节 Visit the Matplotlib installation instructions. Installing节 ...

  10. HDU 5512 - Pagodas - [gcd解决博弈]

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5512 Time Limit: 2000/1000 MS (Java/Others) Mem ...