text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; template <typename... T> void pn(T... args) { ((cout << args << " "), ...); cout << "\n"; } template <typename... T> void ps(T... args) { ((cout << args << " "), ...); cout << ""; } long long power(long long a, long long b, long long P = 1000000007) { long long res = 1; for (; b; b >>= 1, a = 1ll * a * a % P) if (b & 1) res = 1ll * res * a % P; return res; } void solve() { long long n, m, a; cin >> n >> m; string s; cin >> s; vector<long long> arr(n, 0); for (long long i = 0; i < m; i++) { cin >> a; arr[a - 1]++; } long long cnt = 1; long long ans[26] = {}; for (long long i = n - 1; i >= 0; i--) { cnt += arr[i]; ans[s[i] - 'a'] += cnt; } for (auto j : ans) cout << j << " "; cout << "\n"; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n; int a[maxn]; int mx[maxn]; int mk[maxn]; int ans[maxn][26]; void in(); void solve(); void out(); int main() { in(); solve(); out(); } void in() { ios::sync_with_stdio(false); cout.tie(0); cin.tie(0); cin >> n; } void solve() { for (int t = 0; t < n; t++) { int T, m; cin >> T >> m; string S; cin >> S; for (int i = 0; i < m; i++) cin >> a[i]; a[m++] = T; sort(a, a + m); int now = m; for (int i = T - 1; i >= 0; i--) { while (now > 0 && a[now - 1] > i) now--; ans[t][S[i] - 'a'] += m - now; } } } void out() { for (int i = 0; i < n; i++) { for (int j = 0; j < 26; j++) cout << ans[i][j] << ' '; cout << '\n'; } }
#include <bits/stdc++.h> using namespace std; int n, m, k, t; int dr[] = {0, 0, -1, 1}; int dc[] = {1, -1, 0, 0}; int alp[200001][26]; int a[200001]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> t; while (t--) { int ans[26] = {0}; cin >> n >> m; string s; cin >> s; for (int i = 0; i < m; i++) { cin >> a[i]; a[i]--; } for (int i = 0; i < 26; i++) { alp[0][i] = 0; } alp[0][s[0] - 'a'] = 1; for (int i = 1; i < n; i++) { for (int j = 0; j < 26; j++) { alp[i][j] = alp[i - 1][j]; } alp[i][s[i] - 'a']++; } for (int i = 0; i < n; i++) { ans[s[i] - 'a'] += 1; } for (int i = 0; i < m; i++) { for (int j = 0; j < 26; j++) { ans[j] += alp[a[i]][j]; } } for (int i = 0; i < 26; i++) { cout << ans[i] << ' '; } cout << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long int w; cin >> w; while (w--) { long long int n, m; cin >> n >> m; string s; cin >> s; vector<vector<long long int> > v(n, vector<long long int>(26, 0)); v[0][(s[0] - 'a')]++; for (long long int i = 1; i <= n - 1; i++) { v[i] = v[i - 1]; v[i][(s[i] - 'a')]++; } vector<long long int> ans(26, 0); vector<long long int> p(m); for (long long int i = 0; i <= m - 1; i++) { cin >> p[i]; p[i]--; for (long long int j = 0; j <= 25; j++) { ans[j] += v[p[i]][j]; } } for (long long int j = 0; j <= 25; j++) { ans[j] += v[n - 1][j]; cout << ans[j] << " "; } cout << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long tc; cin >> tc; while (tc--) { long long n, m; cin >> n >> m; string s; cin >> s; long long arr[m]; for (long long i = 0; i < m; i++) cin >> arr[i]; long long MM = 97; long long dp[n + 1][26]; unordered_map<long long, long long, custom_hash> mp; for (auto ch : s) mp[ch % MM]++; for (long long i = 0; i < 26; i++) { dp[n][i] = mp[i]; } for (long long i = n - 1; i >= 1; i--) { long long target = s[i] % MM; for (long long j = 0; j < 26; j++) { if (target == j) { dp[i][j] = dp[i + 1][j] - 1; } else { dp[i][j] = dp[i + 1][j]; } } } long long res[26]; for (long long i = 0; i < 26; i++) { res[i] = dp[n][i]; } for (long long i = 0; i < m; i++) { long long l = arr[i]; for (long long j = 0; j < 26; j++) res[j] += dp[l][j]; } for (long long i = 0; i < 26; i++) cout << res[i] << " "; } return 0; }
#include <bits/stdc++.h> using namespace std; int t, n, m, tmp; int main() { scanf("%d", &t); while (t--) { int p[200002] = { 0, }; char s[200002] = { 0, }; int ans[26] = { 0, }; int cnt = 1; scanf("%d %d\n", &n, &m); scanf("%s", s); for (int i = 0; i < n; ++i) ans[s[i] - 'a']++; for (int i = 0; i < m; ++i) { scanf("%d", &tmp); p[i] = tmp - 1; } sort(p, p + m); for (int i = m - 1; i > 0; i--) { for (int j = p[i]; j > p[i - 1]; j--) { ans[s[j] - 'a'] += cnt; } ++cnt; } for (int i = 0; i <= p[0]; ++i) { ans[s[i] - 'a'] += cnt; } for (int i = 0; i < 26; ++i) printf("%d ", ans[i]); puts(""); } }
#include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; } template <typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; } void dbg_out() { cerr << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } const long verybig = 10000000000000; int gcd(int a, int b) { if (a == 0) return b; if (b == 0) return a; if (a == b) return a; if (a > b) return gcd(a - b, b); return gcd(a, b - a); } bool isPrime(int n) { if (n <= 1) return false; for (int i = 2; i < n; i++) if (n % i == 0) return false; return true; } void solve() { int n, k; cin >> n >> k; string s; cin >> s; int a[k]; for (long long i = 0; i < (k); ++i) cin >> a[i]; int count[n]; memset(count, 0, sizeof(count)); for (int i = 0; i < k; i++) { count[a[i] - 1]++; } for (int i = n - 1; i > 0; i--) count[i - 1] += count[i]; int c[26]; memset(c, 0, sizeof(c)); for (int i = 0; i < n; i++) { c[s[i] - 97] += (count[i] + 1); } for (long long i = 0; i < (26); ++i) cout << c[i] << " "; cout << "\n"; } int main() { cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); long long t; cin >> t; for (long long i = 0; i < (t); ++i) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const long long mod = 9973; inline long long read() { long long X = 0; bool flag = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') flag = 0; ch = getchar(); } while (ch >= '0' && ch <= '9') { X = (X << 1) + (X << 3) + ch - '0'; ch = getchar(); } if (flag) return X; return ~(X - 1); } long long n, m, k; long long ar[N], br[N]; long long ans; char ch[N]; int as[N]; int an[30]; void solve() { n = read(); m = read(); scanf("%s", ch + 1); for (register int i(0); i <= 30; ++i) an[i] = 0; for (register int i(0); i <= n + 10; ++i) as[i] = 0; for (register int i(1); i <= m; ++i) { int t = read(); as[1]++; as[t + 1]--; } int t = 0; for (register int i(1); i <= n; ++i) { t += as[i]; an[ch[i] - 'a'] += t + 1; } for (register int i(0); i <= 25; ++i) printf("%d ", an[i]); puts(""); } int main() { int T; T = read(); while (T--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> bool umin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool umax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } const long long N = 200 * 1000 + 9; const long long inf = 1e18; const long long mod = 1e9 + 7; long long i, j, k; void solve() { long long n, m; cin >> n >> m; string s; cin >> s; vector<long long> v(m); map<long long, long long> mpp; for (i = 0; i < m; i++) cin >> v[i], mpp[v[i]]++; vector<long long> prefix_sum(n + 1, 0); for (i = 1; i <= n; i++) { if (mpp[i]) prefix_sum[i] = mpp[i]; } for (i = n - 1; i >= 1; i--) { prefix_sum[i] = prefix_sum[i + 1] + prefix_sum[i]; } vector<long long> ans(27, 0); for (i = 0; i < n; i++) { ans[s[i] - 'a']++; } map<char, long long> mpr; for (i = 0; i < 26; i++) { for (j = 1; j <= n; j++) { long long x = s[j - 1] - 'a'; if (x == i) ans[i] = ans[i] + prefix_sum[j]; } } for (i = 0; i < 26; i++) cout << ans[i] << " "; cout << '\n'; ; return; } signed main() { long long ___T; scanf("%lld", &___T); for (long long cs = 1; cs <= ___T; cs++) solve(); return 0; }
#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; vector<int> v(m); for (int i = 0; i < m; i++) { cin >> v[i]; } sort(v.begin(), v.end()); vector<int> ans(26); for (int i = 0; i < n; i++) { int k = v.end() - upper_bound(v.begin(), v.end(), i); ans[s[i] - 'a'] += (k + 1); } for (auto x : ans) cout << x << " "; cout << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n, m; cin >> n >> m; string s; cin >> s; vector<long long> v(m); for (auto &x : v) cin >> x; ; sort(v.begin(), v.end()); vector<long long> less(n); long long index = 0; for (int i = 0; i < n; i++) { if (index < m) { if (i + 1 <= v[index]) less[i] = m - index; else { index++; i--; } } else less[i] = 0; } long long arr[26] = {0}; for (int i = 0; i < n; i++) { arr[s[i] - 'a'] += less[i]; } for (int i = 0; i < n; i++) { arr[s[i] - 'a']++; } for (auto x : arr) cout << x << " "; cout << endl; ; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 10; long long n; long long a[maxn]; long long mx[maxn]; long long mk[maxn]; long long ans[maxn][26]; void in(); void solve(); void out(); int main() { in(); solve(); out(); } void in() { ios::sync_with_stdio(false); cout.tie(0); cin.tie(0); cin >> n; } void solve() { for (long long t = 0; t < n; t++) { long long T, m; cin >> T >> m; string S; cin >> S; for (long long i = 0; i < m; i++) cin >> a[i]; a[m++] = T; sort(a, a + m); long long now = m; for (long long i = T - 1; i >= 0; i--) { while (now > 0 && a[now - 1] > i) now--; ans[t][S[i] - 'a'] += m - now; } } } void out() { for (long long i = 0; i < n; i++) { for (long long j = 0; j < 26; j++) cout << ans[i][j] << ' '; cout << '\n'; } }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; long long n, m, x, dis[N], sum = 0, arr[27], brr[2 * N]; vector<int> v[N], vv; queue<int> q; bool vis[N]; int main() { long long t; string s; cin >> t; while (t--) { cin >> n >> m; cin >> s; for (int i = 0; i < n; i++) { arr[s[i] - 'a' + 1] += 1; } while (m--) { cin >> x; brr[1]++; brr[x + 1]--; } for (int i = 1; i <= n; i++) { brr[i] += brr[i - 1]; } for (int i = 0; i < n; i++) { arr[s[i] - 'a' + 1] += brr[i + 1]; } for (int i = 1; i <= 26; i++) { cout << arr[i] << " "; arr[i] = 0; } for (int i = 1; i <= n; i++) { brr[i] = 0; } cout << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { long long n, m; cin >> n >> m; string s; cin >> s; vector<int> a(26, 0); vector<int> char_index[26]; for (int i = 0; i < n; i++) { a[s[i] - 'a']++; char_index[s[i] - 'a'].push_back(i); } for (int i = 0; i < m; i++) { long long temp; cin >> temp; temp--; for (int j = 0; j < 26; j++) { std::vector<int>::iterator it = upper_bound(char_index[j].begin(), char_index[j].end(), temp); int count = it - char_index[j].begin(); a[j] += count; } } for (int i = 0; i < 26; i++) cout << a[i] << " "; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::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> v(n), res(26); for (int i = 0; i < m; i++) { int val; cin >> val; val -= 1; v[val]++; } for (int i = n - 1; i > 0; i--) v[i - 1] += v[i]; for (int i = 0; i < n; i++) res[s[i] - 'a'] += (v[i] + 1); for (int i = 0; i < 26; i++) cout << res[i] << " "; cout << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; void run() { ll n, m; cin >> n >> m; string s; cin >> s; vector<ll> p; for (ll i = 0; i < m; ++i) { ll x; cin >> x; p.push_back(x); } sort(p.begin(), p.end()); vector<ll> res(26, 0); ++m; ll currs = 0; ll currp = 0; while (currs < n) { auto chr = s[currs]; while (currp < p.size() && currs == p[currp]) { --m; ++currp; } res[chr - 'a'] += m; ++currs; } cout << res[0]; for (int i = 1; i < 26; ++i) cout << ' ' << res[i]; cout << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t; cin >> t; while (t--) run(); return 0; }
#include <bits/stdc++.h> const int INF = 2e9; using namespace std; map<int, map<char, int>> arr; int res[30]; int main(void) { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int T; cin >> T; while (T--) { arr.clear(); memset(res, 0, sizeof(res)); int n, m; cin >> n >> m; string s; cin >> s; for (int i = 1; i <= s.size(); i++) { arr[i][s[i - 1]]++; for (auto cnt : arr[i - 1]) arr[i][cnt.first] += cnt.second; } for (int i = 0; i < m; i++) { int p; cin >> p; for (int j = 'a'; j <= 'z'; j++) { res[j - 'a'] += arr[p][j]; if (i == m - 1) { res[j - 'a'] += arr[s.size()][j]; cout << res[j - 'a'] << " "; } } } cout << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); ; long long t; cin >> t; while (t--) { long long n, m; cin >> n >> m; string s; cin >> s; vector<long long> p(m), arr(26, 0); vector<long long> ans(n, 0); for (int i = 0; i < int(m); i++) { cin >> p[i]; ++ans[p[i] - 1]; } for (long long i = n - 1; i > 0; --i) ans[i - 1] += ans[i]; for (int i = 0; i < int(n); i++) { arr[s[i] - 'a'] += ans[i] + 1; } for (int i = 0; i < int(26); i++) cout << arr[i] << " "; cout << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int mark[27]; int test; cin >> test; while (test--) { int n, m, x; memset(mark, 0, sizeof(mark)); cin >> n >> m; vector<int> v[27]; string s; cin >> s; for (int i = 0; i < n; i++) { x = s[i] - 'a'; mark[x]++; v[x].push_back(i + 1); } for (int i = 0; i < m; i++) { cin >> x; for (int j = 0; j < 26; j++) { auto low = upper_bound(v[j].begin(), v[j].end(), x); long long int a = low - v[j].begin(); mark[j] += a; } } for (int i = 0; i < 26; i++) cout << mark[i] << " "; cout << endl; } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; const long double PI = 3.141592653589793; const long long N = 1e7; void solve() { long long n, m; cin >> n >> m; vector<long long> a(m + 2), ans(26); a[0] = (-1) * N; string s; cin >> s; for (long long i = 1; i <= m; i++) { cin >> a[i]; --a[i]; } a[m + 1] = N; sort(a.begin(), a.end()); for (long long i = 0; i < n; i++) { char c = s[i]; ans[c - 'a']++; long long lo = 0, hi = m + 1; long long mid; while (lo + 1 < hi) { mid = (lo + hi) / 2; if (a[mid] >= i) hi = mid; else lo = mid; } long long d = m - hi + 1; ans[c - 'a'] += d; } for (auto it : ans) cout << it << " "; cout << "\n"; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cout << fixed << setprecision(13); ; long long T; cin >> T; while (T--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; long long t; long long n, m; string s; long long p[200005]; long long x[200005]; long long res[26]; int main() { cin >> t; while (t--) { cin >> n >> m >> s; for (int i = 0; i < m; i++) cin >> p[i]; for (int i = 0; i < m; i++) x[p[i] - 1]++; x[n - 1] = 1; long long br = 0; for (int i = n - 1; i >= 0; i--) { br += x[i]; res[s[i] - 'a'] += br; } for (int i = 0; i < 26; i++) cout << res[i] << " "; cout << "\n"; for (int i = 0; i < n; i++) x[i] = 0; for (int i = 0; i < 26; i++) res[i] = 0; } return 0; }
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { return a > b ? a : b; } long long min(long long a, long long b) { return a < b ? a : b; } long long abso(long long a) { return a > 0 ? a : -a; } bool cmp(const pair<int, int> &a, const pair<int, int> &b) { if (a.first == b.first) return a.second < b.second; return a.first < b.first; } vector<long long> v, alp; unordered_map<char, long long> U; int main(int argc, char const *argv[]) { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; string st; cin >> st; U.clear(); alp.resize(st.size() + 1); for (int i = 0; i <= st.size(); i++) { alp[i] = 0; } v.resize(m); for (int i = 0; i < m; i++) { cin >> v[i]; v[i]--; alp[0] += 1; alp[v[i] + 1] -= 1; } alp[0] += 1; for (int i = 1; i < alp.size(); i++) { alp[i] += alp[i - 1]; } for (int i = 0; i < st.size(); i++) { U[st[i]] += alp[i]; } for (int i = 0; i < 26; i++) { cout << U[char('a' + i)] << " "; } cout << "\n"; } }
#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 a[m]; for (int i = 0; i < m; i++) { cin >> a[i]; a[i] -= 1; } int b[26][n]; for (int i = 0; i < 26; i++) { for (int j = 0; j < n; j++) b[i][j] = 0; } for (int i = 0; i < n; i++) { if (i == 0) b[s[i] - 'a'][i] = 1; else { for (int j = 0; j < 26; j++) b[j][i] = b[j][i - 1]; b[s[i] - 'a'][i] = b[s[i] - 'a'][i - 1] + 1; } } int c[26] = {0}; for (int i = 0; i < m; i++) { int k = a[i]; for (int j = 0; j < 26; j++) { c[j] += b[j][k]; } } for (int j = 0; j < 26; j++) { c[j] += b[j][n - 1]; } for (int i = 0; i < 26; i++) cout << c[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; vector<long long int> freq(26, 0); vector<long long int> arr(m); vector<long long int> count(n + 1, 0); for (int i = 0; i < m; i++) { cin >> arr[i]; } for (int i = 0; i < m; i++) { count[0] += 1; count[arr[i]] -= 1; } for (int i = 1; i < n; i++) count[i] = count[i] + count[i - 1]; for (int i = 0; i < n; i++) count[i] += 1ll; for (int j = 0; j < n; j++) { freq[s[j] - 'a'] += count[j]; } for (int i = 0; i < 26; i++) { cout << freq[i] << " "; } cout << endl; } }
#include <bits/stdc++.h> using namespace std; const int N = 1000001; long long highp2(long long n) { return (n & (~(n - 1))); } bool isPrime(long long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } long long binarysearchlf(long long l, long long h, vector<long long> &a, long long k) { while (l < h) { long long mid = l + ((h - l + 1) / 2); if (a[mid] < k) l = mid; else h = mid - 1; } return l; } long long binarysearchft(long long l, long long h, vector<long long> &a, long long k) { while (l < h) { long long mid = l + ((h - l) / 2); if (a[mid] < k) l = mid + 1; else h = mid; } return l; } long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } string getstring(long long k, char x) { string s(k, x); return s; } int flpass(int i, vector<long long> &v, int n) { int flag = 0; for (long long j = 0; j < n; j++) { if (v[j] != 0 && j != i) { flag = 1; break; } } return flag; } int getmaxi(int i, vector<long long> &v, int n) { int mi = 0; for (long long j = 1; 1 < n ? j < n : j > n; 1 < n ? j += 1 : j -= 1) { if (j == i) continue; if (v[j] > v[mi]) { mi = j; } } return mi; } long long ask(long long a, long long b) { cout << "?" << " " << a + 1 << " " << b + 1 << endl; long long z; cin >> z; return z; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { long long n; cin >> n; long long m; cin >> m; string s; cin >> s; vector<long long> v(m); vector<long long> v1(n + 1, 0); for (long long i = 0; i < m; i++) { cin >> v[i]; v1[0]++; v1[v[i]]--; } vector<long long> vs(n); vs[0] = v1[0]; for (long long i = 1; 1 < n ? i < n : i > n; 1 < n ? i += 1 : i -= 1) { vs[i] = vs[i - 1] + v1[i]; } vector<long long> ans(26); for (long long i = 0; i < n; i++) { ans[s[i] - 'a'] += vs[i] + 1; } for (long long i = 0; i < 26; i++) cout << ans[i] << " "; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; void yes() { cout << "YES" << endl; } void no() { cout << "NO" << endl; } void nl() { cout << endl; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; string s; vector<vector<int>> a; a.resize(27); vector<int> v(m), ans(27); cin >> s; for (long long i = 0; i < 27; i++) ans[i] = 0; for (long long i = 0; i < n; i++) { a[s[i] - 'a'].push_back(i); } for (long long i = 0; i < m; i++) { cin >> v[i]; v[i]--; } v.push_back(n - 1); for (long long i = 0; i < m + 1; i++) { for (long long j = 0; j < 26; j++) { if (a[j].size() == 0) continue; int x = upper_bound(a[j].begin(), a[j].end(), v[i]) - a[j].begin(); ans[j] += x; } } for (long long i = 0; i < 26; i++) cout << ans[i] << " "; cout << endl; } }
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize "trapv" #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; cin >> t; while (t--) { long long n, m; cin >> n >> m; string s; cin >> s; map<char, long long> v; map<long long, long long> f, r; long long p[m]; for (long long i = 0; i < m; i++) { cin >> p[i]; f[p[i] - 1]++; } if (f.find(n) == f.end()) { r[n - 1] = 1; } else { r[n - 1] = f[n - 1] + 1; } for (long long i = n - 2; i >= 0; i--) { if (f.find(i) == f.end()) r[i] = r[i + 1]; else r[i] = r[i + 1] + f[i]; } for (long long i = 0; i < n; i++) { v[s[i]] += r[i]; } for (char i = 'a'; i <= 'z'; i++) { cout << v[i] << " "; } cout << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int t, n, m, x, ans[26], s[26][maxn]; char ch; int main() { cin >> t; while (t--) { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> ch; for (char j = 'a'; j <= 'z'; j++) { if (ch != j) s[j - 'a'][i] = s[j - 'a'][i - 1]; else s[j - 'a'][i] = s[j - 'a'][i - 1] + 1; } } for (int i = 1; i <= m; i++) { cin >> x; for (int j = 0; j < 26; j++) ans[j] += s[j][x]; } for (int i = 0; i < 26; i++) ans[i] += s[i][n]; for (int i = 0; i < 26; i++) cout << ans[i] << " "; cout << endl; memset(ans, 0, sizeof(ans)); for (int i = 1; i <= n; i++) for (int j = 0; j < 26; j++) s[j][i] = 0; } return 0; }
#include <bits/stdc++.h> using namespace std; template <typename a> void SWAP(a &b, a &c) { a d = b; b = c; c = d; } long long power(long long a, long long b) { long long result = 1; while (b) { if (b & 1) result = a * result; a *= a; b >>= 1; } return result; } long long gcd(long long a, long long b) { while (b) { a = a % b; SWAP(a, b); } return a; } long long lcm(long long a, long long b) { return (a * (b / gcd(a, b))); } int main() { long long t; cin >> t; while (t--) { long long n, m; cin >> n >> m; string s; cin >> s; long long p[m + 5], freq[n + 5]; memset(freq, 0, sizeof freq); for (long long i = 0; i < m; i++) { cin >> p[i]; freq[p[i]]++; } for (long long i = n - 1; i > 0; i--) { freq[i - 1] += freq[i]; } long long ans[1010] = {0}; for (long long i = 0; i < n; i++) { long long input = (long long)s[i]; ans[input] += freq[i + 1] + 1; } for (long long i = 'a'; i <= 'z' - 1; i++) printf("%lld ", ans[i]); printf("%lld\n", ans[(int)'z']); } return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> p; int t, m, n; int quantoscaras(int i) { return 1 + m - (upper_bound(p.begin(), p.end(), i) - p.begin()); } int main() { string str; cin >> t; while (t--) { p.clear(); int cont[26]; for (int i = 0; i < 26; i++) cont[i] = 0; cin >> n >> m; cin >> str; for (int i = 0; i < m; i++) { int x; cin >> x; p.push_back(x); } sort(p.begin(), p.end()); for (int i = 0; i < (int)str.size(); i++) { cont[str[i] - 'a'] += quantoscaras(i); } for (int i = 0; i < 26; i++) { cout << cont[i] << " "; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int t, n, m, a[200005], v[26]; string s; int ser(int x) { int l = 1, r = m, mid, best = m + 1; while (l <= r) { mid = (l + r) / 2; if (a[mid] >= x) { best = mid; r = mid - 1; } else l = mid + 1; } return best; } int main() { int i, j, p; cin >> t; while (t--) { memset(v, 0, sizeof(v)); cin >> n >> m >> s; for (i = 1; i <= m; i++) cin >> a[i]; sort(a + 1, a + m + 1); for (i = 1; i <= n; i++) { int pos = ser(i); v[s[i - 1] - 'a'] += m - pos + 1; } for (i = 0; i < n; i++) v[s[i] - 'a']++; for (i = 0; i < 26; i++) cout << v[i] << ' '; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; char s[200002]; int main() { int t; cin >> t; while (t--) { int n, m; scanf("%d%d", &n, &m); vector<int> f(n); scanf("%s", s); for (int i = 0; i < m; ++i) { int x; scanf("%d", &x); --x; ++f[x]; } for (int i = n - 2; i >= 0; --i) f[i] += f[i + 1]; long long freq[26] = {}; for (int i = 0; i < n; ++i) freq[s[i] - 'a'] += f[i] + 1; for (int i = 0; i < 26; ++i) printf("%lld ", freq[i]); puts(""); } return 0; }
#include <bits/stdc++.h> const long long N = 1e6 + 5; const double pi = acosl(-1); const long long inf = 1e18 + 5; using namespace std; template <typename T> void debug(string s, T x) { cout << s << " = " << x << "\n"; } template <typename T, typename... Args> void debug(string s, T x, Args... args) { cout << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...); } template <class T> void print_container(T &container) { for (auto &t : container) { cout << t << " "; } cout << "\n"; } template <class T> void print_pair_container(T &container) { for (auto &t : container) { cout << t.first << " " << t.second << "\n"; } cout << "\n"; } template <class T> void printArr(T &a, long long n) { for (long long i = 0; i < n; i++) { cout << a[i] << " "; } cout << "\n"; } long long n, k; string s; void solve() { map<char, long long> ans; map<long long, long long> m; cin >> n >> k; cin >> s; s = ' ' + s; long long curr = 1; for (long long i = 0; i < k; i++) { long long x; cin >> x; m[x]++; } long long done = 0; for (auto kv : m) { while (curr <= kv.first) { ans[s[curr]] += (k - done); curr++; } done += kv.second; } for (auto x : s) { ans[x]++; } for (long long i = 0; i < 26; i++) { cout << ans['a' + i] << " "; } cout << "\n"; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> 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; string s; cin >> s; int i = 0; int p[m]; vector<int> ci(26, 0); for (i = 0; i < m; i++) { cin >> p[i]; p[i]--; } sort(p, p + m); int j = 0; for (i = 0; i < s.length(); i++) { while (p[j] < i && j < m) { j++; } ci[s[i] - 'a'] += m + 1 - j; } for (i = 0; i < 26; i++) { cout << ci[i] << " "; } cout << "\n"; } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int N = 200010, mod = 1e9 + 7, INF = 0x3f3f3f3f; const double eps = 1e-6; int n, m; long long p[N], sum[100]; char s[N]; int main() { int _; scanf("%d", &_); while (_--) { scanf("%d%d%s", &n, &m, s + 1); for (int i = 1; i <= m; i++) { int x; scanf("%d", &x); p[1]++; p[x + 1]--; } p[1]++; for (int i = 1; i <= n; i++) p[i] += p[i - 1]; for (int i = 1; i <= n; i++) sum[s[i] - 'a'] += p[i]; for (int i = 0; i < 26; i++) printf("%lld ", sum[i]); puts(""); for (int i = 1; i <= n; i++) p[i] = 0; for (int i = 0; i < 26; i++) sum[i] = 0; } return 0; }
#include <bits/stdc++.h> using namespace std; long long a, b, c, d, e, f, g, n, m, k; int main() { ios_base::sync_with_stdio(false); cin >> n; while (n--) { cin >> a >> b; vector<int> v(b); string str; cin >> str; for (int i = 0; i < b; i++) cin >> v[i]; v.push_back(a); int arr[26][a]; for (int i = 0; i < 26; i++) { for (int j = 0; j < a; j++) arr[i][j] = 0; } arr[str[0] - 'a'][0] = 1; for (int j = 1; j < a; j++) { int ind = str[j] - 'a'; for (int i = 0; i < 26; i++) { arr[i][j] = arr[i][j - 1]; } arr[ind][j]++; } vector<long long> answer(26, 0); for (int i = 0; i <= b; i++) { for (int j = 0; j < 26; j++) { answer[j] += arr[j][v[i] - 1]; } } for (int i = 0; i < answer.size(); i++) { cout << answer[i] << " "; } cout << endl; ; } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; const long long mod = 1e9 + 7; long long sum[maxn][26], cnt[26]; char s[maxn]; int main() { int n, x, T, y; cin >> T; while (T--) { scanf("%d%d", &n, &x); scanf("%s", s + 1); for (int i = 0; i < 26; i++) cnt[i] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < 26; j++) { sum[i][j] = sum[i - 1][j]; } sum[i][s[i] - 'a']++; } for (int i = 0; i <= x; i++) { if (i == x) y = n; else scanf("%d", &y); for (int j = 0; j < 26; j++) { cnt[j] += sum[y][j]; } } for (int i = 0; i < 26; i++) cout << cnt[i] << " "; cout << endl; } }
#include <bits/stdc++.h> using namespace std; long long int mex(long long int a, long long int b, long long int m) { if (b == 0) return 1; if (b % 2) return a * mex((a * a) % m, (b - 1) / 2, m) % m; else return mex((a * a) % m, b / 2, m); } int x, y; void exteu(long long int a, long long int m) { if (m == 0) { x = 1; y = 0; } else { exteu(m, a % m); long long int temp = x; x = y; y = temp - (a / m) * y; } } long long int fact(long long int n) { long long int prod = 1; for (long long int i = 2; i <= n; i++) { prod *= i; } return prod; } long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } bool isprime[200001]; void makesieve() { memset(isprime, true, sizeof(isprime)); for (int i = 2; i <= sqrt(200000); ++i) { if (isprime[i]) { for (int j = i * i; j <= 200000; j += i) { isprime[j] = false; } } } } void solve() { int n, m; cin >> n >> m; string s; cin >> s; vector<int> p(m); for (long long int i = 0; i < m; i++) cin >> p[i]; vector<int> hash(26, 0); sort(p.begin(), p.end()); int ind = 0; for (int i = 0; i < n; ++i) { hash[s[i] - 'a'] += m - ind + 1; while (ind < m && i == p[ind] - 1) ind++; } for (long long int i = 0; i < 26; i++) cout << hash[i] << " "; cout << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int TESTS = 1; cin >> TESTS; while (TESTS--) { solve(); } 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; int 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, n, m; cin >> t; while (t--) { cin >> n >> m; string s; cin >> s; vector<int> pos(m); for (int i = 0; i < m; i++) cin >> pos[i]; long long dp[n + 1][26]; for (int i = 0; i < 26; i++) dp[0][i] = 0; for (int i = 1; i < n + 1; i++) { for (int j = 0; j < 26; j++) dp[i][j] = dp[i - 1][j]; dp[i][s[i - 1] - 'a']++; } vector<long long> ans(26); for (int i = 0; i < m; i++) { int x = pos[i]; for (int j = 0; j < 26; j++) { ans[j] += dp[x][j]; } } for (int i = 0; i < 26; i++) ans[i] += dp[n][i]; for (int i = 0; i < 26; i++) cout << ans[i] << " "; } return 0; }
#include <bits/stdc++.h> using namespace std; template <class A> void read(vector<A> &v); template <class A, size_t S> void read(array<A, S> &a); template <class T> void read(T &x) { cin >> x; } void read(double &d) { string t; read(t); d = stod(t); } void read(long double &d) { string t; read(t); d = stold(t); } template <class H, class... T> void read(H &h, T &...t) { read(h); read(t...); } template <class A> void read(vector<A> &x) { for (auto &a : x) read(a); } template <class A, size_t S> void read(array<A, S> &x) { for (auto &a : x) read(a); } string to_string(char c) { return string(1, c); } string to_string(bool b) { return b ? "yes" : "no"; } string to_string(const char *s) { return string(s); } string to_string(string s) { return s; } string to_string(vector<bool> v) { string res; for (int i = (0); (1) > 0 ? i < ((int)(v).size()) : i > ((int)(v).size()); i += (1)) res += char('0' + v[i]); return res; } template <size_t S> string to_string(bitset<S> b) { string res; for (int i = (0); (1) > 0 ? i < (S) : i > (S); i += (1)) res += char('0' + b[i]); return res; } template <class T> string to_string(T v) { bool f = 1; string res; for (auto &x : v) { if (!f) res += ' '; f = 0; res += to_string(x); } return res; } template <class A> void write(A x) { cout << to_string(x) << " "; } template <class H, class... T> void write(const H &h, const T &...t) { write(h); write(t...); } void print() { cout << ("\n"); } template <class H, class... T> void print(const H &h, const T &...t) { write(h); if (sizeof...(t)) write(' '); print(t...); } void deb() { cerr << endl; } template <typename Head, typename... Tail> void deb(Head H, Tail... T) { cerr << to_string(H) << " "; deb(T...); } using ll = long long; pair<const int, const int> dxdy[4] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}}; void solve() { int n, m; string s; read(n, m, s); vector<int> a(m); read(a); vector<int> fr(n + 1); for (int i = (0); (1) > 0 ? i < (m) : i > (m); i += (1)) { fr[a[i] - 1]++; } for (int i = n - 1; i >= 1; --i) { fr[i - 1] += fr[i]; } vector<int> ans(26, 0); for (int i = (0); (1) > 0 ? i < (n) : i > (n); i += (1)) { ans[s[i] - 'a'] += fr[i] + 1; } write(ans); print(); } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int tc = 1; cin >> tc; for (int i = (0); (1) > 0 ? i < (tc) : i > (tc); i += (1)) { solve(); } }
#include <bits/stdc++.h> using namespace std; int32_t main() { int tt = 1; cin >> tt; while (tt--) { int n, m; cin >> n >> m; int a[200000]; string s; cin >> s; for (int i = 0; i < m; i++) cin >> a[i]; int ans[26] = {0}; vector<int> v(26, 0); for (auto x : s) ans[x - 'a']++; map<int, vector<int>> mm; for (int i = 0; i < n; i++) { v[s[i] - 'a']++; mm[i + 1] = v; } for (int i = 0; i < m; i++) { for (int j = 0; j < 26; j++) ans[j] += mm[a[i]][j]; } for (auto x : ans) cout << x << " "; cout << endl; } }
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base ::sync_with_stdio(false); cin.tie(0); long long t; cin >> t; while (t--) { long long n, m; string s; cin >> n >> m >> s; vector<long long> pref(n); for (long long i = 0, p; i < m; ++i) { cin >> p; ++pref[p - 1]; } for (long long i = n - 1; i > 0; --i) { pref[i - 1] += pref[i]; } vector<long long> ans(26); for (long long i = 0; i < n; ++i) { ans[s[i] - 'a'] += pref[i]; ++ans[s[i] - 'a']; } for (long long i = 0; i < 26; ++i) { cout << ans[i] << " "; } cout << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int s[30][N], res[30]; char ch[N]; signed main() { int t; scanf("%d", &t); while (t--) { int n, m; scanf("%d %d", &n, &m); scanf("%s", ch + 1); memset(res, 0, sizeof(res)); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= 26; ++j) s[j][i] = s[j][i - 1]; ++s[ch[i] - 'a' + 1][i]; } for (int i = 1, x; i <= m; ++i) { scanf("%d", &x); for (int j = 1; j <= 26; ++j) res[j] += s[j][x]; } for (int i = 1; i <= 26; ++i) printf("%d ", res[i] + s[i][n]); puts(""); } return 0; }
#include <bits/stdc++.h> using namespace std; int mod = 1000000007; int32_t main() { long long int t; cin >> t; while (t--) { long long int n, m; cin >> n >> m; string s; cin >> s; vector<long long int> v(n, 0); for (long long int i = 0; i < m; i++) { long long int x; cin >> x; x--; v[x] += 1; } v[n - 1] += 1; for (long long int i = n - 2; i >= 0; i--) v[i] = v[i] + v[i + 1]; vector<long long int> ans(26, 0); for (long long int i = 0; i < n; i++) { ans[s[i] - 97] += v[i]; } for (long long int i = 0; i < 26; i++) cout << ans[i] << " "; cout << endl; } }
#include <bits/stdc++.h> using namespace std; int t, n, m, p; int main() { cin >> t; while (t--) { cin >> n >> m; int a[26] = {0}, len; string s; cin >> s; len = s.size(); vector<long long> v(len + 1, 0); v[0] = 1; for (int i = 0; i < m; i++) cin >> p, v[0]++, v[p]--; a[s[0] - 'a'] += v[0]; for (int i = 1; i < len; i++) { v[i] += v[i - 1]; a[s[i] - 'a'] += v[i]; } for (int i = 0; i < 26; i++) cout << a[i] << " "; cout << endl; } }
#include <bits/stdc++.h> using namespace std; int t, n, m, num[27], ans[27], vis[200005]; char str[200005]; void deal() { cin >> n >> m; char c = getchar(); while (c != '\n') c = getchar(); for (int i = 1; i <= n; i++) str[i] = getchar(); memset(vis, 0, sizeof(vis)); for (int i = 1; i <= m; i++) { int p; cin >> p; vis[p]++; } memset(num, 0, sizeof(num)); memset(ans, 0, sizeof(ans)); for (int i = 1; i <= n; i++) { num[int(str[i] - 'a') + 1]++; for (int j = 1; j <= 26; j++) { ans[j] += num[j] * vis[i]; } ans[int(str[i] - 'a') + 1]++; } for (int i = 1; i <= 26; i++) printf("%d ", ans[i]); printf("\n"); return; } int main() { cin >> t; for (int i = 1; i <= t; i++) deal(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); ; int t, m, n; string s; cin >> t; while (t--) { cin >> n >> m >> s; int a[m], cnt[26]; memset(cnt, 0, sizeof(cnt)); for (long long i = 0; i < m; i++) cin >> a[i]; sort(a, a + m); for (long long i = 0; i < n; i++) { cnt[s[i] - 'a'] += m - (lower_bound(a, a + m, i + 1) - a) + 1; } for (long long i = 0; i < 26; i++) cout << cnt[i] << ' '; cout << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; void GO_GO_GO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void BYE_BYE() { cerr << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; } bool primeArr[1000001] = {false}; long long int fact[1000001]; long long int lazy[1000001] = {0}; long long int BIT[1000001] = {0}; vector<long long int> primes; int main() { GO_GO_GO(); long long int t = 1; cin >> t; while (t--) { long long int i = 0, j = 0; long long int n, m; cin >> n >> m; string s; cin >> s; vector<long long int> v(m); for (i = 0; i < m; i++) { cin >> v[i]; v[i]--; } vector<long long int> temp(n + 1, 0); vector<long long int> ans(26, 0); for (i = 0; i < m; i++) { temp[v[i] + 1]--; temp[0]++; } for (i = 1; i < n + 1; i++) { temp[i] += temp[i - 1]; } for (i = 0; i < n; i++) { ans[s[i] - 'a'] += temp[i] + 1; } for (i = 0; i < 26; i++) cout << ans[i] << " "; cout << "\n"; } BYE_BYE(); return 0; }
#include <bits/stdc++.h> using namespace std; mt19937_64 rang( chrono::high_resolution_clock::now().time_since_epoch().count()); long long int rng(long long int lim) { uniform_int_distribution<long long int> uid(0, lim - 1); return uid(rang); } long long int mpow(long long int base, long long int exp); void ipgraph(long long int n, long long int m); void dfs(long long int u, long long int par); void solve() { long long int n, m; string s; cin >> n >> m >> s; vector<long long int> pref(n); for (long long int i = 0; i < m; ++i) { long long int p; cin >> p; ++pref[p - 1]; } for (long long int i = n - 1; i > 0; --i) { pref[i - 1] += pref[i]; } vector<long long int> ans(26); for (long long int i = 0; i < n; ++i) { ans[s[i] - 'a'] += pref[i]; ++ans[s[i] - 'a']; } for (long long int i = 0; i < 26; ++i) { cout << ans[i] << " "; } cout << "\n"; } signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); long long int t = 1; cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; long long int arr[27]; long long int arrtest[200005]; int main() { long long int test; cin >> test; for (long long int z = 0; z < test; z++) { string reqst; long long int n, m; cin >> n >> m; cin >> reqst; for (long long int i = 0; i < 26; i++) { arr[i] = 0; } for (long long int i = 0; i <= n; i++) { arrtest[i] = 0; } for (long long int i = 0; i < m; i++) { long long int temp; cin >> temp; arrtest[temp] += 1; } arrtest[n] = 1; long long int counter = 0; for (long long int j = n; j > 0; j--) { counter += arrtest[j]; arr[((int)reqst[j - 1] - (int)'a')] += counter; } for (long long int i = 0; i < 26; i++) { cout << arr[i] << " "; } cout << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { long t; cin >> t; while (t--) { long n, m; string s; cin >> n >> m; cin >> s; vector<long> pre(n + 3, 0); for (int i = 1; i <= m; i++) { long x; cin >> x; pre[x]++; } for (int i = n; i >= 1; i--) pre[i - 1] += pre[i]; s = '&' + s; vector<long> re(35, 0); for (int i = 1; i < s.size(); i++) { re[s[i] - 'a'] += pre[i] + 1; } for (int i = 0; i < 26; i++) cout << re[i] << " "; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; void printvec(std::vector<long long> v) { long long n = v.size(); for (long long i = 0; i < n; i++) cout << v[i] << " "; cout << endl; } long long mod = 1e9 + 7; long long power(long long x, unsigned long long y) { long long temp; if (y == 0) return 1; temp = power(x, y / 2); if (y % 2 == 0) return temp * temp; else return x * temp * temp; } long long binarySearch(vector<long long> arr, long long l, long long r, long long x) { if (r >= l) { long long mid = l + (r - l) / 2; if (arr[mid] == x) return mid; if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x); return binarySearch(arr, mid + 1, r, x); } return -1; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int T = 1; cin >> T; while (T--) { long long n, m; cin >> n >> m; string s; cin >> s; std::vector<long long> p(m); for (long long i = 0; i < m; i++) cin >> p[i]; std::vector<long long> v(n, 0); for (long long i = 0; i < m; i++) { v[p[i] - 1]++; } for (long long i = n - 1; i > 0; i--) { v[i - 1] = v[i - 1] + v[i]; } for (long long i = 0; i < n; i++) { v[i]++; } std::vector<long long> ans(26, 0); for (long long i = 0; i < n; i++) { ans[((int)(s[i]) - 97)] += v[i]; } for (long long i = 0; i < 26; i++) { cout << ans[i] << " "; } cout << endl; } }
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long base = 1e9 + 7; const long long oo = 1e6 + 10; const long long gh = 1e3 + 3; const long long inf = 1e15 + 5; long long n, m, k, q; long long a[oo]; long long b[oo]; long long sum[oo]; string s; char c[oo]; void input() { long long x, y, z; cin >> n >> m; cin >> s; for (long long i = 0; i <= 30; i++) sum[i] = b[i] = 0; for (long long i = 1; i <= m; i++) cin >> a[i]; sort(a + 1, a + m + 1); long long j = 0; a[m + 1] = n; for (long long i = 1; i <= m + 1; i++) { while (j < a[i]) { long long t = s[j] - 'a'; b[t]++; j++; } for (long long j = 0; j <= 26; j++) { sum[j] += b[j]; } } for (long long j = 0; j < 26; j++) cout << sum[j] << " "; cout << endl; } void cre() {} void solve() { cre(); } void ouput() {} int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (ifstream("test.txt")) { freopen("test.txt", "r", stdin); } else if (ifstream("" ".inp")) { freopen( "" ".inp", "r", stdin); freopen( "" ".out", "w", stdout); } long long t = 1; cin >> t; while (t--) { input(); solve(); ouput(); } }
#include <bits/stdc++.h> using namespace std; const int MAXN = 40; int pos[MAXN]; const int maxn = 2 * 1e5 + 5; int a[MAXN]; int chars[maxn][27]; int main() { int t; cin >> t; while (t--) { int n; int m; cin >> n >> m; string ss; cin >> ss; for (int y = 1; y <= n; y++) { for (int j = 1; j <= 26; j++) { chars[y][j] = chars[y - 1][j]; if (ss[y - 1] - 'a' + 1 == j) chars[y][j] += 1; } } memset(pos, 0, sizeof(pos)); for (int y = 1; y <= m + 1; y++) { int ds; if (y == m + 1) ds = n; else cin >> ds; for (int y = 1; y <= 26; y++) { pos[y] += chars[ds][y]; } } for (int y = 1; y <= 26; y++) { cout << pos[y] << ' '; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int cnt[1000000 + 1]; const int mod = 998244353; void solve() { int n, m; cin >> n >> m; string s; cin >> s; int a[m]; memset(cnt, 0, sizeof(cnt)); for (int i = 0; i < m; i++) { cin >> a[i]; cnt[a[i]]++; } int mx = *max_element(a, a + m); cnt[mx]++; for (int i = mx - 1; i >= 0; i--) { cnt[i] = cnt[i + 1] + cnt[i]; } for (int i = mx + 1; i <= n; i++) cnt[i] = 1; map<char, int> ma; for (int i = 0; i < n; i++) { ma[s[i]] += cnt[i + 1]; } for (char i = 'a'; i <= 'z'; i++) { cout << ma[i] << " "; } cout << endl; } 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> using namespace std; long long cnt[200000]; 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; memset(cnt, 0, sizeof(cnt)); long long ans[26] = {}; string s; cin >> s; int temp; for (int i = 0; i < m; ++i) { cin >> temp; cnt[temp - 1]++; } 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 (int a : ans) { cout << a << ' '; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t, n, k, x, rise; string s; cin >> t; while (t--) { rise = 0; cin >> n >> k >> s; vector<int> cnt(n, 0), rep(n, 1), mark(26, 0); for (int i = 0; i < k; i++) { cin >> x; cnt[x - 1]++; } for (int i = n - 1; i >= 0; i--) { rise += cnt[i]; rep[i] += rise; } for (int i = 0; i < n; i++) { mark[(int)s[i] - (int)'a'] += rep[i]; } for (auto lol : mark) cout << lol << " "; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int n, m, p[200005], al[27], cm = 0, a, init; string s; cin >> n >> m; for (int j = 0; j < 27; j++) al[j] = 0; for (int j = 0; j < n; j++) p[j] = 0; cin >> s; for (int j = 0; j < m; j++) { cin >> a; p[a - 1]++; } for (int j = 0; j < n; j++) { init = s[j] - 97; al[init] += m - cm + 1; if (p[j] > 0) cm += p[j]; } for (int j = 0; j < 26; j++) cout << al[j] << " "; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> prefix[30]; int main() { ios_base::sync_with_stdio(false); int test; cin >> test; while (test--) { int n, m; string s; cin >> n >> m >> s; for (char c = 'a'; c <= 'z'; c++) { prefix[c - 'a'] = vector<int>(n + 1); for (int i = 1; i <= n; i++) { prefix[c - 'a'][i] = prefix[c - 'a'][i - 1] + (s[i - 1] == c); } } vector<int> p(m), ans(30); for (int i = 0; i < m; i++) { cin >> p[i]; for (char c = 'a'; c <= 'z'; c++) { ans[c - 'a'] += prefix[c - 'a'][p[i]]; } } for (int i = 0; i < n; i++) { ans[s[i] - 'a']++; } for (int i = 0; i < 26; i++) cout << ans[i] << " "; cout << endl; for (int i = 0; i < 26; i++) prefix[i].clear(); } }
#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...); } void solve() { long long int n, m; cin >> n >> m; long long int pre[n][26]; for (long long int i = 0; i < n; i++) { for (long long int j = 0; j < 26; j++) { pre[i][j] = 0; } } string s; cin >> s; long long int arr[m]; for (long long int i = 0; i < m; i++) cin >> arr[i]; for (long long int i = 0; i < s.length(); i++) { long long int ind = s[i] - 'a'; pre[i][ind]++; } for (long long int i = 1; i < n; i++) { for (long long int j = 0; j < 26; j++) { pre[i][j] += pre[i - 1][j]; } } long long int cnt[26]; for (long long int i = 0; i < 26; i++) cnt[i] = 0; for (long long int i = 0; i < m; i++) { long long int key = arr[i]; key--; for (long long int j = 0; j < 26; j++) { cnt[j] += pre[key][j]; } } for (long long int j = 0; j < 26; j++) { cnt[j] += pre[n - 1][j]; } for (long long int i = 0; i < 26; i++) cout << cnt[i] << " "; cout << endl; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long int t = 1; cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n, m; cin >> n >> m; string s; cin >> s; long long arr[m]; for (auto &x : arr) { cin >> x; } long long cs[n]; for (auto &x : cs) { x = 0; } for (auto x : arr) { cs[x - 1]++; } long long ch[26]; long long carry = cs[n - 1]; for (int x = n - 2; x >= 0; x--) { carry += cs[x]; cs[x] = carry; } for (auto &x : ch) x = 0; for (int x = 0; x < n; x++) { ch[s[x] - 'a'] += cs[x]; ch[s[x] - 'a']++; } for (auto x : ch) { cout << x << " "; } cout << endl; } }
#include <bits/stdc++.h> using namespace std; const long int myx = 1e5 + 1; void solve() { long long n, m, temp; string s; cin >> n >> m >> s; vector<long long> cnt(26, 0); map<long long, int> mp; mp[0] = 1; mp[n] = 1; for (int i = 0; i < m; ++i) { cin >> temp; mp[temp]++; } vector<vector<int>> v(mp.size(), vector<int>(2, 0)); int ct = 1; temp = m; auto itr = mp.begin(); v[0][0] = itr->first; v[0][1] = itr->second; advance(itr, 1); int t2 = 0; for (; itr != mp.end(); ++itr, ct++) { v[ct][0] = itr->first; v[ct][1] = m - t2 + 1; t2 += itr->second; } for (int i = 1; i < v.size(); ++i) { int k = v[i][1]; for (int j = v[i - 1][0]; j < v[i][0]; ++j) { cnt[s[j] - 'a'] += k; } } for (auto i : cnt) cout << i << " "; cout << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; for (long long int i = 0; i < t; i++) { long long int v[26] = {0}; string s; long long int n, m; cin >> n >> m; cin >> s; vector<int> x; for (long long int j = 0; j < m; j++) { long long int y; cin >> y; x.push_back(y); } sort(x.begin(), x.end()); long long int q = m; long long int count = 0; long long int j = 0; while (q > 0) { lb: if (j < x[count]) { v[s[j] - 97] += q; j++; goto lb; } q--; count++; } for (long long int j = 0; j < n; j++) { v[s[j] - 97]++; } for (long long int j = 0; j < 26; j++) { cout << v[j] << " "; } cout << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int alph[26] = {0}; int n, m; cin >> n >> m; string s; cin >> s; vector<int> mistakes(n + 1, 0); for (int i = 0; i < m; i++) { int a; cin >> a; mistakes[a]--; mistakes[0]++; } mistakes[0]++; alph[s[0] - 'a'] += mistakes[0]; for (int i = 1; i < n; i++) { mistakes[i] += mistakes[i - 1]; alph[s[i] - 'a'] += mistakes[i]; } for (int i = 0; i < 26; i++) { cout << alph[i] << " "; } cout << endl; } }
#include <bits/stdc++.h> using namespace std; const int NN = 1e6; char s[NN]; int p[NN]; int main() { int t; cin >> t; int n, m; int arr[26]; while (t--) { scanf("%d%d", &n, &m); scanf("%s", s); for (int i = 0; i < m; i++) scanf("%d", &p[i]); sort(p, p + m); memset(arr, 0, sizeof(arr)); for (int i = 0; i < n; i++) { int x = lower_bound(p, p + m, i + 1) - p; arr[s[i] - 'a'] += m - x + 1; } for (int i = 0; i < 26; i++) printf("%d ", arr[i]); printf("\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; long long tot[28], arr[300007][28], prr[300007]; int main() { long long test, n, m; string s; cin >> test; while (test--) { cin >> n >> m; cin >> s; for (int i = 0; i <= n + 10; ++i) { for (int j = 0; j < 27; ++j) { arr[i][j] = 0; } } for (int i = 0; i < 27; ++i) tot[i] = 0; for (int i = 0; i < m; ++i) cin >> prr[i]; for (int i = 0; i < n; ++i) { tot[s[i] - 'a']++; for (int j = 0; j < 26; ++j) { arr[i][j] = tot[j]; } } prr[m] = n; for (int i = 0; i < 27; ++i) tot[i] = 0; for (int i = 0; i <= m; ++i) { for (int j = 0; j < 26; ++j) { tot[j] += arr[prr[i] - 1][j]; } } for (int j = 0; j < 26; ++j) cout << tot[j] << " "; } return 0; }
#include <bits/stdc++.h> using namespace std; vector<long long> pr; signed main() { long long t; cin >> t; for (long long u = 0; u < t; u++) { long long n, m; cin >> n >> m; string s; cin >> s; vector<long long> o(m), ans(26, 0), pok(n, 1); for (long long i = 0; i < m; i++) { cin >> o[i]; o[i]--; } sort(o.begin(), o.end()); long long ind = 0, ko = m; for (long long i = 0; i < n; i++) { pok[i] += ko; while (o[ind] == i) { ko--; ind++; } if (ko == 0) { break; } } for (long long i = 0; i < n; i++) { ans[int(s[i]) - 97] += pok[i]; } for (long long i = 0; i < 26; i++) { cout << ans[i] << ' '; } cout << '\n'; } }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int a[N]; int b[N]; long long ans[28]; char s[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; cin >> (s + 1); memset(b, 0, sizeof b); memset(ans, 0, sizeof ans); memset(a, 0, sizeof a); for (int i = 0; i < m; i++) { cin >> b[i]; } for (int i = 0; i < m; i++) { a[b[i]]++; } int cnt = 0; for (int i = 1; i <= n; i++) { int u = s[i] - 'a'; ans[u] += m - cnt; cnt += a[i]; } for (int i = 1; i <= n; i++) { ans[s[i] - 'a']++; } for (int i = 0; i < 26; i++) { if (i) cout << " "; cout << ans[i]; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> initializeDiffArray(vector<int>& A) { int n = A.size(); vector<int> D(n + 1); D[0] = A[0], D[n] = 0; for (int i = 1; i < n; i++) D[i] = A[i] - A[i - 1]; return D; } void update(vector<int>& D, int l, int r, int x) { D[l] += x; D[r + 1] -= x; } vector<int> printArray(vector<int>& A, vector<int>& D) { vector<int> res; for (int i = 0; i < A.size(); i++) { if (i == 0) A[i] = D[i]; else A[i] = D[i] + A[i - 1]; res.push_back(A[i]); } return res; } void test() { int n, m; cin >> n >> m; string s; cin >> s; int p[m]; for (int i = 0; i < m; i++) cin >> p[i]; vector<int> A(n); for (int i = 0; i < n; i++) A[i] = 1; vector<int> D = initializeDiffArray(A); for (int i = 0; i < m; i++) { update(D, 0, p[i] - 1, 1); } vector<int> res = printArray(A, D); int x[26]; for (int i = 0; i < 26; i++) x[i] = 0; for (int i = 0; i < n; i++) { x[s[i] - 'a'] += res[i]; } for (int i = 0; i < 26; i++) cout << x[i] << " "; cout << "\n"; } int main() { int t = 1; cin >> t; while (t--) { test(); } }
#include <bits/stdc++.h> using namespace std; const int Maxn = 1e5 + 1, Mod = 1e9 + 7; bool sortByVal(const pair<pair<long, long>, double> &a, const pair<pair<long, long>, double> &b) { return (a.second < b.second); } int binaryToDecimal(int n) { int num = n; int dec_value = 0; int base = 1; int temp = num; while (temp) { int last_digit = temp % 10; temp = temp / 10; dec_value += last_digit * base; base = base * 2; } return dec_value; } long long power(long long n, long long r) { if (r == 0) { return 1; } if (r == 1) return n; return (power(n, r / 2) % Mod * power(n, r - (r / 2)) % Mod) % Mod; } template <typename T, typename T1> T mod(T x, T1 p) { x %= p; if (x < 0) x += p; return x; } template <typename T> T inverse(T x, T p) { x = mod(x, p); if (x == 1) return x; return mod(1LL * (-p / x) * (inverse(p % x, p)), p); } bool primeCheck(int n) { if (n == 2 || n == 3 || n == 5) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i += 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } 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); cout.tie(NULL); long long t; t = 1; cin >> t; while (t--) { long long n, m; cin >> n >> m; string s; cin >> s; map<char, long long> mp; std::vector<long long> v(m); long long sum = 0; for (auto &x : v) cin >> x; sort(v.begin(), v.end()); int k = 0; for (int i = 0; i < s.length(); i++) { mp[s[i]]++; if (k >= m || i + 1 <= v[k]) { mp[s[i]] += m - k; } else { while (k < m && i + 1 > v[k]) { k++; } if (k > m) k = m; mp[s[i]] += (m - k); } } int a[26] = {0}; for (auto x : mp) a[x.first - 'a'] = x.second; for (int i = 0; i < 26; i++) cout << a[i] << " "; cout << "\n"; } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimization("unroll-loops") using namespace std; const long long INF = 998244353; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; string s; cin >> s; vector<int> a(n + 1); map<char, int> mp; for (auto &i : s) mp[i]++; for (int i = 0; i < m; i++) { int x; cin >> x; a[0] += 1; if (x < n) a[x] -= 1; } int t = 0; for (int i = 0; i < n; i++) { a[i] += t; t = a[i]; } for (int i = 0; i < n; i++) mp[s[i]] += a[i]; for (char i = 'a'; i <= 'z'; i++) cout << mp[i] << " "; cout << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; long long i, j, k, t, n, q, l, r, mid; long long arr[30]; long long x, m; string s; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> t; while (t--) { memset(arr, 0, sizeof(arr)); cin >> n >> m; long long mp[n + 3]; memset(mp, 0, sizeof(mp)); cin >> s; s = '@' + s; for (long long i = 1; i < m + 1; i++) { cin >> x; mp[1]++; mp[x + 1]--; } for (long long i = 1; i < n + 1; i++) { mp[i] += mp[i - 1]; arr[s[i] - 'a'] += mp[i] + 1; } for (long long i = 0; i < 26; i++) { cout << arr[i] << " "; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const long long mod = 1e9 + 7; long long ans[30], vis[30]; map<int, int> mp; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int T; cin >> T; while (T--) { for (int i = 0; i < 26; i++) vis[i] = ans[i] = 0; int n, m; cin >> n >> m; string s; cin >> s; mp.clear(); for (int i = 0; i < m; i++) { int x; cin >> x; mp[x] += 1; } for (int i = 0; i < s.size(); i++) { ans[s[i] - 'a']++; vis[s[i] - 'a']++; if (mp[i + 1]) { for (int j = 0; j < 26; j++) { ans[j] += vis[j] * mp[i + 1]; } } } for (int i = 0; i < 26; i++) cout << ans[i] << ' '; cout << 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][strlen(s + 1)]; for (register int i = 0; i < 25; ++i) printf("%lld ", ans[i]); printf("%lld\n", ans[25]); } }
#include <bits/stdc++.h> using namespace std; long long a[200005], b[200005]; int main() { long long t, n, m, c[30], i, d, e; cin >> t; string s; while (t--) { cin >> n >> m; cin >> s; for (i = 0; i < m; i++) cin >> a[i]; sort(a, a + m); d = a[m - 1]; for (i = 1; i <= n; i++) b[i] = 1; long long j = 1, k; for (i = m - 2; i >= 0; i--) { if (a[i] != a[i + 1]) { e = a[i]; for (k = d; k > e; k--) { b[k] = b[k] + j; } d = e; } j++; } for (i = 1; i <= d; i++) { b[i] += j; } memset(c, 0, sizeof(c)); for (i = 0; i < n; i++) { char cc = s[i] - 'a'; int dd = cc + 1; c[dd] += b[i + 1]; } for (i = 1; i <= 26; i++) cout << c[i] << " "; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long t, m, p, data; cin >> t; while (t--) { cin >> m >> p; string s; cin >> s; int arr[26] = {0}; vector<long long> v; for (int i = 0; i < p; i++) { cin >> data; v.push_back(data); } sort(v.begin(), v.end()); ; int temp = 1; for (int i = 0; i < s.length(); i++) { arr[s[i] - 'a'] += 1; } for (long long j = v.size() - 1; j > 0; j--) { for (long long i = v[j] - 1; i > v[j - 1] - 1; i--) arr[s[i] - 'a'] += temp; temp++; } for (long long i = v[0] - 1; i >= 0; i--) { arr[s[i] - 'a'] += temp; } for (int i = 0; i < 26; i++) { cout << arr[i] << " "; } cout << '\n'; v.clear(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int test; cin >> test; while (test--) { int n, m; cin >> n >> m; string S; cin >> S; vector<int> P(m); vector<int> cnt(n); for (int i = 0; i < m; i++) { cin >> P[i]; cnt[0]++; cnt[P[i]]--; } vector<int> res(26); for (int i = 0; i < n; i++) res[S[i] - 'a']++; res[S[0] - 'a'] += cnt[0]; for (int i = 1; i < n; i++) { cnt[i] += cnt[i - 1]; res[S[i] - 'a'] += cnt[i]; } for (int i = 0; i < 26; i++) cout << res[i] << " " << flush; cout << endl; } return 0; }
#include <bits/stdc++.h> 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; string s; cin >> s; int arr[m]; for (int i = 0; i < m; i++) { cin >> arr[i]; arr[i] = arr[i] - 1; } int cnt[26]; memset(cnt, 0, sizeof(cnt)); int cod[n][26]; memset(cod, 0, sizeof(cod)); for (int i = 0; i < n; i++) { cod[i][s[i] - 97]++; if (i > 0) { for (int j = 0; j < 26; j++) { cod[i][j] = cod[i - 1][j]; } cod[i][s[i] - 97]++; } } for (int i = 0; i < m; i++) { for (int j = 0; j < 26; j++) cnt[j] += cod[arr[i]][j]; } for (int i = 0; i < n; i++) cnt[s[i] - 97]++; for (int i = 0; i < 26; i++) cout << cnt[i] << " "; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using int64 = long long; template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; } template <class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; } template <class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; } template <class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; } template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; } void debug_out() { std::cerr << '\n'; } template <class Head, class... Tail> void debug_out(Head&& head, Tail&&... tail) { std::cerr << head; if (sizeof...(Tail) != 0) std::cerr << ", "; debug_out(std::forward<Tail>(tail)...); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int q; cin >> q; auto solve = [](int n, int m, string& s, vector<int>& p) -> void { vector<vector<int>> cnt(26, vector<int>(n + 1, 0)); for (char i = 'a'; i <= 'z'; ++i) { for (int j = 1; j <= n; ++j) { cnt[i - 'a'][j] = cnt[i - 'a'][j - 1] + (s[j - 1] == i); } } vector<int> res(26, 0); for (int i = 0; i < m; ++i) { for (int j = 0; j < 26; ++j) { res[j] += cnt[j][p[i]]; } } for (int i = 0; i < n; ++i) { ++res[s[i] - 'a']; } for (int i = 0; i < 26; ++i) { cout << res[i] << " "; } cout << '\n'; return; }; for (int i = 0; i < q; ++i) { int n, m; cin >> n >> m; string s; cin >> s; vector<int> p(m); cin >> p; solve(n, m, s, p); } return 0; }
#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; vector<int> p(m); for (long long i = 0; i < (long long)m; i++) { int x; cin >> x; p[i] = x - 1; } sort(p.begin(), p.end()); vector<int> res(26); for (long long i = 0; i < (long long)n; i++) res[s[i] - 'a']++; for (long long i = 0; i < (long long)n; i++) { auto ind = lower_bound(p.begin(), p.end(), i); int idx = ind - p.begin(); res[s[i] - 'a'] += m - idx; } for (int i : res) cout << i << " "; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t, i, j, n, m, ind; cin >> t; while (t--) { int arr[26]; for (i = 0; i < 26; i++) { arr[i] = 0; } string str; vector<int> v; cin >> n >> m; cin >> str; for (i = 0; i < m; i++) { cin >> j; v.push_back(j); } std::sort(v.begin(), v.end(), std::greater<int>()); for (i = 0; i < n; i++) { j = i + 1; auto up = std::upper_bound(v.begin(), v.end(), j, std::greater<int>()); ind = up - v.begin(); arr[str[i] - 'a'] = arr[str[i] - 'a'] + ind; } for (i = 0; i < n; i++) { arr[str[i] - 'a'] = arr[str[i] - 'a'] + 1; } for (i = 0; i < 26; i++) { cout << arr[i] << " "; } cout << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int t; void abc() { int n, m, i, x; map<char, int> mp; string s; cin >> n >> m >> s; vector<int> p(m); for (i = 0; i < m; i++) cin >> p[i], p[i]--; sort(p.begin(), p.end()); for (i = 0; i < s.size(); i++) { x = lower_bound(p.begin(), p.end(), i) - p.begin(); mp[s[i]] += m - x + 1; } for (i = 0; i < 26; i++) cout << mp['a' + i] << " "; cout << "\n"; } int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> t; while (t--) abc(); return 0; }
#include <bits/stdc++.h> using namespace std; long long int n, m; void solve() { cin >> n >> m; string s; cin >> s; long long int a[26] = {0}; long long int z; vector<long long int> v(n, 0); for (long long int i = 0; i < m; i++) { cin >> z; z--; if (z == n - 1) { v[n - 1]--; } else { v[0]++; v[z + 1]--; } } a[s[0] - 'a'] += v[0] + 1; for (long long int i = 1; i < n; i++) { v[i] = v[i] + v[i - 1]; a[s[i] - 'a'] += v[i] + 1; } for (long long int i = 0; i < 26; i++) { cout << a[i] << " "; } cout << "\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int x; cin >> x; for (long long int i = 1; i <= x; i++) solve(); return 0; }
#include <bits/stdc++.h> int dx4[] = {0, 0, -1, 1}; int dy4[] = {-1, 1, 0, 0}; bool valid(int r, int c, int x, int y) { if (x >= 1 && x <= r && y >= 1 && y <= c) return 1; return 0; } using namespace std; int main() { int t; scanf("%d", &(t)); for (int cs = 1; cs <= t; cs++) { long long int n, m; scanf("%lld %lld", &(n), &(m)); long long int ans[n + 2]; long long int mp[30]; memset(ans, 0, sizeof(ans)); memset(mp, 0, sizeof(mp)); string s; cin >> s; long long int a[m + 2]; memset(a, 0, sizeof(a)); for (int i = 1; i <= m; i++) { scanf("%lld", &(a[i])); ans[1]++; ans[a[i] + 1]--; } ans[1]++; ans[n + 1]--; for (int i = 1; i <= n; i++) { ans[i] += ans[i - 1]; } for (int i = 0; i < n; i++) { int x = (int)s[i] - 97; mp[x] += ans[i + 1]; } for (int ch = 0; ch < 26; ch++) printf("%lld ", mp[ch]); printf("\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; char s[200001]; int a[200001], sum[26], b[26]; int main() { int t; scanf("%d", &t); while (t--) { int n, m, i, j = 0, k; char p; memset(a, 0, sizeof(a)); memset(sum, 0, sizeof(sum)); memset(s, 0, sizeof(s)); memset(b, 0, sizeof(b)); scanf("%d %d", &n, &m); scanf("%c", &p); scanf("%s", s); for (i = 0; i < m; i++) scanf("%d", &a[i]); sort(a, a + m); for (i = 0; i < n; i++) { sum[s[i] - 'a']++; while (a[j] == (i + 1)) { for (k = 0; k < 26; k++) { b[k] += sum[k]; } j++; } } for (i = 0; i < 26; i++) { sum[i] += b[i]; printf("%d ", sum[i]); } printf("\n"); } }
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC optimize("-ffloat-store") int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t, n, m; cin >> t; string s; while (t--) { cin >> n >> m >> s; vector<int> p(m), times(n, 0); times[0] = m + 1; for (auto &P : p) { cin >> P; times[P]--; } long long arr[26] = {0}; arr[s[0] - 'a'] += times[0]; for (int i = 1; i < n; i++) { times[i] += times[i - 1]; arr[s[i] - 'a'] += times[i]; } for (auto x : arr) cout << x << ' '; cout << '\n'; } return 0; }
#include <bits/stdc++.h> using std::cin; using std::cout; const int M = 2e5; void testcase(int n, int m) { std::string s; cin >> s; int alpha[26] = {0}, a[M + 1]; for (int i = 0; i < m; ++i) cin >> a[i]; std::sort(a, a + m); int i = 0, fromindex = 0, toindex, subamount = 0; while (i < m) { int j = i; while (a[j] == a[i]) ++j; toindex = a[i]; for (int i2 = fromindex; i2 < toindex; ++i2) alpha[s[i2] - 'a'] += (m - subamount); subamount += j - i; fromindex = toindex; i = j; } for (i = 0; i < n; ++i) alpha[s[i] - 'a']++; for (i = 0; i < 26; ++i) cout << alpha[i] << " "; cout << "\n"; } int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; testcase(n, m); } }
#include <bits/stdc++.h> using namespace std; long long t1, n, m, p[1000002], t[1000002], w[27]; string s; int main() { cin >> t1; for (int ii = 1; ii <= t1; ii++) { cin >> n >> m; cin >> s; for (int i = 1; i <= m; i++) cin >> p[i]; sort(p + 1, p + 1 + m); for (int i = 1; i <= m; i++) t[p[i]]++; for (int i = n; i >= 1; i--) t[i] = t[i + 1] + t[i]; for (int i = 1; i <= n; i++) t[i]++; for (int i = 0; i < s.size(); i++) w[s[i] - 'a'] += t[i + 1]; for (int i = 0; i < 26; i++) cout << w[i] << " "; cout << endl; for (int i = 1; i <= n + 1; i++) t[i] = 0; for (int i = 0; i < 26; i++) w[i] = 0; } }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int p[N]; int dp[N][26]; char s[N]; int n, m; int ans[26]; int main() { int t; scanf("%d", &t); while (t--) { scanf("%d%d", &n, &m); scanf(" %s", s + 1); for (int i = 0; i <= n; i++) { for (int j = 0; j < 26; j++) { dp[i][j] = 0; } } for (int i = 0; i < 26; i++) ans[i] = 0; for (int i = 0; i < m; i++) scanf("%d", p + i); for (int i = 1; i <= n; i++) { for (int j = 0; j < 26; j++) { dp[i][j] = dp[i - 1][j]; } dp[i][s[i] - 'a']++; ans[s[i] - 'a']++; } for (int i = 0; i < 26; i++) { for (int j = 0; j < m; j++) { ans[i] += dp[p[j]][i]; } } for (int i = 0; i < 25; i++) { printf("%d ", ans[i]); } printf("%d\n", ans[25]); } return 0; }
#include <bits/stdc++.h> const int maxn = 2e5 + 7; using namespace std; const long long mod = 998244353; const long double pi = 3.1415926535897932384626433832795; priority_queue<int, vector<int>, greater<int> > q; int a[maxn][28]; char s[maxn]; int ans[28]; int main() { int t, n, m, x; scanf("%d", &t); while (t--) { fill(ans, ans + 27, 0); scanf("%d %d", &n, &m); fill(a[0], a[0] + n * 27, 0); scanf("%s", s); 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][s[i] - 'a']++; } while (m--) { scanf("%d", &x); for (int i = 0; i < 26; i++) ans[i] += a[x - 1][i]; } for (int i = 0; i < 26; i++) ans[i] += a[n - 1][i]; for (int i = 0; i < 26; i++) printf(i == 25 ? "%d\n" : "%d ", ans[i]); } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100; char s[N]; int dp[N]; long long rep[30]; int main() { int t; cin >> t; while (t--) { int n, m; scanf("%d%d", &n, &m); scanf("%s", s + 1); for (int i = 0; i <= n; i++) { dp[i] = 0; } memset(rep, 0, sizeof rep); int p; for (int i = 0; i < m; i++) { scanf("%d", &p); dp[p + 1]--; } dp[0] = m + 1; for (int i = 1; i <= n; i++) { dp[i] += dp[i - 1]; rep[s[i] - 'a'] += dp[i]; } for (int i = 0; i < 26; i++) { printf("%lld ", rep[i]); } printf("\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; int ans[27]; int a[200005]; int b[6]; bool cmp(int x, int y) { return x < y; } int main() { int t; cin >> t; int n, m; while (t--) { memset(ans, 0, sizeof(ans)); cin >> n >> m; string s; cin >> s; for (int i = 0; i < m; i++) { cin >> a[i]; } sort(a, a + m, cmp); for (int i = 0; i < n; i++) { int pos = lower_bound(a, a + m, i + 1) - a; ans[s[i] - 'a'] += m + 1 - pos; } for (int i = 0; i < 26; i++) cout << ans[i] << " "; cout << endl; for (int i = 1; i < 5; i++) b[i] = 1; } }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; const int N = 2e5 + 1e2; int t, n, m, l[N]; map<char, int> x; string s; int main() { cin >> t; while (t--) { x.clear(); cin >> n >> m >> s; for (int i = 0; i < m; ++i) cin >> l[i]; sort(l, l + m); for (int i = 0; i < l[0]; ++i) x[s[i]] += m; for (int i = 0; i < m - 1; i++) { for (int k = l[i]; k < l[i + 1]; ++k) { x[s[k]] += m - i - 1; } } for (int i = 0; i < n; ++i) x[s[i]]++; for (char i = 'a'; i <= 'z'; ++i) cout << x[i] << " "; cout << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int tc; scanf("%d", &tc); while (tc--) { int n, k; scanf("%d %d", &n, &k); char ar[n + 1]; scanf("%s", ar); vector<int> ans(26, 0), mis(n + 1, 0); for (int i = 0; i < k; 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; void solve() { int n, m; string s; cin >> n >> m >> s; vector<int> miss(m), cnt(26); for (int& i : miss) { cin >> i; } sort(miss.begin(), miss.end()); for (int i = 0, c; i < s.size(); i++) { c = s[i] - 97; cnt[c]++; int ub = upper_bound(miss.begin(), miss.end(), i) - miss.begin(); cnt[c] += m - ub; } for (int i : cnt) cout << i << " "; cout << endl; } int main() { int tc = 1; cin >> tc; while (tc--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const long long INF = 1000000007; 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...); } string gh = "here"; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { long long n, m; cin >> n >> m; string s; cin >> s; vector<long long> p(m); for (int i = 0; i < m; i++) { cin >> p[i]; p[i]--; } vector<vector<long long> > pre(n, vector<long long>(26, 0)); for (int i = 0; i < n; i++) { int a = (s[i] - 'a'); pre[i][a]++; if (i == 0) continue; for (int j = 0; j < 26; j++) { pre[i][j] += pre[i - 1][j]; } } vector<long long> ans(26, 0); for (int i = 0; i < m; i++) { for (int j = 0; j < 26; j++) { ans[j] += pre[p[i]][j]; } } for (int i = 0; i < 26; i++) { ans[i] += pre[n - 1][i]; } for (int i = 0; i < 26; i++) { cout << ans[i] << ' '; } cout << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 10; using namespace std; void solve() { int n, m; cin >> n >> m; string s; cin >> s; int p[m]; vector<int> cnt(n, 0), ans(26, 0); cnt[n - 1] = 1; for (int i = 0; i < m; i++) { cin >> p[i]; cnt[p[i] - 1]++; } for (int i = n - 2; i >= 0; i--) cnt[i] += cnt[i + 1]; for (int i = 0; i < n; i++) ans[s[i] - 'a'] += cnt[i]; for (auto num : ans) cout << num << " "; cout << "\n"; return; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int t; cin >> t; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { long int i, j, k, m, n, count = 0; cin >> n >> m; long int ans[26] = {0}, sol = 0; vector<long int> p(m); string s; cin >> s; for (i = 0; i < s.size(); i++) ans[s[i] - 'a']++; for (i = 0; i < m; i++) { cin >> p[i]; } sort(p.begin(), p.end()); for (j = 0; j < n; j++) { count = upper_bound(p.begin(), p.end(), j) - p.begin(); count = m - count; ans[s[j] - 'a'] += count; } for (auto i : ans) cout << i << " "; cout << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; long long n, m, num[26], ans[26]; char c[maxn]; int wa[maxn]; int main() { int t; cin >> t; while (t--) { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> c[i]; } for (int i = 1; i <= m; i++) { int q; scanf("%d", &q); wa[q]++; } for (int i = 1; i <= n; i++) { ans[c[i] - 'a']++; num[c[i] - 'a']++; if (wa[i]) { for (int j = 0; j < 26; j++) { ans[j] += wa[i] * num[j]; } } } for (int i = 0; i < 26; i++) { printf("%d ", ans[i]); } cout << endl; memset(ans, 0, sizeof(ans)); memset(num, 0, sizeof(num)); fill(wa, wa + n + 1, 0); } return 0; }