forked from ashvish183/Hacktoberfest2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
D_Line.cpp
107 lines (98 loc) · 2.3 KB
/
D_Line.cpp
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// ॐ नमः शिवाय
// ------------------
#include <bits/stdc++.h>
using namespace std;
#define himanshud959 \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define INF 1000000000000000003
#define mod 1e9 + 7
#define ll long long
#define V(i) vector<i>
#define P(i, j) pair<i, j>;
#define F first
#define S second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define ppf pop_front()
#define ppb pop_back()
#define mp(n, m) make_pair(n, m)
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define rep(i, a, b) for (size_t i = a; i < b; i++)
#define repp(i, a, b) for (size_t i = a; i <= b; i++)
#define sz(x) (int)x.size()
#define R return
#define str string
#define print(x) cout << (x) << '\n';
#define cyes cout << "YES" << '\n';
#define cno cout << "NO" << '\n';
#define csum cout << sum << '\n';
#define cans cout << ans << '\n';
#define ccnt cout << cnt << '\n';
#define cmone cout << '-1' << '\n';
#define cone cout << '1' << '\n';
#define czero cout << '0' << '\n';
#define nl "\n"
#define get(t) \
int t; \
cin >> t;
#define getl(t) \
ll t; \
cin >> t;
#define inputvec(n) \
vector<int> a(n); \
for (auto &i : a) \
{ \
cin >> i; \
}
#define getunique(v) \
{ \
sort(v.begin(), v.end()); \
v.erase(unique(v.begin(), v.end()), v.end()); \
}
void myTask()
{
getl(n);
str a;
cin >> a;
int arr[n];
ll ans = 0;
rep(i, 0, n)
{
if (a[i] == 'L')
ans += i;
else
ans += n - i - 1;
if (a[i] == 'L')
arr[i] = n - i - 1 - (i);
else
arr[i] = i - (n - i - 1);
}
sort(arr, arr + n);
reverse(arr, arr + n);
rep(i, 0, n)
{
if (arr[i] > 0)
{
ans += arr[i];
}
cout << ans << " ";
}
cout << nl;
}
int32_t main()
{
himanshud959 /* FIO */
#ifndef ONLINE_JUDGE
freopen("inp.txt", "r", stdin);
freopen("opt.txt", "w", stdout);
#endif
get(_);
while (_--)
{
myTask();
}
R 0;
}