-
Notifications
You must be signed in to change notification settings - Fork 0
/
main-50.cpp
54 lines (43 loc) · 1003 Bytes
/
main-50.cpp
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
#include <cstdio>
#include <algorithm>
#define MAX_N 102400
using namespace std;
long long nums[MAX_N];
long long sums[MAX_N];
int N, M;
int main()
{
fill_n(sums, MAX_N, 0);
scanf("%d %d", &N, &M);
for (int i = 1; i <= N; i++)
{
scanf("%lld", &nums[i]);
sums[i] = nums[i] + sums[i - 1];
}
for (int i = 0; i < M; i++)
{
int opt, l, r;
long long v;
scanf("%d", &opt);
if (opt == 1)
{
scanf("%d %d %lld", &l, &r, &v);
for (int p = l; p <= r; p++)
{
if (nums[p] % v == 0)
{
long long decr = nums[p] - nums[p] / v;
for (int j = p; j <= N; j++)
sums[j] -= decr;
nums[p] /= v;
}
}
}
else
{
scanf("%d %d", &l, &r);
printf("%lld\n", sums[r] - sums[l - 1]);
}
}
return 0;
}