Codeforces 461C Appleman and a Sheet of Paper (analog)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.