-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHcearth_factorial_arr.cpp
More file actions
executable file
·69 lines (59 loc) · 1.13 KB
/
Hcearth_factorial_arr.cpp
File metadata and controls
executable file
·69 lines (59 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include<bits/stdc++.h>
#define z5 100001
#define z9 1000000007
#define M 10000000
using namespace std;
unsigned long long num;
unsigned long int f[M];
unsigned long long a[z5];
void facto(){
f[1]=1;
for(int i=2;i<=M;i++)
f[i]=(i*f[i-1])%z9;
}
long int getFacto(long long n){
long int ft;
for(long long i=M+1;i<=n;i++)
ft=(i*f[i-1])%z9;
return ft;
}
int main(){
facto();
long int n,m,t,l,r,min=INT_MAX,max=INT_MIN;
scanf("%ld%ld",&n,&m);
for(int i=1;i<=n;i++)
scanf("%ulld",&a[i]);
for(int i=0;i<m;i++){
scanf("%ld%ld%ld",&t,&l,&r);
long long sm=0;
switch(t){
case 1: a[l]++;
if(r!=n){
r++;
a[r]--;
if(r>max)
r=max;
}
if(l<min)
l=min;
break;
case 2:
if(min!=INT_MAX||max!=INT_MIN)
for(int i=min+1;i<=max;i++)
a[i]+=a[i-1];
for(int i=l;i<=r;i++){
if(a[i]<=M)
sm=(sm+f[a[i]])%z9;
else
sm=(sm+getFacto(a[i]))%z9;
}
printf("%lld",sm);
min=INT_MAX;
max=INT_MIN;
break;
case 3: a[l]+=r;
break;
}
}
return 0;
}