# bzoj1798--维护序列--线段树

7 43
1 2 3 4 5 6 7
5
1 2 5 5
3 2 4
2 3 7 9
3 1 3
3 4 7

2
35
8

## HINT

【样例说明】

N= 10 1000 1000 10000 60000 70000 80000 90000 100000 100000
M= 10 1000 1000 10000 60000 70000 80000 90000 100000 100000

码来当板子咯qwq

  1 #include<cmath>
2 #include<algorithm>
3 #include<cstdio>
4 #include<iostream>
5 #include<cstring>
6 #define ll long long
7 using namespace std;
8 const int maxn=100009;
9 int n,m,mod,a[maxn];
10 struct tree
11 {
12     int l,r;
14 }tr[maxn<<2];
15
16 void build(int x,int la,int ra)
17 {
18     tr[x].l=la;tr[x].r=ra;
20     if(la==ra)
21     {
22         tr[x].val=a[la]%mod;
23         return;
24     }
25     int mid=(la+ra)>>1;
26     build(x<<1,la,mid);build(x<<1|1,mid+1,ra);
27     tr[x].val=(tr[x<<1].val+tr[x<<1|1].val)%mod;
28     return;
29 }
30
31 void down(int x)
32 {
34
35     tr[x<<1].mul=(tr[x<<1].mul*tr[x].mul)%mod;
36     tr[x<<1|1].mul=(tr[x<<1|1].mul*tr[x].mul)%mod;
37
40
43
45 }
46
47 void multiply(int x,int la,int ra,int num)
48 {
49     if(tr[x].l>ra||tr[x].r<la)return;
50
51     if(la<=tr[x].l&&tr[x].r<=ra)
52     {
53         tr[x].mul=(tr[x].mul*num)%mod;
55         tr[x].val=(tr[x].val*num)%mod;
56         return;
57     }
58     if(tr[x].l==tr[x].r)return;
59     down(x);
60     multiply(x<<1,la,ra,num);
61     multiply(x<<1|1,la,ra,num);
62     tr[x].val=(tr[x<<1].val+tr[x<<1|1].val)%mod;
63 }
64
65 void add(int x,int la,int ra,int num)
66 {
67     if(tr[x].l>ra||tr[x].r<la)return;
68
69     if(la<=tr[x].l&&tr[x].r<=ra)
70     {
72         tr[x].val=(tr[x].val+(tr[x].r-tr[x].l+1)*num)%mod;
73         return;
74     }
75     if(tr[x].l==tr[x].r)return;
76
77     down(x);
80     tr[x].val=(tr[x<<1].val+tr[x<<1|1].val)%mod;
81     return;
82 }
83
84 ll ask(int x,int la,int ra)
85 {
86     if(tr[x].l>ra||tr[x].r<la)return 0;
87
88     if(la<=tr[x].l&&tr[x].r<=ra)
89         return tr[x].val%mod;
90
91     if(tr[x].l==tr[x].r)return 0;
92
93     down(x);
95 }
96
97 int main()
98 {
99     scanf("%d%d",&n,&mod);
100     for(int i=1;i<=n;i++)
101         scanf("%d",&a[i]);
102     build(1,1,n);
103     scanf("%d",&m);
104     while(m--)
105     {
106         int op;
107         scanf("%d",&op);
108         if(op==1)
109         {
110             int t,g,c;
111             scanf("%d%d%d",&t,&g,&c);
112             multiply(1,t,g,c);
113         }
114         else if(op==2)
115         {
116             int t,g,c;
117             scanf("%d%d%d",&t,&g,&c);
119         }
120         else if(op==3)
121         {
122             int t,g;
123             scanf("%d%d",&t,&g);
128 }