bzoj:4333:jsoi2012 the test of the Wise

Source: Internet
Author: User

4333:jsoi2012 the test of the wise time limit:10 Sec Memory limit:256 MB
submit:68 solved:18
[Submit] [Status] [Discuss] Description A.D. 1371, the emperor of the Dajian temple in the Arctic pavilion, just a few years, the chicken coop has built a king temple, Kuan Kung temple, True Zhen Wu Miao, Hero Temple, Wang, all the temple, Bian Shenqiu Pot temple, Martyrs ' Temple, Liu Yueyue temple, Cao Wuhi Temple, a total of 10 temples, collectively referred to as "ten temples." Later, in order to facilitate people to the chicken Coop Mountain Pilgrimage Buddha, the emperor ordered the dredging of the chicken coop has been silted up for many years of the tide ditch. So, there is a "into the Xianghe." However, not everyone can come to the Coop Mountain, the founder of the Pilgrimage River built a stone bridge, in the middle of a high Rx wide ry of the grid diagram (as shown). All the squares are active and reversible, white on one side and black on one side, here we use 0 for white and 1 for black. In the initial case, all the squares are white facing forward. There are Rx+ry button, corresponding to the RX line and Ry column.  Once a button is triggered, the corresponding row or column of the grid is thrown at the same time. At the same time, adviser Liu Ji, who is good at understanding the celestial sky, gives a black-and-white state called "Doom Star". Each person who went to the Coop mountain needs to be triggered and only triggers a button, and if the visitor is in the shape of a "Doom star", it is not allowed to pass. Every day to come to the number of chicken Coop Mountain N is known beforehand, at the same time the Celestial Divinity Mighty, each newcomer always has a very large probability trigger number 1 button, we may wish to use sequence A1,A2,..., an to express, the problem to ensure that the initial time of a sequence of all 1. Meanwhile, in the whole problem, Ai satisfies 1<=ai<=rx+ry. The founder is very concerned about the number of people who are not allowed to go to coop. So he occasionally asks about "how many people in a certain period of time will not pass the" Doom Star "test." However, those who came to the Coop mountain are not willing to do such a single operation. Visitors may suddenly decide to modify their trigger button. In a more troublesome situation, a couple of successive people will suddenly decide to modify the trigger button and all to trigger the same button.  Now this troublesome problem has been given to you. PostScript: When the Qianlong period, a person called Ji Yun to visit here, told people a set of methods, since then no one will not be allowed to pass. Over time, the chicken Coop Mountain Fireworks Still, but this organ chart of the story will gradually lost. It was not until today that the world understood it again.

Input inputs the first line of the file has 2 digits Rx and Ry indicates the height and width of the body chart (). Each line of the Rx line then ry a number that describes the "Doom Star" shape, each of which satisfies a non-0 or 1. The following line has two digits, N and M, respectively, indicating the number of people and the number of times the change was asked. After M line, corresponding to M inquiry or modification. Each line is preceded by a number t: If T is 0: Then there are 2 digits D and X, which indicates that ad is modified to X. If T is 1: Then there are 2 numbers L and R, which indicates how many people in the first person to the R person who triggered the button will appear "Doom Star" shape, thus unable to pass. If T is 2: Then there are 3 digits l,r and x, and the surface changes al,al+1,..., ar-1,ar to X.

Output for each query (that is, T is 1), outputs a single line, an integer that describes the number of people who meet the requirements in the interval [l,r].

Sample Input2 3
0 0 1
1 1 0
7 4
1 1 7
0 2 3
0 3 4
1 1 7Sample Output0
3(Sometimes I think it's nice to copy the surface. )the problem can obviously be converted to the number of prefixes in the band repair query interval, or to a given number. Yes, huh? Looks like there are 64 different states. no right, 5 buttons should be 2^5=32 state? Oh, take all the buttons back to the same thing, that's the state of 2^4=16. then you can do it! the effect of the interval modification to a number is only 1 times (22 offset). mark on the line tree (I'm going to write it in the morning)
#include <cstdio>#include<cstring>#include<algorithm>#defineMN 1000001using namespacestd;intRead_p,read_ca;inlineintRead () {read_p=0; read_ca=GetChar ();  while(read_ca<'0'|| Read_ca>'9') read_ca=GetChar ();  while(read_ca>='0'&&read_ca<='9') read_p=read_p*Ten+read_ca- -, read_ca=GetChar (); returnread_p;}structna{intc[ -],sum,l,r,y,a,q,v;} t[mn<<1];intn,m,q,rx,ry,o[Ten],s[ -],to[ -][Ten],num=0, bo,ro=0, x,n[ -];voidBuildint&p,intLintR) {    if(p==0) p=++num,t[p].l=t[p].r=t[p].sum=t[p].y=0, t[p].a=-1; t[p].c[n[0]]= (r-l) >>1)+(! (l&1)||! (r&1)); t[p].c[n[o[0]]]= (r-l) >>1) + ((l&1)|| (r&1)); T[p].sum= (((r-l) >>1) + ((l&1)|| (r&1))) &1) *o[0]; if(L==R)return; intMid=l+r>>1; Build (T[p].l,l,mid); Build (T[p].r,mid+1, R);}voidPdintPintLintR) {    if(t[p].a!=-1){        if(T[P].L) T[T[P].L].A=T[P].A,T[T[P].L]. V=T[P]. V,T[T[P].L]. Q=T[P]. q,t[t[p].l].y=0; if(T[P].R) T[T[P].R].A=T[P].A,T[T[P].R]. V=T[P]. V,T[T[P].R]. Q=T[P]. q,t[t[p].r].y=0; memset (T[P].C,0,sizeof(T[P].C)); T[P].C[N[T[P]. V]]= ((r-l) >>1)+(! (L-t[p]. q&1)||! (R-t[p]. q&1)); T[P].C[N[T[P].A^T[P]. v]]= (r-l) >>1) + ((L-t[p]. q&1)|| (R-t[p]. q&1)); T[p].sum= (((r-l) >>1) + ((L-t[p]. q&1)|| (R-t[p]. q&1))) &1) *t[p].a^ ((r-l+1&1)*T[p].        V); T[P].A=-1; }}voidUpintPintLintR) {    intMid=l+r>>1; PD (T[P].L,L,MID);pd(T[p].r,mid+1, R); T[p].sum=t[t[p].l].sum^t[t[p].r].sum^ (((mid-l+1) &1) *t[t[p].l].y ^ ((r-mid) &1)*t[t[p].r].y);  for(intI=0;i< -; i++) t[p].c[i]=t[t[p].l].c[n[s[i]^t[t[p].l].y]]+t[t[p].r].c[n[s[i]^t[t[p].r].y]];}voidCgintPintLintRintPointv) {    if(po<=l) T[p].y^=v;Else{PD (P,L,R); intMid=l+r>>1; CG (T[p].r,mid+1, r,po,v); if(mid>=PO) CG (T[P].L,L,MID,PO,V);    Up (P,L,R); }}intAskintPintLintRintPO) {    if(t[p].a!=-1)return(t[p].a* (po-t[p). q&1)) ^t[p]. v^t[p].y; if(L==R)returnt[p].sum^t[p].y; intMid=l+r>>1; if(Po<=mid)returnAsk (T[p].l,l,mid,po) ^t[p].y;Else returnAsk (t[p].r,mid+1, R,po) ^t[p].y;}intQueintPintLintRintLintRintv)    {PD (P,L,R); V^=t[p].y; if(L==L&AMP;&AMP;R==R)returnT[p].c[n[v]]; intMid=l+r>>1; if(R<=mid)returnQue (T[P].L,L,MID,L,R,V);Else    if(L>mid)returnQue (t[p].r,mid+1, r,l,r,v);Else    returnQue (t[p].l,l,mid,l,mid,v) +que (t[p].r,mid+1, r,mid+1, r,v);}voidCaintPintLintRintLintRintVintVintQ) {    if(l==l&&r==R) {T[P].A=V;T[P]. v=v;t[p].y=0; T[p]. q=p; T[P].C[N[V]]= ((r-l) >>1)+(! (l-q&1)||! (r-q&1)); T[p].c[n[v^v]]= (r-l) >>1) + ((l-q&1)|| (r-q&1); T[p].sum= (((r-l) >>1) + ((l-q&1)|| (r-q&1))) &1) ^ (*v) ^ (r-l+1&1)*V); }Else{PD (P,L,R); V^=t[p].y; intMid=l+r>>1; if(R&LT;=MID) CA (T[P].L,L,MID,L,R,V,V,Q);Else        if(L&GT;MID) CA (t[p].r,mid+1, r,l,r,v,v,q);ElseCA (T[P].L,L,MID,L,MID,V,V,Q), CA (T[p].r,mid+1, r,mid+1, r,v,v,q);    Up (P,L,R); }}intMain () {registerinti,j; Rx=read (); Ry=read (); n=0;  for(i=0; i<rx;i++)     for(j=0; j<ry;j++) o[i]^=1<< (i*ry+j), o[j+rx]^=1<< (I*ry+j), Q^=read () << (i*ry+j); N=read (); m=read (); S[bo=num=0]=0;  for(; bo<=num;) { for(i=0; i<rx+ry;i++){             for(j=0; j<=num;j++)            if(s[j]== (S[bo]^o[i])) Break; if(J>num) s[++num]=s[bo]^O[i]; To[bo][i]=J; } Bo++; }     for(i=0;i< -; i++) n[i]=-1;  for(i=0; i<=num;i++) n[s[i]]=i; Num=0; Build (RO,1, N);  while(m--) {Bo=read (); if(bo==0) Bo=read (), CG (RO,1, N,bo,o[read ()-1]^ask (RO,1, N,bo) ^ (bo==1?0: Ask (RO,1, n,bo-1)));Else        if(bo==1)if(Bo=read (), X=read (), n[q]==-1) puts ("0");Elseprintf"%d\n", Que (RO,1, n,bo,x,q));Else        if(Rx=read (), Ry=read (), X=o[read ()-1],CG (RO,1, n,ry+1, Ask (RO,1, N,ry) ^ (((ry-rx+1) &1) (*x)), CA (RO,1, N,rx,ry,x,0, rx-1), rx-1) CG (RO,1, N,rx,ask (RO,1, n,rx-1)); }}
View Code

bzoj:4333:jsoi2012 the test of the Wise

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.