-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorfulTable.cpp
More file actions
80 lines (75 loc) · 1.78 KB
/
ColorfulTable.cpp
File metadata and controls
80 lines (75 loc) · 1.78 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// https://codeforces.com/problemset/problem/1870/C
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int search(vector<int>& values, int val) {
int low = 0, mid, ans, high = values.size()-1;
while (high >= low) {
mid = (low+high)>>1;
if (values[mid] >= val) {
ans = mid;
high = mid-1;
} else {
low = mid+1;
}
}
return ans;
}
int search_rev(vector<int>& values, int val) {
int low = 0, mid, ans, high = values.size()-1;
while (high >= low) {
mid = (low+high)>>1;
if (values[mid] >= val) {
ans = mid;
low = mid+1;
} else {
high = mid-1;
}
}
return ans;
}
void solveCase() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<bool> freq(k+1, false);
for (int i = 0; i < n; ++i) {
freq[a[i]] = true;
}
vector<int> max(n);
vector<int> max_rev(n);
for (int i = 0, curr_max = 0; i < n; ++i) {
curr_max = std::max(curr_max, a[i]);
max[i] = curr_max;
}
for (int i = n-1, curr_max = 0; i >= 0; --i) {
curr_max = std::max(curr_max, a[i]);
max_rev[i] = curr_max;
}
vector<int> ans(k+1);
for (int i = 1; i <= k; ++i) {
if (!freq[i]) {
ans[i] = 0;
} else {
ans[i] = (search_rev(max_rev, i)-search(max, i)+1)*2;
}
}
for (int i = 1; i <= k; ++i) {
cout << ans[i] << " ";
}
cout << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int nC = 1;
cin >> nC;
for (int i = 1; i <= nC; i++) {
// cout << "\nTEST #" << i << ":\n";
solveCase();
}
return 0;
}