Title Link: codeforces 461C appleman and a Sheet of Paper
The main idea: is a folding quilt process, interspersed with asked a section of the quilt thickness of the unit.
The idea of solving problems: using prefix and array simulation. Because the processing for more than half of the folds will be stacked up, the variables need to record the positive and negative state of the current quilt. The subscript relationship can be handled well.
#include <cstdio>#include <cstring>#include <algorithm>using namespace STD;Const intMAXN =1e6+5;intN, Q, W[MAXN];intMain () {scanf("%d%d", &n, &q); for(inti =1; I <= N; i++) W[i] = i;BOOLFlag =false;intK, L, R;intn = 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(inti =0; I < L; i++) W[BW + n-l-i] + = N-W[BW + n-l + i]; }Else{BW + = l; for(inti =0; I < L; i++) W[BW + i]-= w[bw-i]; } N-= l; }Else{scanf("%d", &r);if(flag) {intTMP = N-R; R = n-l; L = tmp; }printf("%d\n", W[BW + R]-W[BW + l]); } }return 0;}
Codeforces 461C Appleman and a Sheet of Paper (analog)