loj6277 数列分块入门题1

裸题分块。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 int a[100005],b[10005],n,m,t1,t2,t3,t4,sq;
 5 
 6 int main(){
 7     ios::sync_with_stdio(false);
 8     cin>>n;
 9     sq=(int)sqrt(n);
10     for(int i=1;i<=n;i++) cin>>a[i];
11     for(int i=1;i<=n;i++) {
12         cin>>t1>>t2>>t3>>t4;
13         if(t1==0){
14             if((t2-1)/sq+1 == (t3-1)/sq+1) {
15                 for(int j=t2;j<=t3;j++) 
16                     a[j]+=t4;
17             }
18             else {
19                 for(int j=t2;j<=((t2-1)/sq)*sq+sq;j++) 
20                     a[j]+=t4;
21                 for(int j=((t3-1)/sq)*sq+1;j<=t3;j++)
22                     a[j]+=t4;    
23                 for(int j=(t2-1)/sq+1+1;j<(t3-1)/sq+1;j++) 
24                     b[j]+=t4;
25             }
26         }
27         else{
28             printf("%d
",a[t3]+b[(t3-1)/sq+1]);
29         }
30     }
31 }
原文地址:https://www.cnblogs.com/mollnn/p/8439726.html