Chunked Learning Notes

Source: Internet
Author: User

Recently, when I was doing a senior simulation, I found that there are a lot of parts that can be divided, so I learned to divide the pieces.

Sub-block is actually a way to do the idea, because I just learned a linear block, so light talk about the linear bar: In fact, the general idea is when we want to a larger size of the problem to modify or query, with data structure is not good to maintain, but the scope is too large and can not use violence to do, So we can divide this big data into about sqrt (n), but not necessarily.

Put together an example: a paper from the national team



Because it is the person who wrote the paper did not have the data, I took a shot, I think it should be a, if anyone has made a mistake, remember to tell me.

#include <iostream> #include <cstdio> #include <cstring>using namespace std; #include <cmath> int N,m,a[100010]={0},len,n=1,d[400]={0},num[400]={0},influence[400][400];char Ch;int Main () {freopen ("cin.in", "R" , stdin), Freopen ("A.out", "w", stdout), int i,j,x,y;scanf ("%d%d", &n,&m), for (I=1;i<=n;++i) scanf ("%d", &a[i]); len=sqrt (n), while (1) {n+=1;if (n*len==n) Break;else if (n*len>n) break;}  for (I=1;i<=n;++i) for (j=1;j<=len;++j) {if ((i-1) *len+j>n) break;  num[i]+=a[(i-1) *len+j]; }if (len==1) {while (m--) {int t,x,y;cin>>t>>x>>y;if (t==1) {for (j=1;j<=n;j+=x) a[j]+=y;} Else{int ans=0;for (j=x;j<=y;++j) Ans+=a[j];cout<<ans<<endl;}} Else{while (m--) {int t;scanf ("%d%d%d", &t,&x,&y), if (t==1) {if (X>=len) {i=1;while (i<=n) {if (i%len== 0) Num[i/len]+=y;else num[i/len+1]+=y;a[i]+=y;i+=x;}} else d[x]+=y;} Else{int ans=0,l,r,ll,rr;l= (x%len==0) X/len: (x/len+1); r= (y%len==0)? (Y/len):(y/len+1); ll=len* (L-1) +1==x?l:l+1;rr=y%len==0?R:r-1;for (i=ll;i<=rr;++i) ans+=num[i];if (LL&LT;=RR) {if (L&LT;LL) for (i=x;i<=l*len;++i) ans+=a[i];if (R&GT;RR) for (I=rr*len+1;i<=y;++i) ans+=a[i];} Else{for (I=x;i<=y;++i) ans+=a[i];}    for (i=1;i<=len;++i) {int r1,r2;    r1=x/i;    if (x%i>1) r1+=1;    r2=y/i;    if (y%i>=1) r2+=1;    ans+= (R2-R1) *d[i]; if (i==1) ans+=d[i];} printf ("%d\n", ans);   }}}}


Chunked Learning Notes

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.