要不是神犇们说了题目大意我才懒得做,语言障碍QAQ

区间取模,调得有点久,线段树还得多练练。。。

 1 #include<bits/stdc++.h>
 2 #define inc(i,l,r) for(i=l;i<=r;i++)
 3 #define dec(i,l,r) for(i=l;i>=r;i--)
 4 #define inf 1e9
 5 #define NM 100000+5
 6 #define mem(a) memset(a,0,sizeof(a))
 7 using namespace std;
 8 struct info{
 9     long long s,m;
10     info(int x=0):s(x),m(x){
11     }
12 }T[3*NM];
13 info operator+(const info&x,const info&y){
14     info f;
15     f.s=x.s+y.s;
16     f.m=max(x.m,y.m);
17     return f;
18 }
19 int n,m,i,x,y,t;
20 void build(int i,int x,int y){
21     int t=(x+y)/2;
22     if(x==y){
23         scanf("%d",&x);
24         T[i]=info(x);
25         return;
26     }
27     build(i*2,x,t);build(i*2+1,t+1,y);
28     T[i]=T[i*2]+T[i*2+1];
29 }
30 long long sum(int i,int x,int y,int a,int b){
31     int t=(x+y)/2;
32     if(b<x||y<a)return 0;
33     if(x>=a&&b>=y)return T[i].s;
34     return sum(i*2,x,t,a,b)+sum(i*2+1,t+1,y,a,b);
35 }
36 void ch(int i,int x,int y,int a,int b){
37     int t=(x+y)/2;
38     if(x==y){
39         T[i]=info(b);
40         return;
41     }
42     if(a<=t)ch(i*2,x,t,a,b);
43     else ch(i*2+1,t+1,y,a,b);
44     T[i]=T[i*2]+T[i*2+1];
45 }
46 void mod(int i,int x,int y,int a,int b,int k){
47     int t=(x+y)/2;
48     if(T[i].m<k)return;
49     if(b<x||a>y)return;
50     if(x==y){
51         T[i].m=T[i].s=T[i].s%k;
52         return;
53     }
54     mod(i*2,x,t,a,b,k);mod(i*2+1,t+1,y,a,b,k);
55     T[i]=T[i*2]+T[i*2+1];
56 }
57 int main(){
58     scanf("%d%d",&n,&m);
59     build(1,1,n);
60     inc(i,1,m){
61         scanf("%d",&x);
62         if(x==1){
63             scanf("%d%d",&x,&y);
64             printf("%I64d\n",sum(1,1,n,x,y));
65         }else if(x==2){
66             scanf("%d%d%d",&x,&y,&t);
67             mod(1,1,n,x,y,t);
68         }else{
69             scanf("%d%d",&x,&y);
70             ch(1,1,n,x,y);
71         }
72     }
73     return 0;
74 }
View Code

 

posted on 2015-08-13 16:55  onlyRP  阅读(194)  评论(0编辑  收藏  举报