-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB.cpp
More file actions
44 lines (36 loc) · 928 Bytes
/
B.cpp
File metadata and controls
44 lines (36 loc) · 928 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
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
void solve() {
int t;
cin >> t;
while (t--) {
int n, q;
cin >> n >> q;
vector<int> points(n);
for (int i = 0; i < n; i++) {
cin >> points[i];
}
unordered_map<int, int> frequency;
for (int i = 0; i < n - 1; i++) {
int start = points[i];
int end = points[i + 1];
int segment_count = i + 1;
int count = end - start;
frequency[segment_count] += count;
}
for (int i = 0; i < q; i++) {
int ki;
cin >> ki;
cout << frequency[ki] << " ";
}
cout << endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}