Skip to content

Commit a989546

Browse files
Add files via upload
1 parent 0a0141e commit a989546

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <cstdio>
2+
#include <vector>
3+
using namespace std;
4+
5+
void solve()
6+
{
7+
int no_of_elements, no_of_updates;
8+
scanf("%d %d", &no_of_elements, &no_of_updates);
9+
10+
vector <int> updates_starting_here(no_of_elements + 2, 0);
11+
while(no_of_updates--)
12+
{
13+
int left, right, value;
14+
scanf("%d %d %d", &left, &right, &value);
15+
16+
updates_starting_here[left + 1] += value;
17+
updates_starting_here[right + 2]-= value;
18+
}
19+
20+
vector <int> element(no_of_elements + 1, 0);
21+
for(int i = 1; i <= no_of_elements; i++)
22+
element[i] = element[i - 1] + updates_starting_here[i];
23+
24+
int no_of_queries;
25+
scanf("%d", &no_of_queries);
26+
27+
while(no_of_queries--)
28+
{
29+
int i;
30+
scanf("%d", &i);
31+
32+
printf("%d\n", element[i + 1]);
33+
}
34+
}
35+
36+
int main()
37+
{
38+
int no_of_test_cases;
39+
scanf("%d", &no_of_test_cases);
40+
41+
while(no_of_test_cases--)
42+
solve();
43+
44+
return 0;
45+
}

0 commit comments

Comments
 (0)