这题说的是 给了一张长方形的纸 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. MFC修改窗口无标题和标题信息,修改执执行文件图标

    一.创建MFC后 窗口显示的是 无标题-工程名 修改方法在网上看到了几种,下面介绍下比较简单的一种: 1.在MianFrame.c文件中找到这个函数 BOOL CMainFrame::PreCreat ...

  2. 理解 ARC 下的循环引用

    本文由 伯乐在线 - nathanw 翻译,dopcn 校稿.未经许可,禁止转载!英文出处:digitalleaves.com.欢迎加入翻译组. ARC 下的循环引用类似于日本的 B 级恐怖片.当你刚 ...

  3. iOS - 获取安装所有App的Bundle ID

    先导入#import <objc/runtime.h>头文件 使用runtime获取设备上的所有app的bundle id // Class LSApplicationWorkspace_ ...

  4. 牛客网多校赛第九场A-circulant matrix【数论】

    链接:https://www.nowcoder.com/acm/contest/147/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...

  5. SQL Fundamentals:Restricting and Sorting Data限制和排序数据(FROM-WHERE-SELECT-ORDER BY)

    SQL Fundamentals || Oracle SQL语言 控制操作的显示列:基本的SELECT语句 控制行:限定查询和排序显示 分组统计查询 限定查询:WHERE字句 排序显示:ORDER B ...

  6. Pymongo NotMasterError while fetching count of the collection as per query from MongoDB in DRF

    django rest framework - Pymongo NotMasterError while fetching count of the collection as per query f ...

  7. 2018/03/20 每日一个Linux命令 之 cp

    cp 命令用于复制文件/目录 cp [-参数] [复制文件] [复制成为的新文件] 参数(这里只介绍平常会用到的,之后的话遇到再回来补充) -f 覆盖已经存在的目标文件而不给出提示. -i 与-f选项 ...

  8. elasticsearch的重启

    没有重启的操作,只有关闭了再启动的操作. ps -ef | grep elastic e表示全部的进程,f表示展示进程间的相关关系,如父子进程. 然后找到你启动es的那个账号,不是root,一般是新建 ...

  9. Constructing Roads----poj2421(最小生成树Kruskal)

    题目链接: http://poj.org/problem?id=2421 想把n个村庄连接在一起:求最小生成树,不同的是已经有了m条线段链接在一起了,求剩下的: 感觉用Kruskal会简单一点 #in ...

  10. 一致性 hash 算法(转)

    add by zhj:介绍了什么是一致性hash,以及实现一致性hash的一种算法. 原文:http://my.oschina.net/u/195065/blog/193614 目录[-] 一致性 h ...