CSU 1770 Button Control Lantern Experiment (tree-like array)

Source: Internet
Author: User

1770: Button control Lantern experiment Time limit:1 Sec Memory limit:128 MB
submit:194 solved:65
[Submit] [Status] [Web Board] Description

should be teaching arrangements, yy and happy to do electrical experiments. The contents of the experiment are exceptionally simple a bunch of buttons the programmed EEPROM can control a string of colored lights. However, the selection of a one-to-one control mode of the low, and quickly follow the experimental instructions to finish the experiment yy immediately feel very boring. So his fingers in a row of buttons on the boring slide to slip, the corresponding lights are constantly changing the switch. It is known that each button will change the state of the corresponding lantern, so each yy slide will change the status of a series of lights. It is now known that the first state of the lantern, has yy n times boring beginning and end of the l,r. Now ask the final state of the lantern.

Input

There are multiple sets of data.
The first row of each group of data, N (1<=n<=10^5) represents the length of the lantern string, T (0<=t<=10^5) represents the number of yy sliding
The second row n number (0 means off 1 for light) gives the current state of n lights.
The two-digit Li,ri (1<=li<=ri<=n) on each line of the T-line represents the interval of each slide.

Output

Each group outputs the state of the final string in one row, and the format is shown in the sample.

Sample Input
3 21 0 11 32 3
Sample Output
0 0 1


Interval Update + single point evaluation of water, Time complexity O (N*log (n)).
#include <iostream>#include<cstring>#include<stdio.h>#include<stdlib.h>#include<algorithm>using namespacestd;Const intN =100005;intA[n];intc[n],n,m;intLowbit (inti) {    returni& (-i);}voidUpdateintIdxintv) {     for(inti=idx;i<=n;i+=lowbit (i)) {C[i]+=W; }}intGetsum (intidx) {    intsum =0;  for(inti=idx;i>=1; i-=lowbit (i)) {Sum+=C[i]; }    returnsum;}intMain () { while(SCANF ("%d%d", &n,&m)! =EOF) {memset (c,0,sizeof(c));  for(intI=1; i<=n;i++) {scanf ("%d",&A[i]); }         while(m--){            intL,r; scanf ("%d%d",&l,&R); Update (L,1); Update (R+1,-1); }         for(intI=1; i<n;i++){            if(Getsum (i)%2==1){                if(a[i]==0) printf ("1"); Elseprintf"0"); }Else{printf ("%d", A[i]); }        }        if(Getsum (n)%2==1){            if(a[n]==0) printf ("1\n"); Elseprintf"0\n"); }Elseprintf"%d\n", A[n]); }    return 0;}

CSU 1770 Button control Lantern Experiment (tree-like array)

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.