Codeforces Round #263 (Div. 2)E(线段树点更新)
2014-08-27 19:01
218 查看
E. Appleman and a Sheet of Paper
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Appleman has a very big sheet of paper. This sheet has a form of rectangle with dimensions 1 × n. Your task is help Appleman with folding of such a sheet.
Actually, you need to perform q queries. Each query will have one of the following types:
Fold the sheet of paper at position pi.
After this query the leftmost part of the paper with dimensions 1 × pi must
be above the rightmost part of the paper with dimensions 1 × ([current width of sheet] - pi).
Count what is the total width of the paper pieces, if we will make two described later cuts and consider only the pieces between the cuts. We will make one cut at distance li from
the left border of the current sheet of paper and the other at distance ri from
the left border of the current sheet of paper.
Please look at the explanation of the first test example for better understanding of the problem.
Input
The first line contains two integers: n and q (1 ≤ n ≤ 105; 1 ≤ q ≤ 105)
— the width of the paper and the number of queries.
Each of the following q lines contains one of the described queries in the following format:
"1 pi" (1 ≤ pi < [current width of sheet]) —
the first type query.
"2 li ri" (0 ≤ li < ri ≤ [current width of sheet]) —
the second type query.
Output
For each query of the second type, output the answer.
Sample test(s)
input
output
input
output
Note
The pictures below show the shapes of the paper during the queries of the first example:
After the first fold operation the sheet has width equal to 4, after the second one the width of the sheet equals to 2.
题意:RT
思路:感觉这题挺有意思的,由于每次操作都是从左向右折叠
1.当折叠的长度l <= 总长度 L 的一半,直接从左往右折 l
2.当折叠的长度l > 总长度 L 的一半,相当于从右往左折 L-l ,然后再将纸片左右对调
每次折叠可以用线段树暴力维护每个点的厚度,因为每次折叠区间都在不断缩小,所以暴力更新均摊下来也不会慢
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Appleman has a very big sheet of paper. This sheet has a form of rectangle with dimensions 1 × n. Your task is help Appleman with folding of such a sheet.
Actually, you need to perform q queries. Each query will have one of the following types:
Fold the sheet of paper at position pi.
After this query the leftmost part of the paper with dimensions 1 × pi must
be above the rightmost part of the paper with dimensions 1 × ([current width of sheet] - pi).
Count what is the total width of the paper pieces, if we will make two described later cuts and consider only the pieces between the cuts. We will make one cut at distance li from
the left border of the current sheet of paper and the other at distance ri from
the left border of the current sheet of paper.
Please look at the explanation of the first test example for better understanding of the problem.
Input
The first line contains two integers: n and q (1 ≤ n ≤ 105; 1 ≤ q ≤ 105)
— the width of the paper and the number of queries.
Each of the following q lines contains one of the described queries in the following format:
"1 pi" (1 ≤ pi < [current width of sheet]) —
the first type query.
"2 li ri" (0 ≤ li < ri ≤ [current width of sheet]) —
the second type query.
Output
For each query of the second type, output the answer.
Sample test(s)
input
7 4 1 3 1 2 2 0 1 2 1 2
output
4 3
input
10 9 2 2 9 1 1 2 0 1 1 8 2 0 8 1 2 2 1 3 1 4 2 2 4
output
7 2 10 4 5
Note
The pictures below show the shapes of the paper during the queries of the first example:
After the first fold operation the sheet has width equal to 4, after the second one the width of the sheet equals to 2.
题意:RT
思路:感觉这题挺有意思的,由于每次操作都是从左向右折叠
1.当折叠的长度l <= 总长度 L 的一半,直接从左往右折 l
2.当折叠的长度l > 总长度 L 的一半,相当于从右往左折 L-l ,然后再将纸片左右对调
每次折叠可以用线段树暴力维护每个点的厚度,因为每次折叠区间都在不断缩小,所以暴力更新均摊下来也不会慢
相关文章推荐
- CodeforcesBeta Round #35 (Div. 2) E. Parade(线段树区间更新)
- CF 242E(div 2) n课线段树更新
- Codeforces Round #442 (Div. 2)-E-Danil and a Part-time Job(DFS序+线段树区间更新)
- 【线段树延迟更新】Codeforces Round #104 (Div. 1) E
- Educational Codeforces Round 37 (Rated for Div. 2) F. SUM and REPLACE(线段树,区间更新)
- Codeforces Round #169 (Div. 2) C. Little Girl and Maximum Sum(线段树区间更新)
- Codeforces Beta Round #75 (Div. 1 Only) B. Queue 线段树。单点更新
- Codeforces Round #343 (Div. 2) B. Far Relative’s Problem (线段树+区间更新+单点查询)
- HDU 1394 Minimum Inversion Number [线段树->单点更新]【数据结构】
- Billboard(线段树区间更新与求值)
- POJ 2828 Buy Tickets(线段树--单点更新)
- hdu 3308 LCIS (线段树+单点更新+区间合并)
- HDOJ-2795 Billboard [线段树][单点更新+单点查询+维护区间最值]
- HDU3074 Multiply game(线段树 单点更新)
- NYOJ 123 士兵杀敌(四)(线段树--区间更新+单点查询)
- HDU-2795 Billboard 线段树单点更新
- HDU 1754 I Hate It(线段树单点更新+区间求最值)
- 【POJ 2777】 Count Color(线段树区间更新与查询)
- poj 3468 A Simple Problem with Integers 线段树,区间更新.
- 【线段树延迟更新】HDU 3275