LUOGUP3948 Data Structure 10-20
Is relatively bare difference problem, but pay attention to the online query began silly, every time the violence from 1 to N to do it again, there is an array of every time to empty ... The result T is a lot of points.
In fact, when online query directly with the variable + sweep to R on the line.
1#include <cstdio>2#include <algorithm>3#include <cstring>4 5 using namespacestd;6typedefLong Longll;7 8 intN,opt,tot,fin;9 Chardoit[5];Ten ll Sjt,minn,maxx; Onell cha[100000],sta[100000],sum[100000]; A - intMain () - { thescanf"%d%d",&n,&opt); -scanf"%lld%lld%lld",&sjt,&minn,&Maxx); - for(intI=1; i<=opt;i++) - { + intL=0, r=0; ll x=0; -scanf"%s", doit+1); + if(doit[1]=='A') A { atscanf"%d%d%lld",&l,&r,&x); -cha[l]+=x,cha[r+1]-=x; - } - Else - { -scanf"%d%d",&l,&R); inll noww=0, cnt=0; - for(intI=1; i<=r;i++) to { +noww+=Cha[i]; -ll cmp=noww*i%Sjt; the if(I>=l&&cmp>=minn&&cmp<=maxx) cnt++; * } $printf"%lld\n", CNT);Panax Notoginseng } - } the for(intI=1; i<=n;i++) sta[i]=sta[i-1]+Cha[i]; + for(intI=1; i<=n;i++) A { thesum[i]=sum[i-1]; +ll cmp=sta[i]*i%Sjt; - if(Cmp>=minn&&cmp<=maxx) sum[i]++; $ } $scanf"%d",&fin); - for(intI=1; i<=fin;i++) - { the intL=0, r=0; -scanf"%d%d",&l,&R);Wuyiprintf"%lld\n", sum[r]-sum[l-1]); the } - return 0; Wu}View Code
sjtu1329 Dinner 10-20
Binary enumeration of bare topics. From the data range can be seen, the results of the card for more than half an hour ... Because the word misspelled .... Sigh ... I'm so stupid, really.
Also note that since the binary digits start from 0, you should subtract 1 for the dish number.
1#include <cstdio>2#include <algorithm>3#include <cstring>4 5 using namespacestd;6 7 intT,n,m,fake,ans;8 CharSSS;9 intrequest[ -][ -],num[ -];Ten OneInlineintRead () { A CharCh=getchar ();intx=0, f=1; - while(ch<'0'|| Ch>'9') { - if(ch=='-') f=-1; theCh=GetChar (); - } - while(ch<='9'&& ch>='0') { -x=x*Ten+ch-'0'; +Ch=GetChar (); - } +sss=ch; A returnx*F; at } - - intMain () - { -scanf"%d",&T); - while(t--) in { -scanf"%d%d",&n,&m); to for(intI=1; i<=m;i++) + for(intj=1; j<=n;j++) - { thenum[i]++; *request[i][j]=read (); $ if(sss!=' ') Break;Panax Notoginseng } -Fake= (1<<n)-1; the for(intI=0; i<=fake;i++) + { A intCnt=0; the for(intj=1; j<=m;j++) + for(intk=1; k<=num[j];k++) - { $ if(request[j][k]<0) $ { - inttmp=-request[j][k]-1; - if(! ((i>>tmp) &1)) {cnt++; Break;} the } - ElseWuyi { the inttmp=request[j][k]-1; - if((i>>tmp) &1) {cnt++; Break;} Wu } - } Aboutans=Max (ans,cnt); $ } - if(ans==m) printf ("bingo!\n"); - Elseprintf"sigh...\n"); -ans=0; Amemset (NUM,0,sizeof(num)); + } the return 0; -}View Code
Miscellaneous questions Clip