text stringlengths 49 983k |
|---|
#include <bits/stdc++.h>
using namespace std;
char ar[200005];
int main() {
int tc = 1;
scanf("%d", &tc);
while (tc--) {
int n, m;
scanf("%d %d", &n, &m);
scanf("%s", ar);
string s = ar;
vector<int> mis(m);
vector<long long> pus(n + 1, 0);
for (int i = 0; i < m; i++) {
scanf("%d", &mis[i]);
pus[0]++;
pus[mis[i]]--;
}
pus[0]++;
for (int i = 1; i < n; i++) {
pus[i] += pus[i - 1];
}
vector<long long> ans(26, 0);
for (int i = 0; i < n; i++) {
ans[s[i] - 'a'] += pus[i];
}
for (int i = 0; i < 26; i++) printf("%lld%c", ans[i], " \n"[i + 1 == 26]);
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int n, m;
cin >> n >> m;
string s;
cin >> s;
long long int arr[m];
for (long long int i = 0; i < m; i++) {
cin >> arr[i];
}
vector<long long int> v(n);
for (long long int i = 0; i < m; i++) {
v[arr[i] - 1]++;
}
for (long long int i = n - 1; i > 0; i--) {
v[i - 1] += v[i];
}
long long int hash[123];
memset(hash, 0, sizeof(hash));
for (long long int i = 0; i < n; i++) {
hash[s[i]] += (v[i] + 1);
}
for (long long int i = 97; i < 123; i++) {
cout << hash[i] << " ";
}
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int t, n, m, sum[26][200005];
long long ans[26];
char s[200005];
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &m);
scanf("%s", s + 1);
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 26; j++) sum[j][i] = sum[j][i - 1];
sum[s[i] - 'a'][i]++;
}
memset(ans, 0, sizeof(ans));
while (m--) {
int x;
scanf("%d", &x);
for (int i = 0; i < 26; i++) ans[i] += sum[i][x];
}
for (int i = 0; i < 26; i++) ans[i] += sum[i][n];
for (int i = 0; i < 26; i++) printf("%lld ", ans[i]);
printf("\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<long long> cnt(n);
for (int i = 0; i < m; i++) {
int p;
cin >> p;
++cnt[p - 1];
}
for (int i = n - 1; i >= 1; i--) {
cnt[i - 1] += cnt[i];
}
int ans[26] = {0};
for (int i = 0; i < n; i++) {
ans[s[i] - 'a'] += cnt[i];
ans[s[i] - 'a']++;
}
for (int i = 0; i < 26; i++) {
cout << ans[i] << " ";
}
cout << "\n";
}
int main() {
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 9;
int p[N], ans[N];
void solve() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
for (int i = 1; i <= m; i++) cin >> p[i];
sort(p + 1, p + m + 1);
for (int i = 1; i <= n; i++) {
int l = 1, r = m;
while (l <= r) {
int mid = (l + r) / 2;
if (p[mid] < i)
l = mid + 1;
else
r = mid - 1;
}
ans[s[i - 1] - 'a'] += m - r + 1;
}
for (int i = 0; i < 26; i++) {
cout << ans[i] << ' ';
ans[i] = 0;
}
cout << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(), cout.tie();
int t;
cin >> t;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
int pref[200001], ans[26];
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
memset(pref, 0, sizeof pref);
memset(ans, 0, sizeof ans);
int n, m;
string s;
cin >> n >> m >> s;
for (int i = 0, p; i < m; ++i) {
cin >> p;
++pref[p - 1];
}
for (int i = n - 1; i > 0; --i) {
pref[i - 1] += pref[i];
}
for (int i = 0; i < n; ++i) {
ans[s[i] - 'a'] += pref[i];
++ans[s[i] - 'a'];
}
for (int i = 0; i < 26; ++i) {
cout << ans[i] << " ";
}
cout << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long int n, p;
cin >> n >> p;
string s;
cin >> s;
long long int parr[p + 1];
for (int i = 0; i < p; i++) cin >> parr[i];
long long int arr[n + 1];
memset(arr, 0, sizeof(arr));
for (int i = 0; i < p; i++) {
arr[parr[i] - 1] += 1;
}
long long int tmp = 0;
arr[n] = 1;
for (int i = n; i >= 0; i--) {
if (arr[i] != 0) {
tmp += arr[i];
arr[i] = tmp;
} else {
arr[i] += tmp;
}
}
int freq[27];
memset(freq, 0, sizeof(freq));
for (int i = 0; i < n; i++) {
freq[s[i] - 'a'] += arr[i];
}
for (int i = 0; i < 26; i++) {
cout << freq[i] << " ";
}
cout << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
set<int> st;
int main() {
int t;
scanf("%d", &t);
int n, m;
string s;
map<char, int> mp;
int arr[200005], ans[26], cnt[26];
for (int i = 0; i < t; ++i) {
for (int i = 0; i < 26; ++i) ans[i] = 0;
scanf("%d", &n);
scanf("%d", &m);
cin >> s;
for (int i = 0; i < m; ++i) {
scanf("%d", &arr[i]);
}
sort(arr, arr + m);
mp.clear();
st.clear();
int prev = 0;
for (int k = 0; k < m; ++k) {
if (st.find(arr[k]) == st.end()) {
for (int i = 0; i < 26; ++i) {
ans[i] += mp[char('a' + i)];
}
for (int j = prev; j < arr[k]; ++j) {
ans[s[j] - 'a']++;
mp[s[j]]++;
}
} else {
for (int i = 0; i < 26; ++i) {
ans[i] += mp[char('a' + i)];
}
}
prev = arr[k];
}
for (int j = 0; j < 26; ++j) {
cout << ans[j] + count(s.begin(), s.end(), char('a' + j)) << " ";
}
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char ar[200005];
int main() {
int tc;
scanf("%d", &tc);
while (tc--) {
int n, m;
scanf("%d %d %s", &n, &m, ar);
vector<int> mis(n + 2, 0), ans(26, 0);
for (int i = 0; i < m; i++) {
int a;
scanf("%d", &a);
mis[1]++;
mis[a + 1]--;
}
mis[1]++;
for (int i = 1; i <= n; i++) {
mis[i] += mis[i - 1];
ans[ar[i - 1] - 'a'] += mis[i];
}
for (int i = 0; i < 26; i++) {
printf("%d%c", ans[i], " \n"[i + 1 == 26]);
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
long long len, w, n;
cin >> t;
while (t--) {
long long a[200001] = {0}, ans[26] = {0};
cin >> len >> w;
string s;
cin >> s;
for (long long i = 0; i < w; i++) {
cin >> n;
a[0]++;
a[n]--;
}
a[0]++;
a[len]--;
for (int i = 1; i <= len; i++) {
a[i] += a[i - 1];
}
for (int i = 0; i < len; i++) {
ans[s[i] - 'a'] += a[i];
}
for (int i = 0; i < 26; i++) {
cout << ans[i] << " ";
ans[i] = 0;
}
cout << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF = 0x3f3f3f3f;
const long long mod = 1000000009;
const long long maxn = 200005;
void std_quick_io() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
long long cot[26][maxn];
int n, m;
int lowbit(int x) { return x & (-x); }
long long sum1(int x, int k) {
long long s = 0;
while (x) {
s += cot[k][x];
x -= lowbit(x);
}
return s;
}
void update1(int x, long long y, int k) {
while (x < n + 1) {
cot[k][x] += y;
x += lowbit(x);
}
}
int main() {
int t;
cin >> t;
while (t--) {
scanf("%d%d", &n, &m);
for (int i = 0; i < 26; i++)
for (int j = 0; j < n + 1; j++) cot[i][j] = 0;
string s;
cin >> s;
vector<int> res(m);
for (int i = 0; i < m; i++) {
scanf("%d", &res[i]);
}
res.push_back(n);
for (int i = 0; i < n; i++) {
update1(i + 1, 1LL, (int)(s[i] - 'a'));
}
map<int, long long> ma;
for (int j = 0; j <= m; j++) {
ma[res[j]]++;
}
vector<long long> ans(26, 0);
for (auto it = ma.begin(); it != ma.end(); it++) {
for (int i = 0; i < 26; i++)
ans[i] += (it->second) * (sum1((it->first), i));
}
for (int i = 0; i < 26; i++) {
if (i != 0) printf(" ");
printf("%lld", ans[i]);
}
printf("\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char s1[10000020];
long long int ar1[200009];
long long int ar2[200009];
int main() {
long long int test, i, n;
cin >> test;
while (test--) {
long long int ar3[30] = {0};
for (i = 0; i < 100005; i++) {
ar1[i] = 0;
ar2[i] = 0;
}
long long int m, k;
cin >> m >> k;
cin >> s1;
long long int l = strlen(s1);
for (i = 0; i < k; i++) {
cin >> ar1[i];
}
sort(ar1, ar1 + k);
long long int cnt = 2;
for (i = k - 1; i >= 0; i--) {
ar2[ar1[i] - 1] = cnt;
cnt++;
}
long long int mx = 1;
for (i = l - 1; i >= 0; i--) {
if (ar2[i] >= mx) mx = ar2[i];
ar2[i] = mx;
}
for (i = 0; i < l; i++) {
ar3[s1[i] - 'a'] += ar2[i];
}
for (i = 0; i < 26; i++) cout << ar3[i] << " ";
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int ans[30];
long long int cnt[200005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int i, m, n, t, x;
char s[200005];
cin >> t;
while (t--) {
cin >> n >> m >> s + 1;
for (i = 1; i <= n; i++) cnt[i] = 0;
for (i = 1; i <= m; i++) cin >> x, ++cnt[1], --cnt[x + 1];
++cnt[1];
for (i = 1; i <= n; i++) cnt[i] += cnt[i - 1];
for (i = 0; i < 26; i++) ans[i] = 0;
for (i = 1; i <= n; i++) ans[s[i] - 'a'] += cnt[i];
for (i = 0; i < 26; i++) cout << ans[i] << ' ';
cout << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 1e6 + 5;
const int mod = 998244353;
int p[N];
long long f[N];
char s[N];
long long ans[30];
int main() {
int t;
scanf("%d", &t);
while (t--) {
memset(ans, 0, sizeof(ans));
int n, m;
scanf("%d%d", &n, &m);
scanf("%s", s + 1);
for (int i = 0; i <= n; i++) {
f[i] = 0;
}
for (int i = 1; i <= m; i++) {
scanf("%d", &p[i]);
f[p[i]]++;
}
for (int i = n - 1; i >= 1; i--) {
f[i] = f[i] + f[i + 1];
}
for (int i = 1; i <= n; i++) {
ans[s[i] - 'a']++;
ans[s[i] - 'a'] += f[i];
}
for (int i = 0; i < 26; i++) {
printf("%lld%c", ans[i], " \n"[i == 25]);
}
}
return 0;
}
|
#include <bits/stdc++.h>
const long long OO = LLONG_MAX;
const long long _OO = LLONG_MIN;
const long long MOD = 1e9 + 7;
const double PI = acos(-1);
const double EPSILON = std::numeric_limits<double>::epsilon();
bool double_comp(double a, double b) { return fabs(a - b) < EPSILON; }
unsigned long long gcd(unsigned long long a, unsigned long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n, m;
string s;
cin >> n >> m >> s;
long long prefix[200001] = {0};
for (int i = 0; i < m; i++) {
int p;
cin >> p;
prefix[1]++;
if (p + 1 != n + 1) prefix[p + 1]--;
}
long long freq[26] = {0};
freq[s[0] - 'a'] = prefix[1] + 1;
for (int i = 2; i <= n; i++) {
prefix[i] += prefix[i - 1];
freq[s[i - 1] - 'a'] += prefix[i];
freq[s[i - 1] - 'a']++;
}
for (int i = 0; i < 26; i++) {
cout << freq[i] << " ";
}
cout << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, t, m, x;
vector<int> sum(200001);
vector<int> f(26);
string s;
cin >> t;
bool ans;
while (t--) {
cin >> n >> m;
cin >> s;
for (int i = 0; i < 26; i++) f[i] = 0;
for (int i = 0; i < n; i++) sum[i] = 0, f[s[i] - 'a']++;
sum[0] = m;
for (int i = 0; i < m; i++) {
cin >> x;
sum[x] -= 1;
}
x = 0;
for (int i = 0; i < n; i++) {
x += sum[i];
f[s[i] - 'a'] += x;
}
for (int i = 0; i < 26; i++) cout << f[i] << " ";
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int m, n, l = 0, x = 0, ts;
cin >> ts;
while (ts--) {
string s;
cin >> m >> n;
long long int a[n + 10];
map<long long int, long long int> p;
cin >> s;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (int i = 0; i < m; i++) {
p[s[i]]++;
l = lower_bound(a, a + n, i + 1) - a;
if (a[l - 1] != i + 1) {
x = n - l;
} else {
l--;
x = n - l;
}
p[s[i]] += x;
}
for (int i = 97; i <= 122; i++) {
char ch = i;
cout << p[ch] << " ";
}
cout << endl;
memset(a, 0, sizeof(a));
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
long long int res = 1;
a %= 1000000007;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a % 1000000007;
a = a * a % 1000000007;
}
return res;
}
long long int modInverse(long long int a) { return power(a, 1000000007 - 2); }
const int N = 500023;
bool vis[N];
vector<int> adj[N];
void solve() {
long long int n, m;
cin >> n >> m;
string s;
cin >> s;
s = '&' + s;
map<long long int, long long int> repeat;
for (long long int i = 0; i < m; i++) {
long long int c;
cin >> c;
repeat[c]++;
}
long long int cnt[28] = {0};
long long int final[28] = {0};
for (int i = 1; i <= n; i++) {
cnt[s[i] - 'a']++;
final[s[i] - 'a']++;
for (int j = 0; j < 26; j++) {
final[j] += (cnt[j] * repeat[i]);
}
}
for (int i = 0; i < 26; i++) {
cout << final[i] << ' ';
}
cout << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T = 1;
cin >> T;
int t = 0;
while (t++ < T) {
solve();
}
cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
<< "ms\n";
}
|
#include <bits/stdc++.h>
using namespace std;
char s[200005];
int cnt[200005][26];
long long tot[26];
int main() {
int T = 1;
cin >> T;
while (T--) {
int n, m;
cin >> n >> m;
scanf("%s", s + 1);
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 26; j++) cnt[i][j] = cnt[i - 1][j];
cnt[i][s[i] - 'a']++;
}
memset(tot, 0, sizeof(tot));
for (int i = 0; i < 26; i++) tot[i] += cnt[n][i];
for (int i = 1; i <= m; i++) {
int t;
scanf("%d", &t);
for (int j = 0; j < 26; j++) tot[j] += cnt[t][j];
}
for (int i = 0; i < 26; i++) printf("%lld ", tot[i]);
puts("");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long MAX_N = 2e5 + 11;
char s[MAX_N];
long long freq[26 + 1];
long long p[MAX_N], pref[MAX_N];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
long long tc;
cin >> tc;
while (tc--) {
long long n, m;
cin >> n >> m;
memset(freq, 0, sizeof freq);
for (long long i = 1; i <= n; i++) {
pref[i] = 0;
cin >> s[i];
freq[s[i] - 'a']++;
}
pref[n + 1] = 0;
for (long long i = 1; i <= m; i++) {
long long x;
cin >> x;
pref[1]++;
pref[x + 1]--;
}
for (long long i = 1; i <= n; i++) {
pref[i] += pref[i - 1];
freq[s[i] - 'a'] += pref[i];
}
for (long long i = 0; i < 26; i++) cout << freq[i] << " ";
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
void solve() {
long long int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<long long int> p(m);
for (int i = 0; i < m; i++) {
cin >> p[i];
}
vector<vector<long long int>> v(n, vector<long long int>(26, 0));
v[0][s[0] - 'a']++;
for (int i = 1; i < n; i++) {
v[i][s[i] - 'a']++;
for (int j = 0; j < 26; j++) {
v[i][j] += v[i - 1][j];
}
}
map<long long int, long long int> m1;
for (auto x : p) {
m1[x]++;
}
long long int count = 0;
vector<long long int> res(26, 0);
for (auto x : m1) {
long long int val = x.second;
vector<long long int> v1 = v[x.first - 1];
for (int i = 0; i < 26; i++) {
res[i] += (val)*v1[i];
}
}
for (int i = 0; i < n; i++) {
res[s[i] - 'a']++;
}
for (auto x : res) {
cout << x << " ";
}
cout << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
while (q--) {
map<char, long long int> d;
string p;
int n, m;
cin >> n >> m;
cin >> p;
vector<map<char, long long int>> x(n + 2);
for (int i = 0; i < n; i++) {
x[i][p[i]]++;
for (char j = 'a'; j <= 'z'; j++) {
x[i + 1][j] = x[i][j];
if (i == n - 1) d[j] = x[i][j];
}
}
for (int i = 0; i < m; i++) {
int y;
cin >> y;
y--;
for (char j = 'a'; j <= 'z'; j++) {
d[j] += x[y][j];
}
}
for (char j = 'a'; j <= 'z'; j++) {
cout << d[j] << " ";
}
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 5;
using namespace std;
int t, n, m, x;
int a[N][26] = {0}, vis[26] = {0};
char c[N] = {0};
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &m);
scanf("%s", c);
for (int i = 0; i < 26; i++) a[0][i] = 0;
for (int i = 0; i < n; i++) {
if (i > 0) {
for (int j = 0; j < 26; j++) {
a[i][j] = a[i - 1][j];
}
}
a[i][c[i] - 'a']++;
}
for (int i = 0; i < 26; i++) vis[i] = a[n - 1][i];
while (m--) {
cin >> x;
for (int i = 0; i < 26; i++) {
vis[i] += a[x - 1][i];
}
}
printf("%d", vis[0]);
for (int i = 1; i < 26; i++) {
printf(" %d", vis[i]);
}
printf("\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
const long long mod = 1000000009;
const long long maxn = 200005;
void std_quick_io() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main() {
std_quick_io();
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
vector<vector<long long> > cot(n, vector<long long>(26));
string s;
cin >> s;
vector<long long> res(m);
for (int i = 0; i < m; i++) {
cin >> res[i];
res[i]--;
}
res.push_back(n - 1);
cot[0][s[0] - 'a'] = 1;
for (int i = 1; i < n; i++) {
for (int j = 0; j < 26; j++) {
if (s[i] - 'a' == j) {
cot[i][j] = cot[i - 1][j] + 1LL;
} else {
cot[i][j] = cot[i - 1][j];
}
}
}
vector<long long> ans(26, 0);
for (int i = 0; i < 26; i++) {
for (int j = 0; j <= m; j++) {
ans[i] += cot[res[j]][i];
}
}
for (int i = 0; i < 26; i++) {
if (i != 0) cout << " ";
cout << ans[i];
}
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 50;
int T, N, M, segs[MAXN], ans[30], stat[30];
int i, lptr, rptr;
string s;
int main() {
for (cin >> T; T--;) {
cin >> N >> M >> s;
for (i = 0; i < 30; i++) ans[i] = stat[i] = 0;
for (i = 0; i < M; i++) cin >> segs[i];
segs[M] = N;
sort(segs, segs + M);
for (lptr = rptr = 0; lptr <= M; lptr++) {
while (segs[lptr] > rptr) stat[s[rptr++] - 'a'] += 1;
for (i = 0; i < 30; i++) ans[i] += stat[i];
}
for (i = 0; i < 26; i++) cout << ans[i] << " ";
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<int> pref(n);
fill(pref.begin(), pref.end(), 0);
for (int a, i = 0; i < m; i++) {
cin >> a;
pref[a - 1]++;
}
for (int i = n - 1; i > 0; i--) pref[i - 1] += pref[i];
int freq[27] = {0};
for (int i = 0; i < n; i++) {
freq[s[i] - 'a']++;
freq[s[i] - 'a'] += pref[i];
}
for (int i = 0; i < 26; i++) cout << freq[i] << " ";
cout << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<int> p(m);
for (int i = 0; i < m; ++i) cin >> p[i];
vector<int> count(n);
for (int i = 0; i < m; ++i) {
count[p[i] - 1]++;
}
count[n - 1]++;
for (int i = count.size() - 2; i >= 0; --i) count[i] += count[i + 1];
map<char, int> mp;
for (int i = 0; i < count.size(); ++i) {
mp[s[i]] += count[i];
}
for (char c = 'a'; c <= 'z'; ++c) {
if (mp.count(c))
cout << mp[c] << " ";
else
cout << 0 << " ";
}
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> v;
map<long long int, map<long long int, long long int> > u;
vector<long long int> w;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n, m, i, j, k, p, q, o, l, s, t;
string a, b;
cin >> t;
while (t--) {
long long int AA = 0, BB = 0, CC = 0, DD = 0, EE = 0, FF = 0, GG = 0,
HH = 0, II = 0, JJ = 0, KK = 0, LLL = 0, MM = 0, NN = 0,
OO = 0, PP = 0, QQ = 0, RR = 0, SS = 0, TT = 0, UU = 0,
VV = 0, WW = 0, XX = 0, YY = 0, ZZ = 0;
cin >> n >> m;
cin >> a;
for (i = 0; i < a.size(); i++) {
v[a[i] - 'a']++;
if (a[i] == 'a') {
AA++;
}
if (a[i] == 'b') {
BB++;
}
if (a[i] == 'c') {
CC++;
}
if (a[i] == 'd') {
DD++;
}
if (a[i] == 'e') {
EE++;
}
if (a[i] == 'f') {
FF++;
}
if (a[i] == 'g') {
GG++;
}
if (a[i] == 'h') {
HH++;
}
if (a[i] == 'i') {
II++;
}
if (a[i] == 'j') {
JJ++;
}
if (a[i] == 'k') {
KK++;
}
if (a[i] == 'l') {
LLL++;
}
if (a[i] == 'm') {
MM++;
}
if (a[i] == 'n') {
NN++;
}
if (a[i] == 'o') {
OO++;
}
if (a[i] == 'p') {
PP++;
}
if (a[i] == 'q') {
QQ++;
}
if (a[i] == 'r') {
RR++;
}
if (a[i] == 's') {
SS++;
}
if (a[i] == 't') {
TT++;
}
if (a[i] == 'u') {
UU++;
}
if (a[i] == 'v') {
VV++;
}
if (a[i] == 'w') {
WW++;
}
if (a[i] == 'x') {
XX++;
}
if (a[i] == 'y') {
YY++;
}
if (a[i] == 'z') {
ZZ++;
}
u[i + 1][0] = AA;
u[i + 1][1] = BB;
u[i + 1][2] = CC;
u[i + 1][3] = DD;
u[i + 1][4] = EE;
u[i + 1][5] = FF;
u[i + 1][6] = GG;
u[i + 1][7] = HH;
u[i + 1][8] = II;
u[i + 1][9] = JJ;
u[i + 1][10] = KK;
u[i + 1][11] = LLL;
u[i + 1][12] = MM;
u[i + 1][13] = NN;
u[i + 1][14] = OO;
u[i + 1][15] = PP;
u[i + 1][16] = QQ;
u[i + 1][17] = RR;
u[i + 1][18] = SS;
u[i + 1][19] = TT;
u[i + 1][20] = UU;
u[i + 1][21] = VV;
u[i + 1][22] = WW;
u[i + 1][23] = XX;
u[i + 1][24] = YY;
u[i + 1][25] = ZZ;
}
for (i = 0; i < m; i++) {
cin >> o;
for (j = 0; j < 26; j++) {
v[j] += u[o][j];
}
}
for (i = 0; i < 26; i++) {
cout << v[i] << " ";
}
cout << "\n";
b.clear();
v.clear();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int b[200005];
int main() {
int t;
cin >> t;
while (t--) {
int m, n;
cin >> n >> m;
string s;
cin >> s;
long long a[30] = {0};
memset(b, 0, sizeof(b));
for (int i = 0; i < m; i++) cin >> b[i];
sort(b, b + m);
int x = 0;
for (int i = 0; i < n; i++) {
while (i + 1 > b[x] && b[x] != 0) x++;
a[s[i] - 'a'] += m + 1 - x;
}
for (int i = 0; i < 26; i++) cout << a[i] << ' ';
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long a, b, k, val = 1;
cin >> a >> b;
long arr[26] = {0}, pos[a];
memset(pos, 0, sizeof(pos));
string s;
cin >> s;
for (long i = 0; i < b; i++) {
cin >> k;
pos[k - 1]++;
}
for (long j = (a - 1); j >= 0; j--) {
if (pos[j] > 0) {
val += pos[j];
}
arr[s[j] - 'a'] += val;
}
for (long i : arr) cout << i << " ";
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, b, x, q, t, ans, l, r, m, p, now, sum;
bool ok;
string s;
map<int, int> a, pos;
map<char, int> c;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> q;
while (q--) {
cin >> n >> m;
cin >> s;
for (int i = 1; i <= m; ++i) {
cin >> x;
a[x + 1]++;
}
sum = m + 1;
for (int i = 0; i < s.size(); ++i) {
sum -= a[i + 1];
c[s[i]] += sum;
}
for (char j = 'a'; j <= 'z'; ++j) {
cout << c[j] << ' ';
}
cout << '\n';
a.clear();
c.clear();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int n, m, t, i, j, k, c = 0;
long long int x, y, z;
string s;
int main() {
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
};
cin >> t;
while (t--) {
cin >> n >> m;
cin >> s;
long long int a[m + 1], b[26] = {0}, c[26] = {0};
for (j = 0; j < m; j++) cin >> a[j];
sort(a, a + m);
x = 0;
for (i = 0; i < n; i++) {
b[s[i] - 97]++;
c[s[i] - 97]++;
baal:
if (a[x] == i + 1 && x < m) {
for (k = 0; k < 26; k++) b[k] = b[k] + c[k];
x++;
if (a[x] == a[x - 1]) goto baal;
}
}
for (i = 0; i < 26; i++) cout << b[i] << ' ';
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long MXN = 300 + 10;
const long long MX5 = 2e5 + 10;
const long long MX6 = 1e6 + 10;
const long long LOG = 20;
const long long INF = 1e15;
const double eps = 1e-9;
const long long MOD = 1e9 + 7;
long long power(long long a, long long b, long long md) {
return (!b ? 1
: (b & 1 ? a * power(a * a % md, b / 2, md) % md
: power(a * a % md, b / 2, md) % md));
}
long long bmm(long long a, long long b) {
return (a % b == 0 ? b : bmm(b, a % b));
}
string base2(long long n) {
string a = "";
while (n >= 2) {
a += (char)(n % 2 + '0');
n /= 2;
}
a += (char)(n + '0');
reverse((a).begin(), (a).end());
return a;
}
long long q, n, m, x;
long long A[MX5], cnt[50], ps[MX5];
string s;
void solve() {
memset(cnt, 0, sizeof cnt);
memset(ps, 0, sizeof ps);
cin >> n >> m >> s;
for (int i = 0; i < m; i++) {
cin >> x;
ps[x - 1]++;
}
for (int i = n - 1; i >= 0; i--) ps[i] += ps[i + 1];
for (int i = 0; i <= n - 1; i++) {
cnt[s[i] - 'a'] += ps[i] + 1;
}
for (int i = 'a' - 'a'; i <= 'z' - 'a'; i++) {
cout << cnt[i] << ' ';
}
cout << '\n';
return;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> q;
while (q--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e16;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int n, m;
cin >> n >> m;
string s;
cin >> s;
long long int a[n];
memset(a, 0, sizeof(a));
for (int i = 0; i < m; i++) {
long long int x;
cin >> x;
a[x]++;
}
long long int res[26];
long long int now[26];
memset(res, 0, sizeof(res));
memset(now, 0, sizeof(now));
for (int i = 0; i < n; i++) {
res[s[i] - 'a']++;
for (int j = 0; j < 26; j++) {
res[j] += now[j] * a[i];
}
now[s[i] - 'a']++;
}
for (int i = 0; i < 26; i++) cout << res[i] << " ";
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline bool valid(int x, int n) { return 0 <= x && x < n; }
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
template <typename T>
inline T pop(queue<T>& q) {
T front = q.front();
q.pop();
return front;
}
template <typename T>
inline T gcd(T a, T b) {
for (; b; a %= b, swap(a, b))
;
return a;
}
template <typename T>
tuple<T, T, T> xgcd(T a, T b) {
if (b == 0) return {1, 0, a};
T x, y, g;
tie(x, y, g) = xgcd(b, a % b);
return {y, x - (a / b) * y, g};
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<int> p(m);
for (int i = 0; i < m; i++) cin >> p[i];
vector<vector<int> > press(n, vector<int>(26, 0));
for (int i = 0; i < n; i++) {
press[i][s[i] - 'a']++;
if (i)
for (int j = 0; j < 26; j++) {
press[i][j] += press[i - 1][j];
}
}
vector<int> rst(26, 0);
for (int i = 0; i < m; i++) {
for (int j = 0; j < 26; j++) {
rst[j] += press[p[i] - 1][j];
}
}
for (int j = 0; j < 26; j++) {
rst[j] += press[n - 1][j];
}
for (int r : rst) cout << r << " ";
cout << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
long long res[MAXN][30];
inline void Init() {
ios::sync_with_stdio(false);
cin.tie(0);
}
int main() {
Init();
int T;
cin >> T;
while (T--) {
int N, M;
long long c[30] = {0};
string s;
cin >> N >> M;
cin >> s;
for (int i = 0; i < 26; i++) res[0][i] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < 26; j++) res[i + 1][j] = res[i][j];
res[i + 1][s[i] - 'a']++;
}
while (M--) {
int x;
cin >> x;
for (int i = 0; i < 26; i++) c[i] += res[x][i];
}
for (int i = 0; i < 26; i++) c[i] += res[N][i];
for (int i = 0; i < 26; i++) cout << c[i] << " ";
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool isSorted(long long int n, long long int a[]) {
long long int i;
for (i = 0; i < n - 1; i++) {
if (a[i] > a[i + 1]) return false;
}
return true;
}
int32_t main() {
time_t start = clock();
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t, diff, n, m, i;
bool flg;
string str;
cin >> t;
while (t--) {
long long int ans[26];
for (i = 0; i < 26; i++) ans[i] = 0;
cin >> n >> m;
cin >> str;
long long int pos[m];
for (i = 0; i < m; i++) cin >> pos[i];
for (i = 0; i < n; i++) {
ans[str[i] - 97] += 1;
}
sort(pos, pos + m);
long long int j;
for (i = 0, j = 0; i < n; i++) {
while (j < m && pos[j] <= i) ++j;
ans[str[i] - 97] += (m - j);
}
for (i = 0; i < 26; i++) cout << ans[i] << " ";
cout << '\n';
}
cerr << fixed << setprecision(6)
<< "Time: " << 1.0 * (clock() - start) / CLOCKS_PER_SEC << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int f = 1, res = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
res = res * 10 + c - '0', c = getchar();
}
return f * res;
}
const int maxn = 2e5 + 5;
char c[maxn];
int a[27], p[maxn], n, m, t, s[maxn][27];
int main() {
t = read();
while (t--) {
n = read();
m = read();
scanf("%s", c + 1);
memset(a, 0, sizeof(a));
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 26; j++) s[i][j] = s[i - 1][j];
s[i][c[i] - 'a']++;
}
for (int i = 1; i <= m; i++) {
p[i] = read();
for (int j = 0; j < 26; j++) {
a[j] += s[p[i]][j];
}
}
for (int i = 0; i < 26; i++) a[i] += s[n][i];
for (int i = 0; i < 26; i++) {
printf("%d ", a[i]);
a[i] = 0;
}
printf("\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, M;
cin >> n >> M;
vector<char> s(n);
int m = M;
vector<int> p(m), b(n), yes(n, 0), cnt(26, 0);
for (int i = 0; i < n; i++) {
cin >> s[i];
cnt[s[i] - 'a']++;
}
for (int i = 0; i < m; i++) {
cin >> p[i];
p[i]--;
}
sort(p.begin(), p.end());
int top = 0;
for (int i = 0; i < n; i++) {
if (top >= M) break;
if (p[top] != i)
cnt[s[i] - 'a'] += m;
else {
int t = top;
while (top < M - 1 && p[top] == p[top + 1]) top++;
int c = ++top - t;
cnt[s[i] - 'a'] += m;
m -= c;
}
}
for (int i = 0; i < 26; i++) cout << cnt[i] << " ";
cout << endl;
return;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
long long gcdfun(long long x, long long y) {
if (y == 0)
return x;
else
return gcdfun(y, x % y);
}
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
char a[n];
vector<int> b(m), c(26), d(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
c[a[i] - 97]++;
}
for (int i = 0; i < m; i++) {
cin >> b[i];
d[b[i] - 1]++;
}
for (int i = n - 2; i >= 0; i--) d[i] += d[i + 1];
for (int i = 0; i < n; i++) c[a[i] - 97] += d[i];
for (int i = 0; i < 26; i++) cout << c[i] << " ";
cout << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
char s[200000 + 1];
int c[200000 + 1];
int a[26];
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
cin >> s;
memset(c, 0, sizeof(c));
memset(a, 0, sizeof(a));
c[0] = m + 1;
for (int i = 0; i < m; ++i) {
int p;
cin >> p;
c[p] -= 1;
}
int count = 0;
for (int i = 0; i < n; ++i) {
count += c[i];
a[s[i] - 'a'] += count;
}
for (int i = 0; i < 26; ++i) {
cout << a[i] << (i == 25 ? '\n' : ' ');
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, m;
cin >> n >> m;
string str;
cin >> str;
long long dp[26][n + 1];
memset(dp, 0, sizeof(dp));
;
for (long long i = 0; i < str.size(); i++) {
dp[str[i] - 'a'][i]++;
}
vector<long long> p;
for (long long i = 0; i < m; i++) {
long long k;
cin >> k;
k--;
p.push_back(k);
}
for (char ch = 'a'; ch <= 'z'; ch++) {
for (long long i = 1; i < n; i++) {
dp[ch - 'a'][i] += dp[ch - 'a'][i - 1];
}
}
vector<long long> cnt(26, 0);
for (auto i : p) {
for (char ch = 'a'; ch <= 'z'; ch++) {
if (dp[ch - 'a'][i]) {
cnt[ch - 'a'] += dp[ch - 'a'][i];
}
}
}
for (auto i : str) {
cnt[i - 'a']++;
}
for (char ch = 'a'; ch <= 'z'; ch++) {
cout << cnt[ch - 'a'] << ' ';
}
cout << endl;
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10, OO = 0x3f3f3f3f;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int tc, n, m;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
cin >> tc;
while (tc--) {
cin >> n >> m;
cin >> s;
vector<long long> freq(n + 1, 0);
vector<int> indx(m);
for (int i = 0; i < int(m); i++) {
cin >> indx[i];
freq[0]++;
freq[indx[i]]--;
}
freq[0]++;
for (int i = int(1); i <= int(n - 1); i++) freq[i] += freq[i - 1];
vector<long long> karakter(26, 0);
for (int i = 0; i < int(n); i++) karakter[s[i] - 'a'] += freq[i];
for (int i = 0; i < int(26); i++) cout << karakter[i] << " ";
cout << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int p[N];
int cnt[26];
char str[N];
int main() {
int t, n, m;
scanf("%d", &t);
while (t--) {
memset(cnt, 0, sizeof(cnt));
scanf("%d%d", &n, &m);
scanf("%s", str + 1);
for (int i = 1; i <= m; i++) scanf("%d", p + i);
sort(p + 1, p + 1 + m);
int i = 1, j = 1;
while (i <= n && j <= m) {
if (i <= p[j])
cnt[str[i++] - 'a'] += m - j + 1;
else
j++;
}
for (i = 1; i <= n; i++) cnt[str[i] - 'a']++;
for (i = 0; i < 26; i++) printf("%d ", cnt[i]);
printf("\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int ans[N];
int res[N];
int fun[N];
int main() {
int t;
cin >> t;
while (t--) {
memset(res, 0, sizeof res);
memset(fun, 0, sizeof fun);
int n, m;
string st;
scanf("%d%d", &n, &m);
cin >> st;
for (int i = 1; i <= m; i++) {
scanf("%d", &ans[i]);
}
sort(ans + 1, ans + 1 + m);
for (int i = 1; i <= m; i++) {
for (int j = 0; j < 26; j++) {
if (res[j] != 0) {
res[j] += fun[j];
}
}
for (int j = ans[i - 1]; j <= ans[i] - 1; j++) {
fun[st[j] - 'a']++;
res[st[j] - 'a']++;
}
}
for (int i = 0; i < n; i++) {
res[st[i] - 'a']++;
}
for (int i = 0; i < 26; i++) {
printf("%d ", res[i]);
}
printf("\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const int INF = 1e9 + 7;
const long long LINF = 1e18;
const double PI = 3.1415926535897932384626433832795;
long double START_TIME, TIME;
const int MAX_SIZE = 5e5;
map<char, long long> M;
void fast_in_out() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
START_TIME = clock();
}
void make() {
char c = 'a';
while (c != 'z') {
M[c] = 0;
c = c + 1;
}
M[c] = 0;
}
void solve() {
int n, m;
string s;
cin >> n >> m >> s;
make();
vector<int> p(m), c(n, 0);
for (auto& i : p) {
cin >> i;
++c[i - 1];
}
int x = 1;
for (int i = n - 1; i > -1; --i) {
c[i] += x;
x = max(x, c[i]);
M[s[i]] += c[i];
}
for (auto& i : M) {
cout << i.second << ' ';
}
cout << '\n';
}
int main() {
fast_in_out();
TIME = (clock() - START_TIME) / CLOCKS_PER_SEC;
int t;
cin >> t;
while (t--) {
solve();
}
cerr << '\n' << TIME << " sec." << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
long long freq[26] = {};
string s;
cin >> s;
std::vector<int> p(m);
for (int i = 0; i < m; ++i) {
cin >> p[i];
}
sort(p.begin(), p.end());
int j = 0;
for (int i = 0; i < s.size(); ++i) {
freq[s[i] - 'a'] += 1;
}
for (int i = 0; i < n; ++i) {
while (i >= p[j] && j < m) {
j++;
}
freq[s[i] - 'a'] += (m - j);
}
for (int i = 0; i < 26; ++i) {
printf("%d ", freq[i]);
}
printf("\n");
}
return 0;
}
|
// 巨菜的ACMer-Happier233
#include <bits/stdc++.h>
using namespace std;
//-----
typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fi first
#define se second
#define pw(x) (1ll << (x))
#define bt(x, k) (((x) >> k) & 1)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i, l, r) for(int i=(l);i<(r);++i)
#define per(i, l, r) for(int i=(r)-1;i>=(l);--i)
#define mst(t, v, n) memset(t, v, sizeof(decltype(*(t))) * (n))
#define sf(x) scanf("%d", &(x))
#if (not defined(ACM_LOCAL) || defined(ACM_TEST))
#define endl '\n'
#endif
constexpr int N = int(2e5 + 10);
constexpr int MOD = 998244353;
const int INF = 0x3f3f3f3f;
int c[N];
ll ans[26];
void solve() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
fill_n(c, n + 1, 0);
rep(i, 0, m) {
int x;
cin >> x;
c[x - 1]++;
}
per(i, 0, n) {
c[i] += c[i + 1];
}
fill_n(ans, 26, 0);
rep(i, 0, n) {
ans[s[i] - 'a'] += c[i] + 1;
}
rep(i, 0, 26) {
printf("%lld%c", ans[i], " \n"[i == 25]);
}
}
int main() {
#ifdef ACM_LOCAL
freopen("./data/std.in", "r", stdin);
// freopen("./data/std2.out", "w", stdout);
#endif
#if (not defined(ACM_LOCAL) || defined(ACM_TEST))
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#endif
#ifdef ACM_LOCAL
clock_t start = clock();
#endif
int t = 1;
cin >> t;
while (t--)
solve();
#ifdef ACM_LOCAL
clock_t end = clock();
cerr << "Run Time: " << double(end - start) / CLOCKS_PER_SEC << "s" << endl;
#endif
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
const int nax = 5005;
int main() {
int t;
cin >> t;
while (t--) {
int n, m, x;
string s;
cin >> n >> m;
int p[m];
cin >> s;
for (int i = 0; i < m; i++) {
cin >> p[i];
}
vector<int> v[26];
int ans[26] = {0};
for (int i = 0; i < n; i++) {
v[s[i] - 'a'].push_back(i + 1);
}
for (int i = 0; i < 26; i++) ans[i] += v[i].size();
for (int i = 0; i < 26; i++) {
for (int j = 0; j < m; j++) {
int x = p[j];
int ub = -1;
ub = (int)(upper_bound(v[i].begin(), v[i].end(), x) - v[i].begin());
if (ub != -1) ans[i] += ub;
}
}
for (int i = 0; i < 26; i++) cout << ans[i] << " ";
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long INF = 2000000000000000000LL;
const int inf = 0x3f3f3f3f;
const long double EPS = 1e-9;
const int maxn = 2e5 + 5;
long long frecnt[27][maxn], sum[27];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
int test;
cin >> test;
while (test--) {
int n, m;
string str;
cin >> n >> m;
cin >> str;
std::vector<int> v(m);
for (int i = 0; i < m; i++) {
cin >> v[i];
}
str = "#" + str;
for (int i = 0; i < 26; i++) {
frecnt[i][0] = 0;
sum[i] = 0;
for (int j = 1; j < str.size(); j++) {
frecnt[i][j] = frecnt[i][j - 1];
if (str[j] == char(i + 'a')) {
frecnt[i][j]++;
}
}
}
for (int j = 1; j < str.size(); j++) {
sum[(str[j] - 'a')]++;
}
for (int i = 0; i < v.size(); i++) {
for (int j = 0; j < 26; j++) {
sum[j] += frecnt[j][v[i]];
}
}
for (int i = 0; i < 26; i++) {
cout << sum[i] << " ";
}
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int letter[26] = {0};
string str;
int m, n;
cin >> n >> m;
cin >> str;
vector<int> p(m + 1);
for (int i = 0; i < m; i++) {
cin >> p[i];
}
vector<int> cnt(n);
for (int i = 0; i < m; i++) {
cnt[p[i] - 1]++;
}
cnt[n - 1]++;
for (int i = n - 1; i > 0; i--) {
cnt[i - 1] += cnt[i];
}
for (int i = 0; i < n; i++) {
letter[str[i] - 'a'] += cnt[i];
}
for (int i = 0; i < 26; i++) {
cout << letter[i] << " ";
}
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int t, n, m, har[27];
string s;
int sum[200005][27];
int main() {
cin >> t;
while (t--) {
cin >> n >> m;
cin >> s;
for (int i = 0; i <= 25; i++) har[i] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 26; j++) sum[i][j] = 0;
}
for (int i = 0; i < n; i++) {
if (i != 0) {
for (int j = 0; j <= 25; j++) {
sum[i][j] = sum[i - 1][j];
}
}
sum[i][s[i] - 'a']++;
}
int l = 0;
for (int i = 0; i < m; i++) {
cin >> l;
for (int j = 0; j < 26; j++) {
har[j] += sum[l - 1][j];
}
}
for (int j = 0; j < 26; j++) {
har[j] += sum[n - 1][j];
}
for (int i = 0; i < 26; i++) {
cout << har[i] << ' ';
}
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
string s;
cin >> s;
int p[m];
int c[n][26];
int ans[26];
for (int i = 0; i < 26; i++) {
ans[i] = 0;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < 26; j++) {
c[i][j] = 0;
}
}
for (int i = 0; i < m; i++) {
cin >> p[i];
}
sort(p, p + m);
c[0][int(s[0]) - 97] = 1;
for (int i = 1; i < n; i++) {
for (int j = 0; j < 26; j++) {
if (int(s[i]) == (97 + j)) {
c[i][j] = c[i - 1][j] + 1;
} else
c[i][j] = c[i - 1][j];
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < 26; j++) {
ans[j] = ans[j] + c[p[i] - 1][j];
}
}
for (int i = 0; i < 26; i++) {
ans[i] = ans[i] + c[n - 1][i];
}
for (int j = 0; j < 26; j++) {
if (j != 25)
cout << ans[j] << " ";
else
cout << ans[j] << endl;
;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char s[200005];
long long c[30][200005];
long long ans[30];
int main() {
int t;
cin >> t;
while (t--) {
for (int i = 0; i < 30; i++) ans[i] = 0;
int n, m;
scanf("%d%d", &n, &m);
scanf("%s", s + 1);
for (register int i = 1; i <= n; ++i) {
char C = s[i];
for (register int j = 0; j < 26; ++j) {
if (char('a' + j) == C)
c[j][i] = c[j][i - 1] + 1;
else
c[j][i] = c[j][i - 1];
}
}
for (register int i = 1; i <= m; ++i) {
int x;
scanf("%d", &x);
for (register int k = 0; k < 26; ++k) ans[k] += c[k][x];
}
for (register int k = 0; k < 26; ++k) ans[k] += c[k][n];
for (register int i = 0; i < 25; ++i) printf("%lld ", ans[i]);
printf("%lld\n", ans[25]);
}
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename _t>
inline void read(_t &x) {
x = 0;
_t fu = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') fu = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch & 15);
ch = getchar();
}
x *= fu;
}
long long gcd(long long x, long long y) { return !x ? y : gcd(y % x, x); }
void exgcd(long long a, long long b, long long &x, long long &y) {
if (!b) {
x = 1;
y = 0;
return;
}
exgcd(b, a % b, y, x);
y -= a / b * x;
}
struct Mart {
int a, b, c, d;
Mart operator*(Mart &m) {
Mart temp;
temp.a = a * m.a + b * m.c;
temp.b = a * m.b + b * m.d;
temp.c = c * m.a + d * m.c;
temp.d = c * m.b + d * m.d;
return temp;
}
Mart() { a = b = c = d = 0; }
Mart(int x[4]) {
a = x[0];
b = x[1];
c = x[2];
d = x[3];
}
Mart(int u, int v, int w, int x) {
a = u;
b = v;
c = w;
d = x;
}
int det() { return a * d - b * c; }
};
const int maxn = 2e5 + 10;
int num[maxn][26];
char s[maxn];
int ans[26];
int main() {
int t;
scanf("%d", &t);
while (t--) {
memset(ans, 0, sizeof ans);
int n, m;
scanf("%d %d", &n, &m);
scanf("%s", s + 1);
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 26; j++) {
if (j + 'a' == s[i])
num[i][j] = num[i - 1][j] + 1;
else
num[i][j] = num[i - 1][j];
}
}
for (int i = 0, x; i < m; i++) {
scanf("%d", &x);
for (int j = 0; j < 26; j++) ans[j] += num[x][j];
}
for (int i = 0; i < 26; i++) ans[i] += num[n][i];
for (int i = 0; i < 26; i++) printf("%d ", ans[i]);
printf("\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long dp[200005][26];
int main() {
int t;
cin >> t;
while (t-- > 0) {
int n, m;
cin >> n >> m;
string s;
cin >> s;
for (int i = 0; i < n + 1; i++) {
for (int j = 0; j < 26; j++) {
dp[i][j] = 0;
}
}
for (int i = 0; i < n; i++) {
int x = s.at(i) - 'a';
for (int j = 0; j < 26; j++) {
if (j == x) {
dp[i + 1][j] = dp[i][j] + 1;
} else {
dp[i + 1][j] = dp[i][j];
}
}
}
long long answer[26];
for (int j = 0; j < 26; j++) {
answer[j] = 0;
}
for (int i = 0; i < m; i++) {
int temp;
cin >> temp;
for (int i = 0; i < 26; i++) {
answer[i] += dp[temp][i];
}
}
for (int i = 0; i < 26; i++) {
answer[i] += dp[n][i];
}
for (int j = 0; j < 26; j++) {
cout << answer[j] << " ";
}
cout << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
using lld = long long int;
using pii = pair<int, int>;
using pil = pair<int, lld>;
using pli = pair<lld, int>;
int n, m;
char a[200009];
int s[200009][26];
lld res[26];
int main() {
int i, j, k, l;
int t = 1, tv = 0;
scanf("%d", &t);
while (t--) {
scanf("%d %d", &n, &m);
scanf("%s", a);
for (i = 0; i < n; i++) {
for (j = 0; j < 26; j++) {
s[i + 1][j] = s[i][j];
}
s[i + 1][a[i] - 'a']++;
}
for (i = 0; i < 26; i++) {
res[i] = s[n][i];
}
while (m--) {
scanf("%d", &i);
for (j = 0; j < 26; j++) {
res[j] += s[i][j];
}
}
for (i = 0; i < 26; i++) {
printf("%lld ", res[i]);
}
printf("\n");
}
}
|
#include <bits/stdc++.h>
long long N = 1e18 + 2;
using namespace std;
char ar[200005];
int main() {
int tc;
scanf("%d", &tc);
while (tc--) {
int n, m;
scanf("%d %d %s", &n, &m, &ar);
vector<int> freq(n + 2, 0), ans(26, 0);
for (int i = 0; i < m; i++) {
int p;
scanf("%d", &p);
freq[1]++;
freq[p + 1]--;
}
freq[1]++;
for (int i = 1; i <= n; i++) {
freq[i] += freq[i - 1];
ans[ar[i - 1] - 'a'] += freq[i];
}
for (int i = 0; i < 26; i++) printf("%d%c", ans[i], " \n"[i + 1 == 26]);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int inf = (long long)1e18;
const int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
string alpha = "abcdefghijklmnopqrstuvwxyz";
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tc;
cin >> tc;
while (tc--) {
int n, m;
cin >> n >> m;
string s;
cin >> s;
map<char, int> mp;
for (int i = 0; i < s.size(); i++) mp[s[i]]++;
int cum[n + 1];
memset(cum, 0, sizeof cum);
for (int i = 0; i < m; i++) {
int x;
cin >> x;
cum[x + 1]--;
cum[1]++;
}
for (int i = 2; i <= n; i++) cum[i] = cum[i - 1] + cum[i];
for (int i = 1; i <= n; i++) mp[s[i - 1]] += cum[i];
for (int i = 0; i < alpha.size(); i++) cout << mp[alpha[i]] << " ";
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
const int mx = 2e5 + 10, alphaNum = 30;
using namespace std;
long long int alpha[alphaNum], arr[mx], p[mx], counter[mx];
int main() {
string s;
int t;
int n, m;
scanf("%d", &t);
while (t--) {
cin >> n >> m >> s;
for (int i = 0; i < m; i++) scanf("%d", &p[i]);
memset(alpha, 0, sizeof(alpha));
memset(counter, 0, sizeof(counter));
for (int i = 0; i < m; ++i) counter[p[i] - 1]++;
;
for (int i = n - 1; i >= 0; --i) counter[i] += counter[i + 1];
for (int i = 0; i < n; i++) counter[i]++;
for (int i = 0; i < n; ++i) {
alpha[s[i] - 'a'] += counter[i];
}
for (int i = 0; i < 26; ++i) cout << alpha[i] << " ";
cout << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
string s;
cin >> n >> m >> s;
vector<int> pref(n);
for (int i = 0; i < m; ++i) {
int p;
cin >> p;
++pref[p - 1];
}
for (int i = n - 1; i > 0; --i) {
pref[i - 1] += pref[i];
}
vector<int> ans(26);
for (int i = 0; i < n; ++i) {
ans[s[i] - 'a'] += pref[i];
++ans[s[i] - 'a'];
}
for (int i = 0; i < 26; ++i) {
cout << ans[i] << " ";
}
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, m;
cin >> n >> m;
string s;
cin >> s;
long long store[n][26];
for (int j = 0; j < 26; j++) store[0][j] = 0;
store[0][s[0] - 'a']++;
for (int i = 1; i < n; i++) {
for (int j = 0; j < 26; j++) store[i][j] = store[i - 1][j];
store[i][s[i] - 'a']++;
}
long long p[m];
long long ans[26] = {0};
for (int i = 0; i < m; i++) {
cin >> p[i];
for (int j = 0; j < 26; j++) ans[j] += store[p[i] - 1][j];
}
for (int j = 0; j < 26; j++) ans[j] += store[n - 1][j];
for (int i = 0; i < 26; i++) cout << ans[i] << " ";
cout << endl;
}
int main() {
long long t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int T, n, m, p[N], a[N][26], ans[26];
char s[N];
signed main() {
cin >> T;
while (T--) {
cin >> n >> m >> s + 1;
for (int i = 1; i <= m; i++) cin >> p[i];
++m;
p[m] = n;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 26; j++) a[i][j] = a[i - 1][j] + (s[i] - 'a' == j);
}
for (int i = 1; i <= m; i++) {
for (int j = 0; j < 26; j++) ans[j] += a[p[i]][j];
}
for (int i = 0; i < 26; i++) cout << ans[i] << " ";
cout << endl;
memset(ans, 0, sizeof ans);
for (int i = 1; i <= n; i++) {
p[i] = ans[i] = s[i] = 0;
memset(a[i], 0, sizeof a[i]);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long n, m, i, j, x;
string s, tmp;
cin >> n >> m;
s = " ";
cin >> tmp;
s += tmp;
long long dp[n + 1][26];
vector<long long> ans(26, 0);
for (i = 0; i <= n; i++) {
for (j = 0; j < 26; j++) {
dp[i][j] = 0;
}
}
for (i = 1; i <= n; i++) {
ans[s[i] - 'a']++;
for (j = 0; j < 26; j++) {
dp[i][j] = dp[i - 1][j];
}
dp[i][s[i] - 'a']++;
}
for (i = 0; i < m; i++) {
cin >> x;
for (j = 0; j < 26; j++) {
ans[j] += dp[x][j];
}
}
for (i = 0; i < 26; i++) {
cout << ans[i] << " ";
}
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t > 0) {
int n;
int m;
cin >> n >> m;
string s;
cin >> s;
int h[26] = {0};
vector<int> v1(26, 0);
vector<vector<int>> v(s.length(), v1);
for (int i = 0; i < n; i++) {
h[(int)s[i] - 97]++;
for (int j = 0; j < 26; j++) {
v[i][j] += h[j];
}
}
for (int i = 0; i < m; i++) {
int k;
cin >> k;
for (int i = 0; i < 26; i++) h[i] += v[k - 1][i];
}
for (int x : h) {
cout << x << " ";
}
cout << endl;
t--;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
string s;
cin >> s;
int p;
int count[n];
for (int i = 0; i < n; i++) {
count[i] = 0;
}
for (int i = 0; i < m; i++) {
cin >> p;
p--;
count[p]++;
}
for (int i = n - 2; i >= 0; i--) {
count[i] += count[i + 1];
}
for (int i = 0; i < n; i++) {
count[i]++;
}
int ans[26];
for (int i = 0; i < 26; i++) {
ans[i] = 0;
}
for (int i = 0; i < n; i++) {
ans[s[i] - 'a'] += count[i];
}
for (int i = 0; i < 26; i++) {
cout << ans[i] << " ";
}
cout << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<long long int, long long int> a,
pair<long long int, long long int> b) {
return a.first < b.first;
}
bool check(int a) {
int sum = 0;
while (a > 0) {
sum += (a % 10);
a /= 10;
}
if (sum == 10) return true;
return false;
}
bool prime[10005];
void seivertexe() {
memset(prime, 1, sizeof(prime));
prime[0] = 0;
prime[1] = 0;
for (long long int i = 2; i <= 10000; i++) {
if (prime[i] == 1) {
for (long long int j = i * i; j <= 10000; j += i) prime[j] = 0;
}
}
}
template <typename T>
std::string NumberToString(T Number) {
std::ostringstream ss;
ss << Number;
return ss.str();
}
bool isPrime(long long int n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (long long int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
long long int power(long long int x, long long int y) {
if (y == 0)
return 1;
else if (y % 2 == 0)
return (power(x, y / 2) % 1000000007 * power(x, y / 2) % 1000000007) %
1000000007;
else
return (x % 1000000007 *
(power(x, y / 2) % 1000000007 * power(x, y / 2) % 1000000007) %
1000000007) %
1000000007;
}
long long int factorial1(long long int n) {
return (n == 1 || n == 0)
? 1
: (n % 1000000007 * factorial1(n - 1) % 1000000007) % 1000000007;
}
long long int fact(long long int n);
long long int nCr(long long int n, long long int r) {
return fact(n) % 1000000007 /
((fact(r) % 1000000007 * fact(n - r) % 1000000007)) % 1000000007;
}
long long int fact(long long int n) {
long long int res = 1;
for (int i = 2; i <= n; i++) res = (res * i) % 1000000007;
return res % 1000000007;
}
void solve() {}
struct pr {
long long int a;
long long int t;
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long int t;
cin >> t;
while (t--) {
long long int n, m;
cin >> n >> m;
string second;
cin >> second;
long long int p[m + 1];
long long int last[26] = {0};
for (long long int i = 0; i < m; i++) {
cin >> p[i];
}
long long int count[26] = {0};
vector<vector<long long int> > v(n + 100);
for (int i = 0; i < n; i++) {
count[second[i] - 'a']++;
last[second[i] - 'a']++;
for (long long int j = 0; j < 26; j++) {
v[i].push_back(count[j]);
}
}
long long int k = 0;
long long int acc[26] = {0};
for (long long int i = 0; i < m; i++) {
k = 0;
p[i]--;
for (auto it = v[p[i]].begin(); it != v[p[i]].end(); it++) {
acc[k++] += (*it);
}
}
for (int i = 0; i < 26; i++) {
acc[i] += last[i];
}
for (int i = 0; i < 26; i++) {
cout << acc[i] << " ";
}
cout << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
class solution {
public:
void solve() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<int> v(m);
for (int i = 0; i < m; i++) {
cin >> v[i];
}
vector<int> ch(26, 0);
vector<int> dp(n, 0);
dp[0] = 1;
for (int i = 0; i < m; i++) {
dp[0]++;
dp[v[i]]--;
}
for (int i = 0; i < n; i++) {
int charecter = s[i] - 'a';
if (i == 0) {
ch[charecter] = dp[0];
} else {
dp[i] += dp[i - 1];
ch[charecter] += dp[i];
}
}
for (auto it : ch) {
cout << it << " ";
}
cout << "\n";
}
}
};
int main() {
ios::sync_with_stdio(0), cout.tie(0), cin.tie(0);
long long i = 0;
solution s;
s.solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m, i, j;
cin >> n >> m;
vector<vector<int>> v(n, vector<int>(27, 0));
vector<int> total(27, 0);
string s;
int p[m];
cin >> s;
for (i = 0; i < m; i++) cin >> p[i];
v[0][s[0] - 'a']++;
for (i = 1; i < n; i++) {
v[i][s[i] - 'a']++;
for (j = 0; j < 26; j++) v[i][j] = v[i][j] + v[i - 1][j];
}
for (i = 0; i < m; i++) {
for (j = 0; j < 26; j++) {
total[j] = total[j] + v[p[i] - 1][j];
}
}
for (j = 0; j < 26; j++) {
total[j] = total[j] + v[n - 1][j];
}
for (i = 0; i < 26; i++) cout << total[i] << " ";
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, i, j = 0, u, n, m;
cin >> t;
while (t--) {
string s;
cin >> n >> m >> s;
vector<int> pref(n);
for (i = 0; i < m; i++) {
int p;
cin >> p;
pref[p - 1]++;
}
for (i = n - 1; i > 0; i--) {
pref[i - 1] += pref[i];
}
vector<int> ans(26);
for (i = 0; i < n; i++) {
ans[s[i] - 'a'] += pref[i] + 1;
}
for (i = 0; i < 26; i++) {
cout << ans[i] << " ";
}
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void fakemain() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
string s;
cin >> s;
int a[n + 1];
memset(a, 0, sizeof(a));
for (int i = 0; i < m; i++) {
int x;
cin >> x;
a[x]++;
}
a[n]++;
int f[30];
memset(f, 0, sizeof(f));
f[s[n - 1] - 'a']++;
for (int i = n - 1; i > 0; i--) {
a[i] += a[i + 1];
f[s[i - 1] - 'a'] += a[i];
}
for (int i = 0; i < 26; i++) cout << f[i] << " ";
cout << "\n";
}
}
int main() { fakemain(); }
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, m;
cin >> t;
while (t--) {
cin >> n >> m;
string str;
map<int, int> mark;
vector<int> ans(26, 0);
cin >> str;
for (int i = 0, x; i < m; i++) {
cin >> x;
mark[x - 1]++;
}
int cnt = 1;
for (int i = n - 1; i >= 0; i--) {
if (mark[i]) {
cnt += mark[i];
}
ans[str[i] - 'a'] += cnt;
}
for (auto it : ans) cout << it << ' ';
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long MAX_N = 1e5 + 11;
long long ans[26 + 1];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
long long tc;
cin >> tc;
while (tc--) {
long long n, m;
cin >> n >> m;
string s;
cin >> s;
vector<vector<long long> > cache(n + 1, vector<long long>(26));
for (long long i = 0; i < n; i++) {
cache[i + 1] = cache[i];
cache[i + 1][s[i] - 'a']++;
}
memset(ans, 0, sizeof ans);
for (long long i = 0; i < m; i++) {
long long x;
cin >> x;
for (long long j = 0; j < 26; j++) ans[j] += cache[x][j];
}
for (long long i = 0; i < 26; i++) ans[i] += cache[n][i];
for (long long i = 0; i < 26; i++) cout << ans[i] << " ";
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
ostream& operator<<(ostream& o, const pair<T, U>& x) {
o << "(" << x.first << ", " << x.second << ")";
return o;
}
template <typename T>
ostream& operator<<(ostream& o, const vector<T>& x) {
o << "[";
int b = 0;
for (auto& a : x) o << (b++ ? ", " : "") << a;
o << "]";
return o;
}
template <typename T>
ostream& operator<<(ostream& o, const set<T>& x) {
o << "{";
int b = 0;
for (auto& a : x) o << (b++ ? ", " : "") << a;
o << "}";
return o;
}
template <typename T>
ostream& operator<<(ostream& o, const multiset<T>& x) {
o << "{";
int b = 0;
for (auto& a : x) o << (b++ ? ", " : "") << a;
o << "}";
return o;
}
template <typename T>
ostream& operator<<(ostream& o, const unordered_set<T>& x) {
o << "{";
int b = 0;
for (auto& a : x) o << (b++ ? ", " : "") << a;
o << "}";
return o;
}
template <typename T>
ostream& operator<<(ostream& o, const unordered_multiset<T>& x) {
o << "{";
int b = 0;
for (auto& a : x) o << (b++ ? ", " : "") << a;
o << "}";
return o;
}
template <typename T, typename U>
ostream& operator<<(ostream& o, const map<T, U>& x) {
o << "{";
int b = 0;
for (auto& a : x) o << (b++ ? ", " : "") << a;
o << "}";
return o;
}
template <typename T, typename U>
ostream& operator<<(ostream& o, const multimap<T, U>& x) {
o << "{";
int b = 0;
for (auto& a : x) o << (b++ ? ", " : "") << a;
o << "}";
return o;
}
template <typename T, typename U>
ostream& operator<<(ostream& o, const unordered_map<T, U>& x) {
o << "{";
int b = 0;
for (auto& a : x) o << (b++ ? ", " : "") << a;
o << "}";
return o;
}
template <typename T, typename U>
ostream& operator<<(ostream& o, const unordered_multimap<T, U>& x) {
o << "{";
int b = 0;
for (auto& a : x) o << (b++ ? ", " : "") << a;
o << "}";
return o;
}
double time() { return double(clock()) / CLOCKS_PER_SEC; }
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n, m;
string s;
cin >> n >> m >> s;
vector<int> X(m);
for (auto& x : X) cin >> x, x--;
sort(begin(X), end(X));
vector<int> ans(256);
for (int i = 0, j = 1; i < n; i++) {
while (j <= m and X[m - j] == n - i - 1) j++;
ans[s[n - i - 1]] += j;
}
for (int i = 'a'; i <= 'z'; i++) cout << ans[i] << " \n"[i == 'z'];
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t = 0;
cin >> t;
for (int z = 0; z < t; z++) {
long int a[26];
for (long int i = 0; i < 26; i++) a[i] = 0;
long int n = 0, m = 0;
cin >> n >> m;
string s;
cin >> s;
long int ar[m];
for (long int i = 0; i < m; i++) cin >> ar[i];
sort(ar, ar + m);
long int initial = 0;
for (long int i = 0; i < m; i++) {
for (int j = 0 + initial; j < ar[i]; j++) {
a[s[j] - 97] += m - i + 1;
}
initial = ar[i];
}
for (long int i = initial; i < n; i++) {
a[s[i] - 97]++;
}
for (long int i = 0; i < 26; i++) cout << a[i] << ' ';
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '"' << x << '"'; }
void __print(const string &x) { cerr << '"' << x << '"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T>
void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
__print(t);
if (sizeof...(v)) cerr << ", ";
_print(v...);
}
vector<int> input(int n) {
vector<int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
return a;
}
vector<long long int> input_lli(int n) {
vector<long long int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
return a;
}
void print(vector<int> arr) {
for (int i = 0; i < arr.size(); ++i) cout << arr[i] << ' ';
cout << endl;
}
long long int gcd(long long int a, long long int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<int> arr(26, 0);
;
int last = m;
int j = 0;
vector<int> q(m);
for (int i = 0; i < m; ++i) {
cin >> q[i];
}
sort(q.begin(), q.end());
;
for (int i = 0; i < n; ++i) {
if (i < q[j]) {
arr[s[i] - 'a'] += last;
} else {
while (i >= q[j] && j < m) {
last -= 1;
++j;
}
arr[s[i] - 'a'] += last;
}
arr[s[i] - 'a'] += 1;
;
}
for (int i = 0; i < 26; ++i) {
cout << arr[i] << ' ';
}
cout << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t, n, m, a[200001], i, j, t1, ans[26];
string str;
cin >> t;
for (i = 0; i < t; i++) {
cin >> n >> m;
memset(a, 0, sizeof(int) * n);
memset(ans, 0, sizeof(int) * 26);
cin >> str;
for (j = 0; j < m; j++) {
cin >> t1;
a[t1 - 1]++;
}
for (j = n - 1; j > 0; j--) a[j - 1] += a[j];
for (j = 0; j < n; j++) ans[str[j] - 'a'] += a[j] + 1;
for (j = 0; j < 26; j++) cout << ans[j] << " ";
cout << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
map<int, int> mp, mp2, mp3;
int n, m;
cin >> n >> m;
string s;
cin >> s;
int p[m];
for (int i = 0; i < m; ++i) {
cin >> p[i];
}
sort(p, p + m);
int ct = 0;
for (int i = 0; i < m; ++i) {
string str = s.substr(ct, p[i] - ct);
for (int j = 0; j < 26; ++j) {
mp[j] += count(str.begin(), str.end(), 'a' + j) * (m - i);
}
ct = p[i];
}
for (int i = 0; i < n; ++i) {
int x = s[i] - 'a';
mp[x]++;
}
for (int i = 0; i < 26; ++i) {
cout << mp[i] << " ";
}
cout << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long Digits(long long a) { return (floor(log10(a)) + 1); }
long long BMod(long long B, long long P, long long M) {
long long R = 1;
B = B % M;
while (P) {
if (P & 1) R = (R * B) % M;
P >>= 1;
B = (B * B) % M;
}
return R;
}
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int len, tryy, i, x;
cin >> len >> tryy;
int ara[len + 7];
memset(ara, 0, sizeof(ara));
string s;
cin >> s;
for (i = 0; i < tryy; i++) {
cin >> x;
ara[x - 1]++;
}
for (i = len - 1; i > 0; i--) {
ara[i - 1] += ara[i];
}
map<char, int> m;
for (i = 0; i < s.size(); i++) {
m[s[i]] += ara[i] + 1;
}
for (char c = 'a'; c <= 'z'; c++) {
cout << m[c] << " ";
}
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long int dp[200001][27];
int main() {
long long int t;
cin >> t;
for (int i = 1; i <= t; i++) {
long long int n, m;
cin >> n >> m;
string s;
cin >> s;
long long int a[m + 2];
for (int j = 1; j <= m; j++) {
cin >> a[j];
}
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= 26; k++) {
dp[j][k] = dp[j - 1][k];
}
long long int q = (s[j - 1] - 'a') + 1;
dp[j][q]++;
}
a[m + 1] = n;
for (int j = 1; j <= 26; j++) {
long long int ans = 0;
for (int k = 1; k <= m + 1; k++) {
ans += dp[a[k]][j];
}
cout << ans << " ";
}
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
int arr[m + 1];
string s;
cin >> s;
for (int i = 0; i < m; i++) {
cin >> arr[i];
arr[i]--;
}
arr[m] = n - 1;
sort(arr, arr + m);
map<char, long long> m1;
long long ans[27];
for (int i = 0; i < 27; i++) ans[i] = 0;
int j = 0;
int a = arr[j];
for (int i = 0; i < n; i++) {
m1[s[i]]++;
long long cnt = 0;
while (j <= m && arr[j] == i) {
cnt++;
j++;
}
if (cnt) {
for (char j = 'a'; j <= 'z'; j++) {
ans[j - 'a'] += cnt * m1[j];
}
}
}
for (int i = 0; i < 26; i++) cout << ans[i] << " ";
cout << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 26;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n, m;
string s;
cin >> n >> m >> s;
vector<int> a(m);
for (int i = 0; i < m; i++) {
cin >> a[i];
}
vector<vector<int>> d(n, vector<int>(N));
d[0][s[0] - 'a']++;
for (int i = 1; i < n; i++) {
for (int j = 0; j < N; j++) {
d[i][j] = d[i - 1][j];
}
d[i][s[i] - 'a']++;
}
vector<int> ans(N);
for (int i = 0; i < n; i++) {
ans[s[i] - 'a']++;
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < N; j++) {
ans[j] += d[a[i] - 1][j];
}
}
for (int i = 0; i < N; i++) {
cout << ans[i] << " ";
}
cout << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, m;
scanf("%d %d", &n, &m);
string s;
cin >> s;
map<char, vector<long long> > count;
for (char ch = 'a'; ch <= 'z'; ch++) {
count[ch] = vector<long long>(n + 10);
}
for (int i = 1; i <= n; i++) {
for (int ch = 'a'; ch <= 'z'; ch++) {
count[ch][i] = count[ch][i - 1];
}
count[s[i - 1]][i]++;
}
map<char, long long> ans;
for (int i = 0; i < m; i++) {
int p;
scanf("%d", &p);
for (int ch = 'a'; ch <= 'z'; ch++) {
ans[ch] += count[ch][p];
}
}
for (int ch = 'a'; ch <= 'z'; ch++) {
ans[ch] += count[ch][n];
}
for (int ch = 'a'; ch <= 'z'; ch++) {
printf("%lld ", ans[ch]);
}
printf("\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int ch[26] = {0};
int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<int> pref(n, 0);
vector<int> v(m);
for (int i = 0; i < m; i++) {
cin >> v[i];
pref[v[i] - 1]++;
}
int sum = 0;
for (int i = n - 1; i >= 0; i--) {
sum += pref[i];
pref[i] = sum + 1;
}
for (int i = 0; i < n; i++) {
ch[s[i] - 'a'] += pref[i];
}
for (int i = 0; i < 26; i++) cout << ch[i] << " ";
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<int> v(m);
for (int i = 0; i < m; i++) {
cin >> v[i];
}
v.push_back(n);
sort(v.begin(), v.end());
vector<long long> answer(26), tmp(26);
int curidx = 0;
for (int i = 0; i < v.size(); i++) {
while (curidx < v[i]) {
tmp[s[curidx] - 'a']++;
curidx++;
}
for (int i = 0; i < 26; i++) answer[i] += tmp[i];
}
for (int i = 0; i < 26; i++) {
cout << answer[i] << " \n"[i == 25];
}
}
}
|
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
long long n, m, a[200010], p[200010], val[200010], num[30];
signed main() {
ios::sync_with_stdio(false);
long long t;
cin >> t;
while (t--) {
cin >> n >> m;
string s;
cin >> s;
for (long long i = 1; i <= n; i++) val[i] = 0;
for (long long i = 1; i <= 26; i++) num[i] = 0;
for (long long i = 1; i <= m; i++) {
cin >> p[i];
val[p[i]]++;
}
a[n] = 1;
for (long long i = n - 1; i >= 1; i--) {
a[i] = a[i + 1] + val[i];
}
for (long long i = 1; i <= n; i++) {
num[s[i - 1] - 'a' + 1] += a[i];
}
for (long long i = 1; i <= 26; i++) {
cout << num[i] << " ";
}
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long N = 100001;
long long mod = 1000000007;
long long min(long long a, long long b) {
if (a < b)
return a;
else
return b;
}
long long max(long long a, long long b) {
if (a > b)
return a;
else
return b;
}
long long power(long long a, long long b) {
long long res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
long long gcd(long long p, long long q) {
if (p % q == 0)
return q;
else {
return gcd(q, p % q);
}
}
long long mul(long long a, long long b) {
return ((a % mod) * (b % mod)) % mod;
}
long long sub(long long a, long long b) {
return (((a - b) % mod) + mod) % mod;
}
void solve() {
long long n, m;
cin >> n >> m;
string s;
cin >> s;
long long ans[26] = {0};
vector<long long> p(n, 0);
while (m--) {
long long x;
cin >> x;
p[x - 1]++;
}
for (long long i = n - 1; i > 0; i--) p[i - 1] += p[i];
for (long long i = 0; i < n; i++) ans[s[i] - 'a'] += (p[i] + 1);
for (long long i = 0; i < 26; i++) cout << ans[i] << " ";
cout << '\n';
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
for (long long mmm = 0; mmm < t; mmm++) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
int t;
cin >> t;
while (t--) {
int n, m;
string s;
cin >> n >> m >> s;
vector<int> acc(n, 0), ans(26, 0);
for (int i = 0; i < m; i++) {
int v;
cin >> v;
acc[v] -= 1;
}
acc[0] = m + 1;
for (int i = 1; i < n; i++) {
acc[i] += acc[i - 1];
}
for (int i = 0; i < n; i++) {
ans[s[i] - 'a'] += acc[i];
}
for (int i = 0; i < 26; i++) {
printf("%d%c", ans[i], i == 25 ? '\n' : ' ');
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
int a[26] = {0};
for (int i = 0; i < n; i++) {
a[s[i] - 'a']++;
}
vector<int> pre(n);
for (int i = 0; i < m; i++) {
int p;
cin >> p;
++pre[p - 1];
}
for (int i = n - 1; i > 0; i--) {
pre[i - 1] += pre[i];
}
for (int i = 0; i < n; i++) {
a[s[i] - 'a'] += pre[i];
}
for (int i = 0; i < 26; i++) cout << a[i] << " ";
cout << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
int t;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<int> p(m);
vector<int> ans(26);
for (int i = 0; i < m; ++i) {
cin >> p[i];
p[i]--;
}
vector<int> cnt(n);
for (int i = 0; i < m; ++i) {
++cnt[p[i]];
}
for (int i = n - 1; i > 0; --i) {
cnt[i - 1] += cnt[i];
}
for (int i = 0; i < n; ++i) {
ans[s[i] - 'a'] += cnt[i] + 1;
}
for (auto elem : ans) {
cout << elem << " ";
}
cout << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int t;
int n, m, p;
string str;
long long ans[30];
void slove() {
cin >> n >> m;
for (int i = 0; i < 29; i++) ans[i] = 0;
vector<int> sum(n + 2, 0);
cin >> str;
for (int i = 1; i <= m; i++) {
cin >> p;
sum[1]++;
sum[p + 1]--;
}
sum[1]++;
sum[n + 1]--;
for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + sum[i];
for (int i = 1; i <= n; i++) {
ans[str[i - 1] - 'a'] += sum[i];
}
for (int i = 0; i < 26; i++) cout << ans[i] << " ";
cout << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> t;
while (t--) {
slove();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solution(int n, int m, string s, vector<int> arr) {
int count[n];
for (int i = 0; i < n; i++) count[i] = 0;
for (int i = m - 1; i >= 0; i--) {
count[arr[i] - 1]++;
}
int ans[26];
for (int i = 0; i < 26; i++) ans[i] = 0;
if (n >= 2)
for (int i = n - 2; i >= 0; i--) {
count[i] += count[i + 1];
}
for (int i = 0; i < n; i++) {
ans[s[i] - 'a'] += count[i] + 1;
}
for (int i = 0; i < 26; i++) cout << ans[i] << " ";
cout << "\n";
}
int main() {
int t;
cin >> t;
for (int i = 0; i < t; i++) {
int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<int> arr(m);
for (int j = 0; j < m; j++) cin >> arr[j];
solution(n, m, s, arr);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int is_prime(long long int n) {
long long int i;
for (i = 2; i <= sqrt(n); i++) {
if (n % i == 0) return i;
}
return 1;
}
long long int gcd(long long int a, long long int b) {
while (b != 0) {
long long int c = a % b;
a = b;
b = c;
}
return a;
}
void solve() {
long long int n, m;
cin >> n >> m;
string s;
cin >> s;
long long int a[m];
for (long long int i = 0; i < m; i++) cin >> a[i];
long long int pre[26][n];
for (long long int i = 0; i < 26; i++)
for (long long int j = 0; j < n; j++) pre[i][j] = 0;
for (long long int i = 0; i < n; i++) {
pre[s[i] - 'a'][i]++;
}
for (long long int i = 0; i < 26; i++) {
for (long long int j = 1; j < n; j++) {
pre[i][j] = pre[i][j - 1] + pre[i][j];
}
}
long long int freq[26] = {0};
for (long long int i = 0; i < m; i++) {
for (long long int j = 0; j < 26; j++) {
freq[j] += pre[j][a[i] - 1];
}
}
for (long long int i = 0; i < 26; i++) {
freq[i] += pre[i][n - 1];
}
for (long long int i = 0; i < 26; i++) cout << freq[i] << " ";
cout << "\n";
}
void testcase() {
int t;
cin >> t;
while (t--) {
solve();
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
testcase();
}
|
#include <bits/stdc++.h>
using namespace std;
void _print(long long int t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
template <class T, class V>
void _print(pair<T, V> p) {
cerr << "{";
_print(p.first);
cerr << ",";
_print(p.second);
cerr << "}";
}
template <class T>
void _print(vector<T> v) {
cerr << "[";
for (T i : v) {
_print(i);
cerr << " ";
}
cerr << "]";
}
const int INF = 1e6 + 1;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
long long int t;
cin >> t;
while (t--) {
long long int n, m;
cin >> n >> m;
string s;
cin >> s;
long long int arr[m];
for (long long int i = 0; i < m; i++) {
cin >> arr[i];
}
sort(arr, arr + m);
vector<long long int> freq(n + 1, 0);
freq[n] = 1;
for (long long int i = m - 1; i >= 0; i--) {
freq[arr[i]]++;
}
for (long long int i = n - 1; i > 0; i--) {
freq[i] += freq[i + 1];
}
vector<long long int> ans(26, 0);
for (long long int i = 0; i < n; i++) {
ans[s[i] - 'a'] += freq[i + 1];
}
for (long long int j : ans) {
cout << j << " ";
}
cout << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
void show(vector<int> v) {
for (auto t : v) cout << t << " ";
cout << endl;
}
void printAr(int a[], int n) {
for (int *i = a; i != a + n; ++i) cout << *i << " ";
cout << endl;
}
const int NN = 2e5 + 3;
int cm[NN][26], p[NN];
int ans[26];
const int mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
cin >> T;
int n, x, k, m;
string s;
while (T--) {
cin >> n >> m;
cin >> s;
fill(ans, ans + 26, 0);
for (int i = 0; i < m; i++) {
cin >> p[i];
p[i]--;
}
for (int i = 0; i < 26; i++) {
cm[0][i] = 0;
}
cm[0][s[0] - 'a']++;
for (int j = 1; j <= n - 1; j++) {
for (int i = 0; i < 26; i++) {
cm[j][i] = cm[j - 1][i];
}
cm[j][s[j] - 'a']++;
}
for (int i = 0; i < m; i++) {
for (int j = 0; j <= 25; j++) {
ans[j] = ans[j] + cm[p[i]][j];
}
}
for (int i = 0; i < 26; i++) {
ans[i] = ans[i] + cm[n - 1][i];
}
printAr(ans, 26);
}
}
|
#include <bits/stdc++.h>
using namespace std;
char s[200010];
int g[200010][30];
int main() {
int i, j, k;
int n, t, m;
cin >> t;
while (t--) {
cin >> n >> m;
cin >> s + 1;
int ans[30] = {0};
for (i = 1; i <= n; i++) {
for (j = 0; j < 26; j++) {
g[i][j] = g[i - 1][j];
}
g[i][s[i] - 'a']++;
}
for (i = 1; i <= m; i++) {
int x;
cin >> x;
for (j = 0; j < 26; j++) {
ans[j] += g[x][j];
}
}
for (i = 0; i < 26; i++) ans[i] += g[n][i];
for (i = 0; i < 26; i++) {
if (i) printf(" ");
printf("%d", ans[i]);
}
puts("");
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
template <class T>
void _sf(T &x) {
cin >> x;
}
void _sf(int &x) { scanf("%d", &x); }
void _sf(long long &x) { scanf("%lld", &x); }
void _sf(double &x) { scanf("%lf", &x); }
void _sf(char &x) { scanf(" %c", &x); }
void _sf(char *x) { scanf("%s", x); }
void sf() {}
template <class T, class... U>
void sf(T &head, U &...tail) {
_sf(head);
sf(tail...);
}
template <class T>
void _out(const T &x) {
cout << x;
}
void _out(const int &x) { printf("%d", x); }
void _out(const long long &x) { printf("%lld", x); }
void _out(const double &x) { printf("%.16f", x); }
void _out(const char &x) { putchar(x); }
void _out(const char *x) { printf("%s", x); }
template <class T, class U>
void _out(const pair<T, U> &x) {
_out(x.F);
putchar(' ');
_out(x.S);
}
template <class T>
void _out(const vector<T> &x) {
for (auto i = x.begin(); i != x.end(); _out(*i++))
if (i != x.cbegin()) putchar(' ');
}
void out() {}
template <class T, class... U>
void out(const T &head, const U &...tail) {
_out(head);
putchar(sizeof...(tail) ? ' ' : '\n');
out(tail...);
}
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
const int maxn = 2e5 + 5;
char s[maxn];
int cnt[maxn];
int sum[30];
int main() {
int ___T;
scanf("%d", &___T);
for (int cs = 1; cs <= ___T; cs++) {
int n, m;
sf(n, m);
memset((cnt), 0, sizeof((cnt)));
cin >> (s + 1);
for (int i = (1); i <= (m); ++i) {
int x;
sf(x);
if (i == m) {
cnt[n]++;
}
cnt[x]++;
}
memset((sum), 0, sizeof((sum)));
for (int i = (n); i >= 1; --i) {
cnt[i] += cnt[i + 1];
}
for (int i = (1); i <= (n); ++i) {
;
}
for (int i = (1); i <= (n); ++i) {
sum[s[i] - 'a'] += cnt[i];
}
for (int i = (0); i <= (25); ++i) {
cout << sum[i] << " ";
}
cout << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 20;
long long pfx[N];
int32_t main() {
long long t;
cin >> t;
while (t--) {
long long n, m;
cin >> n >> m;
string s;
cin >> s;
long long mx = 0;
for (long long i = 0; i <= n; i++) pfx[i] = 0;
long long x;
for (long long i = 0; i < m; i++) cin >> x, pfx[x]++, mx = max(mx, x);
long long fq[26];
memset(fq, 0, sizeof fq);
for (long long i = mx; i >= 1; i--) pfx[i] += pfx[i + 1];
for (long long i = 1; i <= n; i++) fq[s[i - 1] - 'a'] += pfx[i] + 1;
for (long long i = 0; i < 26; i++) cout << fq[i] << " ";
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename N, typename A>
struct Graph {
private:
unordered_map<N, unordered_map<N, A>> data;
public:
Graph() { data = unordered_map<N, unordered_map<N, A>>(); }
~Graph() {}
bool as_node(const N &n) const {
auto res = data.find(n);
return res != data.end();
}
bool as_arc(const N &n, const N &m) const {
if (as_node(n) && as_node(m)) {
auto res = data.at(n).find(m);
return res != data.at(n).end();
}
return false;
}
void insert_node(const N &n) {
if (!as_node(n)) {
data[n] = unordered_map<N, A>();
}
}
void insert_arc(const N &n, const N &m, const A &a) {
if (!as_arc(n, m)) {
data[n][m] = a;
}
}
void insert_arc_node(const N &n, const N &m, const A &a) {
insert_node(n);
insert_node(m);
insert_arc(n, m, a);
}
const A &arc_at(const N &n, const N &m) const { return data[n][m]; }
const unordered_map<N, A> &node_neighbours(const N &n) const {
return data.at(n);
}
template <size_t VSIZE>
bool as_path_bfs(N s, N t, array<bool, VSIZE> &v) const {
if (s == t) return true;
if (v[s]) return false;
v[s] = true;
for (const auto &m : node_neighbours(s)) {
if (!v[m.first])
if (as_path_bfs(m.first, t, v)) return true;
}
return false;
}
};
template <typename T>
void __printc(const T &c) {
for (const auto &x : c) {
cout << x << " ";
}
}
template <typename T>
void print(const vector<T> &c) {
__printc(c);
}
template <typename T>
void print(const list<T> &c) {
__printc(c);
}
template <typename T>
void print(const set<T> &c) {
__printc(c);
}
template <typename T>
void print(const T &x) {
cout << x;
}
template <typename T>
void println(const T &x) {
print(x);
cout << "\n";
}
void test_case() {
const uint32_t SIZE = 200001;
array<int32_t, SIZE> cnt;
cnt.fill(0);
unordered_map<char, int32_t> mp;
int32_t n, m;
cin >> n >> m;
string s;
cin >> s;
int j = 0;
for (int64_t i = (0); i < (n); i++) {
if (mp.find(s[i]) == mp.end()) {
mp[s[i]] = j;
j++;
}
}
int temp;
vector<int> p(m);
for (int64_t i = (0); i < (m); i++) {
cin >> temp;
p.push_back(temp);
}
sort(p.begin(), p.end(), greater<int>());
for (int64_t i = (0); i < (n); i++) {
while (p.size() > 0 && (int64_t)p.back() <= i) {
p.pop_back();
}
cnt[mp[s[i]]] += 1 + p.size();
}
for (int64_t i = (0); i < (26); i++) {
char ch = (char)('a' + i);
if (mp.find(ch) == mp.end()) {
cout << 0 << " ";
} else {
cout << cnt[mp[ch]] << " ";
}
}
cout << "\n";
}
int main(void) {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
;
int t;
cin >> t;
while (t-- > 0) {
test_case();
}
return EXIT_SUCCESS;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<long long int> v;
long long int letter[200];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int n, x, testCase, ans = 0, sum = 0, a, b, c, count = 0, m;
cin >> testCase;
while (testCase--) {
memset(letter, (0), sizeof(letter));
cin >> n >> m;
string s;
cin >> s;
v.clear();
for (int i = 0; i < m; i++) {
cin >> x;
v.push_back(x);
}
v.push_back(n);
sort(v.begin(), v.end());
vector<long long int>::iterator it;
it = v.begin();
long long int t = v.size();
for (int i = 0; i < s.size(); i++) {
char ch = s[i];
letter[ch] += t;
while (*it == i + 1) {
t--;
it++;
}
}
for (int i = 97; i <= 97 + 25; i++) {
cout << letter[i] << " ";
}
cout << endl;
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.