题目链接:Codeforces 461C Appleman and a Sheet of Paper
题目大意:就是一个叠被子的过程,穿插着询问一段区间上被子的单位厚度。
解题思路:用前缀和数组模拟即可。因为对于折超过一半的处理为将令一半叠上来,所以需要变量记录当前被子的正反状态。处理好下标关系即可。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1e6+5;
int N, Q, W[maxn];
int main () {
scanf("%d%d", &N, &Q);
for (int i = 1; i <= N; i++)
W[i] = i;
bool flag = false;
int k, l, r;
int n = N, bw = 0;
while (Q--) {
scanf("%d%d", &k, &l);
if (k == 1) {
if (l > n - l) {
flag = !flag;
l = n - l;
}
if (flag) {
for (int i = 0; i < l; i++)
W[bw + n - l - i] += N - W[bw + n - l + i];
} else {
bw += l;
for (int i = 0; i < l; i++)
W[bw + i] -= W[bw - i];
}
n -= l;
} else {
scanf("%d", &r);
if (flag) {
int tmp = n - r;
r = n - l;
l = tmp;
}
printf("%d\n", W[bw + r] - W[bw + l]);
}
}
return 0;
}
分享到:
相关推荐
暴枚最长桌脚的长度$l$,然后长度比$l$长的桌脚全部都要砍掉长度比$l$短的桌脚选择代价前$k$小的砍掉用线段树维护;示例程序 :typedef long l
Codeforces 185A - Plant 全测试点49个
假设有多个pair对,设dis(a,b)=2的x次幂,dis(a,c)等于2的y次幂,即有dis(a,c)=dis(a,b)+dis(b,c)=2的x次幂+2的y次幂,很明显若是dis(a,c)为2的幂数,那么x==y,可得每对pair的dis是相等的。 那么对于第四对pair,...
Codeforces 题库 101-200 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
Codeforces 题库 001-100 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
codeforces编程网站预测分数插件
CF gym模拟赛CF gym模拟赛CF gym模拟赛CF gym模拟赛
使用于Google Chrome的Codeforces Enhancer 1.1.2插件安装包。 版本:codeforces enhancer 1.1.2 使用浏览器:Google Chrome
Some of the Codeforces problems codes
Codeforces 1105B - Zuhair and Strings 测试点37个(全)
Codeforces-Newcomer-Sheet
codeforces 19 E Fairy 一道比较难的题目的解题报告 推荐阅读
Codeforces global round 10 codes
Codeforces round 678 division 2 codes
lucifer1004大佬的博客cf上分攻略故里大佬的githubcf思维题刷题数:44- (1421)codeforces 676 div2 A,B done
Codeforces部门2,A # And a2oj Ladder 4 some problems Ladder URL:http://a2oj.com/Ladder.jsp?ID=4难度等级:2问题提示: 1- 4A. Watermelon: http://codeforces.com/problemset/problem/4/A 2- 71A. Way Too ...
Codeforces Round #632 (Div. 2) C. Eugene and an array 题意: 求出一个数列中子区间满足 此区间的任意子区间之和 不为0的区间个数。 思路: 考虑用dp[x]dp[x]dp[x]记录前缀和为xxx的区间右端点。 那么这道题其实...
解决问题的方法教育Codeforces回合101 - 2/6 常规托架顺序-接受红色和蓝色...添加糖果-接受1447B-号码盒-接受 Codeforces回合#674(Div.3) 虚拟参与1426A-楼层号-接受1426B-对称矩阵-接受1426C-增加并复制-已接受1426
用于模拟Codeforces Javascript IO功能的小包装。 安装 npm i @ip-algorithmics/codeforces-io 介绍 Javascript / Typescript的Codeforce使用readLine()和print()函数输入和输出到标准输入/控制台。 如何使用 该库...
Codeforces - 1107B. Digital root & 1107C. Brutality(规律 & 贪心)Codeforces - 1107B.