-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMO.cpp
More file actions
48 lines (39 loc) · 808 Bytes
/
MO.cpp
File metadata and controls
48 lines (39 loc) · 808 Bytes
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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 100010
int ara[MAX+5];
int L = 0, R = -1, sum = 0, ans[MAX];
struct query
{
int id,l,r,mod;
query() {};
} query[MAX+5];
void add(int x,int mod)
{
sum+=(ara[x]%mod);
}
void rem(int x,int mod)
{
sum-=(ara[x]%mod);
}
int main()
{
int n,q;
cin >> n >> q;
for(int i=0; i<n; i++) cin>>ara[i];
for(int i=0; i<q; i++)
{
cin >> query[i].l >> query[i].r >> query[i].mod;
query[i].id = i;
}
for(int i=0; i<q; i++)
{
while(query[i].r>R) add(++R,query[i].mod);
while(query[i].l>L) rem(L++,query[i].mod);
while(query[i].r<R) rem(R--,query[i].mod);
while(query[i].l<L) add(--L,query[i].mod);
cout<<sum<<endl;
}
return 0;
}