# bzoj 1798: [Ahoi2009]Seq 维护序列seq 线段树 区间乘法区间加法 区间求和

### 题目链接:

http://www.lydsy.com/JudgeOnline/problem.php?id=1798

### 代码:

  1 #include <bits/stdc++.h>
2 using namespace std;
3 typedef long long ll;
4 #define MS(a) memset(a,0,sizeof(a))
5 #define MP make_pair
6 #define PB push_back
7 const int INF = 0x3f3f3f3f;
8 const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
10     ll x=0,f=1;char ch=getchar();
11     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
12     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
13     return x*f;
14 }
15 //////////////////////////////////////////////////////////////////////////
16 const int maxn = 1e5+10;
17
18 ll a[maxn],mod,ans[maxn];
19
20 struct node{
21     int l,r;
23     void update(int a,int m,int len){
25         mul = ((ll)(m*mul))%mod;
26         sum = ((ll)((ll)sum*m+(ll)len*a))%mod;
27     }
28 }tree[maxn<<2];
29
30 void pushup(int rt){
31     tree[rt].sum = (tree[rt<<1].sum + tree[rt<<1|1].sum) % mod;
32 }
33
34 void pushdown(int rt,int len){
38         tree[rt].add = 0; tree[rt].mul = 1;
39     }
40 }
41
42
43 void build(int rt,int l,int r){
44     tree[rt].l = l, tree[rt].r = r;
45     tree[rt].add = 0, tree[rt].mul = 1;
46     if(l == r) {
47         tree[rt].sum = a[l];
48         return ;
49     }
50     int mid = (l+r)/2;
51     build(rt<<1,l,mid);
52     build(rt<<1|1,mid+1,r);
53     pushup(rt);
54 }
55
56 void update(int rt,int l,int r,int add,int mul){
57     int L = tree[rt].l, R = tree[rt].r;
58     if(l<=L && R<=r){
60         return ;
61     }
62     pushdown(rt,R-L+1);
63     int mid = (L+R)/2;
66     pushup(rt);
67 }
68
69 ll query(int rt,int l,int r){
70     int L = tree[rt].l, R = tree[rt].r;
71     if(l<=L && R<=r)
72         return tree[rt].sum;
73     else{
74         ll ans = 0;
75         pushdown(rt,R-L+1);
76         int mid = (L+R)/2;
77         if(l<=mid) ans = ((ll)(ans+query(rt<<1,l,r)))%mod;
78         if(r>mid) ans = ((ll)(ans+query(rt<<1|1,l,r)))%mod;
79         pushup(rt);
80         return ans;
81     }
82 }
83
84 int main(){
87     for(int i=1; i<=n; i++){
89     }
90     build(1,1,n);
92     while(m--){
94         if(op == 1){
96             update(1,a,b,0,x);
97         }else if(op == 2){
107 }