-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUPDATEIT.cpp
More file actions
43 lines (42 loc) · 872 Bytes
/
UPDATEIT.cpp
File metadata and controls
43 lines (42 loc) · 872 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
#include <bits/stdc++.h>
using namespace std;
//long long n;
long long tree[1000002];
void update(long long idx ,long long val,long long n){
while (idx <= n){
tree[idx] += val;
idx += (idx & -idx);
}
}
long long read(long long idx){
long long sum = 0;
while (idx > 0){
sum += tree[idx];
idx -= (idx & -idx);
}
return sum;
}
int main() {
int t;
scanf("%d",&t);
while(t--)
{
long long n,u,l,r,val,x,q;
scanf("%lld%lld",&n,&u);
while(u--)
{
scanf("%lld%lld%lld",&l,&r,&val);
update(l+1,val,n);
update(r+2,-val,n);
}
scanf("%lld",&q);
while(q--)
{
scanf("%lld",&x);
printf("%lld\n",read(x+1));
}
memset(tree,0,1000002);
}
// your code goes here
return 0;
}