text stringlengths 49 983k |
|---|
#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 a;
cin >> a;
int arr[n + 5];
set<int> st;
int mark[n + 5];
memset(mark, 0, sizeof mark);
for (int i = 0; i < m; i++) {
int x;
cin >> x;
mark[0]++;
mark[x]--;
}
mark[0]++;
for (int i = 1; i <= n; i++) {
mark[i] += mark[i - 1];
}
int ans[28];
memset(ans, 0, sizeof ans);
for (int i = 0; i < n; i++) {
int x = a[i] - 'a';
ans[x] += mark[i];
}
for (int i = 0; i < 26; i++) {
cout << ans[i] << " ";
}
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
int32_t 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;
long long a[m];
for (long long i = 0; i < m; i++) cin >> a[i];
long long pre[n + 1][26];
memset(pre, 0, sizeof(pre));
long long ans[26] = {0};
for (long long i = 1; i <= n; i++) {
for (long long j = 0; j < 26; j++) pre[i][j] = pre[i - 1][j];
pre[i][s[i - 1] - 'a']++;
}
for (long long i = 0; i < m; i++) {
for (long long j = 0; j < 26; j++) {
ans[j] += pre[a[i]][j];
}
}
for (long long i = 0; i < 26; i++) ans[i] += pre[n][i];
for (long long i = 0; i < 26; i++) cout << ans[i] << " ";
cout << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
return a < b ? a = b, 1 : 0;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long double pii = 3.14159265359;
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int T;
cin >> T;
while (T-- != 0) {
int N, M;
cin >> N >> M;
string str;
cin >> str;
vector<int> dp[N];
for (int x = 0; x < (N); x++) {
for (int y = 0; y < (26); y++) dp[x].push_back(0);
}
dp[0][str[0] - 'a']++;
for (int x = 1; x < (N); x++) {
dp[x] = dp[x - 1];
dp[x][str[x] - 'a']++;
}
vector<long long> ans(26);
vector<int> v(M);
for (int x = 0; x < (M); x++) {
cin >> v[x];
v[x]--;
for (int y = 0; y < (26); y++) {
ans[y] += dp[v[x]][y];
}
}
for (int y = 0; y < (26); y++) ans[y] += dp[N - 1][y];
for (int x = 0; x < (26); x++) cout << ans[x] << ' ';
cout << nl;
}
return 0;
}
|
#include <bits/stdc++.h>
using ll = long long;
const ll INF = 1e9;
using namespace std;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vc<vc<T>>;
using pi = pair<ll, ll>;
using vi = vc<ll>;
template <class T>
inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
ll Q;
cin >> Q;
for (ll q = ll(0); q < ll(Q); q++) {
ll n, m;
cin >> n >> m;
string S;
cin >> S;
ll cnt[26];
for (ll i = ll(0); i < ll(26); i++) cnt[i] = 0;
for (ll i = ll(0); i < ll(n); i++) {
cnt[(ll)(S[i] - 'a')]++;
}
ll d[n + 1];
for (ll i = ll(0); i < ll(n + 1); i++) d[i] = 0;
for (ll i = ll(0); i < ll(m); i++) {
ll a;
cin >> a;
a--;
d[a]++;
}
for (ll i = ll(n) - 1; i >= ll(0); i--) {
d[i] += d[i + 1];
}
for (ll i = ll(0); i < ll(n); i++) {
cnt[(ll)(S[i] - 'a')] += d[i];
}
for (ll i = ll(0); i < ll(26); i++) {
cout << cnt[i];
if (i != 25)
cout << " ";
else
cout << "\n";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
;
long long int t, i;
cin >> t;
for (i = 0; i < t; i++) {
int m, n;
cin >> m >> n;
string s;
cin >> s;
int local[26] = {0};
int ans[26] = {0};
int mis[n];
int j;
for (j = 0; j < n; j++) cin >> mis[j];
int k = 0, p;
sort(mis, mis + n);
for (j = 0; j < m; j++) {
local[int(s[j]) - 97]++;
while (mis[k] == j + 1) {
for (p = 0; p < 26; p++) ans[p] += local[p];
k++;
}
}
for (p = 0; p < 26; p++) ans[p] += local[p];
for (j = 0; j < 26; j++) cout << ans[j] << " ";
cout << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long h[200001];
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, g[123] = {0}, c = 0, x, v[123] = {0};
for (long long i = 0; i <= 200000; i++) h[i] = 0;
cin >> n >> m;
string s;
cin >> s;
for (long long i = 0; i < n; i++) v[(int)s[i]]++;
long long p[m];
for (long long i = 0; i < m; i++) {
cin >> p[i];
h[p[i] - 1]++;
}
sort(p, p + m);
for (long long i = p[m - 1] - 1; i >= 0; i--) {
if (h[i] > 0) {
while (h[i]--) {
c++;
}
v[(int)s[i]] += c;
} else {
v[(int)s[i]] += c;
}
}
for (long long i = 97; i <= 122; i++) {
cout << v[i] << " ";
}
cout << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
long long int t;
cin >> t;
while (t--) {
long long int n, m;
vector<int> a(26);
cin >> n >> m;
string s;
cin >> s;
vector<int> p(m);
for (long long int i = (long long int)0; i < (long long int)m; i++) {
cin >> p[i];
}
sort((p).begin(), (p).end());
long long int x = m + 1;
long long int j = 0;
for (long long int i = (long long int)0; i < (long long int)m; i++) {
while (j < n && j < p[i]) {
a[s[j] - 97] += x;
j++;
}
x--;
}
while (j < n) {
a[s[j] - 97] += x;
j++;
}
for (long long int i = (long long int)0; i < (long long int)26; i++) {
cout << a[i] << " ";
}
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool f(int x) {
if (x > 101) {
return 1;
}
return 0;
}
int my_lower(int l, int r) {
while (r - l > 1) {
int m = (l + r) / 2;
(f(m) ? r : l) = m;
}
if (l < r and f(l)) {
return l;
}
return r;
}
void solve() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<vector<int>> v(s.size(), vector<int>(26));
for (int i = 0; i < s.size(); i++) {
if (i > 0) v[i] = v[i - 1];
v[i][s[i] - 'a']++;
}
vector<int> ans(26);
for (int i = 0; i < m; i++) {
int p;
cin >> p;
for (int j = 0; j < 26; j++) {
ans[j] = ans[j] + v[p - 1][j];
}
}
for (int j = 0; j < 26; j++) {
ans[j] = ans[j] + v[s.size() - 1][j];
}
for (int elem : ans) {
cout << elem << ' ';
}
cout << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int ar[maxn], num[maxn];
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
memset(num, 0, sizeof(num));
memset(ar, 0, sizeof(ar));
cin >> n >> m;
string s;
cin >> s;
for (int i = 1; i <= m; i++) {
int x;
cin >> x;
x--;
ar[x]++;
}
int len = s.length();
for (int i = 0; i < len; i++) {
num[s[i] - 97]++;
}
for (int i = len - 1; i >= 0; i--) {
ar[i] += ar[i + 1];
num[s[i] - 97] += ar[i];
}
for (int i = 0; i < 26; i++) {
if (i < 25)
cout << num[i] << " ";
else
cout << num[i] << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int mxN = 2 * 1e5;
int p[mxN], a[mxN + 1][26];
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;
for (int i = 0; i <= n; i++) {
for (int j = 0; j < 26; j++) a[i][j] = 0;
}
for (int i = 0; i < n; i++) a[i + 1][s[i] - 'a']++;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 26; j++) a[i][j] += a[i - 1][j];
}
int ans[26];
for (int j = 0; j < 26; j++) ans[j] = a[n][j];
for (int i = 0; i < m; i++) {
cin >> p[i];
for (int j = 0; j < 26; j++) ans[j] += a[p[i]][j];
}
for (int j = 0; j < 26; j++) cout << ans[j] << " ";
cout << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int tot[28], arr[300007][28], prr[300007];
int main() {
int 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;
void __print(int first) { cerr << first; }
void __print(long first) { cerr << first; }
void __print(long long first) { cerr << first; }
void __print(unsigned first) { cerr << first; }
void __print(unsigned long first) { cerr << first; }
void __print(unsigned long long first) { cerr << first; }
void __print(float first) { cerr << first; }
void __print(double first) { cerr << first; }
void __print(long double first) { cerr << first; }
void __print(char first) { cerr << '\'' << first << '\''; }
void __print(const char *first) { cerr << '\"' << first << '\"'; }
void __print(const string &first) { cerr << '\"' << first << '\"'; }
void __print(bool first) { cerr << (first ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &first) {
cerr << '{';
__print(first.first);
cerr << ',';
__print(first.second);
cerr << '}';
}
template <typename T>
void __print(const T &first) {
int f = 0;
cerr << '{';
for (auto &i : first) 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...);
}
int main() {
map<char, int> dict;
for (int i = 0; i < 26; i++) dict['a' + i] = 0;
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<int> suf(n + 1, 0);
for (int i = 0; i < m; i++) {
int aux;
cin >> aux;
suf[aux - 1]++;
}
suf[n] = 1;
for (int i = n - 1; i >= 0; i--) {
suf[i] += suf[i + 1];
}
for (int i = 0; i < n; i++) dict[s[i]] += suf[i];
for (int i = 0; i < 26; i++) {
cout << dict['a' + i] << " ";
dict['a' + i] = 0;
}
puts("");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
string x;
cin >> x;
int ar[m];
for (int i = 0; i < m; i++) {
cin >> ar[i];
}
int prefix[n + 1];
for (int i = 0; i <= n; i++) {
prefix[i] = 0;
}
for (int i = 0; i < m; i++) {
prefix[ar[i]]++;
}
for (int i = n; i >= 0; i--) {
if (i < n) {
prefix[i] += prefix[i + 1];
}
}
int freq[26];
for (int i = 0; i < 26; i++) freq[i] = 0;
for (int i = 0; i < n; i++) {
freq[x[i] - 'a'] += prefix[i + 1] + 1;
}
for (int i = 0; i < 26; i++) {
cout << freq[i] << " ";
}
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
long long a[N][26];
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);
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= 26; j++) {
a[i][j] = 0;
}
}
for (int i = 0; i < 26; i++) ans[i] = 0;
for (int i = 0; i < m; i++) cin >> b[i];
for (int i = 1; i <= n; i++) {
int d = s[i] - 'a';
a[i][d]++;
}
for (int i = 0; i < 26; i++) {
for (int j = 2; j <= n; j++) {
a[j][i] = a[j - 1][i] + a[j][i];
}
}
for (int i = 0; i < m; i++) {
int k = b[i];
for (int j = 0; j < 26; j++) {
ans[j] += a[k][j];
}
}
for (int i = 0; i < 26; i++) {
ans[i] += a[n][i];
}
for (int i = 0; i < 26; i++) {
if (i) cout << " ";
cout << ans[i];
}
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int MOD = 1e9 + 7;
const int INF32 = 1 << 30;
const long long INF64 = 1LL << 60;
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;
vector<int> in(n);
vector<int> ans(26);
for (int i = 0; i < m; i++) {
int p;
cin >> p;
p--;
in[p]++;
}
int j = 1;
for (int i = n - 1; i > -1; i--) {
if (in[i]) j += in[i];
ans[s[i] - 'a'] += j;
}
for (int i = 0; i < 26; i++) cout << ans[i] << ' ';
cout << endl;
}
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;
int freq[n][26];
memset(freq, 0, sizeof freq);
freq[0][s[0] - 'a']++;
for (int i = 1; i < n; i++) {
for (int j = 0; j < 26; j++) {
freq[i][j] += freq[i - 1][j];
}
freq[i][s[i] - 'a']++;
}
int ans[26] = {0};
while (m--) {
int index;
cin >> index;
index--;
for (int i = 0; i < 26; i++) {
ans[i] += freq[index][i];
}
}
for (char x : s) {
ans[x - 'a']++;
}
for (int i = 0; i < 26; i++) cout << ans[i] << " ";
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
long long int arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
long long int mx = INT_MIN;
if (n == 1) {
cout << arr[0] << "\n";
return;
}
int flag = 0;
for (int i = 0; i < n; i++) {
if (arr[i] > 0) {
flag = 1;
break;
}
mx = max(arr[i], mx);
}
if (flag == 0) {
cout << mx << "\n";
return;
}
long long int sign = 0, sum = 0;
long long int ans = arr[0];
if (arr[0] > 0)
sign = 1;
else
sign = -1;
mx = 0;
for (int i = 0; i < n; i++) {
if ((sign == 1 && arr[i] > 0) || (sign == -1 && arr[i] < 0))
ans = max(ans, arr[i]);
else {
sum += ans;
ans = arr[i];
sign *= (-1);
}
if (i == n - 1) {
if ((arr[n - 1] > 0 && arr[n - 2] > 0) ||
(arr[n - 1] < 0 && arr[n - 2] < 0)) {
ans = max(ans, arr[i]);
sum += ans;
} else
sum += arr[i];
}
}
cout << ans << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
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;
const long long inf = 1e9 + 5;
const long long INF = 1e18 + 5;
const long long maxn = 5e5 + 5;
long long n, b[511111], mx = -1000000001;
long long a[511111], u[555555], sum, cnt;
long long bi(long long x, long long y) {
if (y == 0) return 1ll;
if (y == 1) return x;
long long z = bi(x, y / 2);
z = z * z % n;
if (y & 1) z = z * x % n;
return z % n;
}
long long an[35];
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(NULL);
int q;
cin >> q;
while (q--) {
int n, m;
cin >> n >> m;
string second;
cin >> second;
for (int i = 1; i <= m; i++) cin >> a[i], u[a[i] - 1]++;
for (int i = 0; i < n; i++) {
b[second[i] - 'a']++;
if (u[i] > 0) {
for (int j = 0; j <= 25; j++) an[j] += b[j] * u[i];
}
u[i] = 0;
}
for (int i = 0; i <= 25; i++) cout << an[i] + b[i] << ' ', an[i] = b[i] = 0;
for (int i = 0; i <= n; i++) u[i] = an[i] = b[i] = a[i] = 0;
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, int> p, pair<int, int> p1) { return p.first < p1.first; }
void print(int arr[], int n) {
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
cout << "\n";
}
long long int power(long long int x, long long int y, long long int p) {
long long int res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
bool vowl(char c) {
return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
}
long long int gcd(long long int a, long long int b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
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 second;
cin >> second;
int a[m];
map<int, char> make_pair;
for (int i = 0; i < m; i++) {
cin >> a[i];
}
int arr[n][26];
for (int i = 0; i < n; i++) {
for (int j = 0; j < 26; j++) {
arr[i][j] = 0;
}
}
arr[0][second[0] - 97] = 1;
for (int i = 1; i < n; i++) {
for (int j = 0; j < 26; j++) {
arr[i][j] = arr[i - 1][j];
}
arr[i][second[i] - 97]++;
;
}
int ans[26] = {0};
for (int i = 0; i < m; ++i) {
for (int j = 0; j < 26; j++) {
if (arr[a[i] - 1][j] > 0) {
ans[j] += arr[a[i] - 1][j];
}
}
}
for (int j = 0; j < n; ++j) {
++ans[second[j] - 97];
}
for (int i = 0; i < 26; i++) {
cout << ans[i] << " ";
}
cout << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
char s[N];
int m, n;
void sol() {
int b[26] = {0};
scanf("%d %d", &n, &m);
int a[N] = {0};
scanf("%s", s);
int t;
for (int i = 0; i < m; i++) {
scanf("%d", &t);
a[t - 1]++;
}
a[n - 1] = 1;
for (int i = n - 1; i >= 0; i--) {
if (i < n - 1) a[i] += a[i + 1];
int num = s[i] - 'a';
b[num] += a[i];
}
for (int i = 0; i < 26; i++) {
if (i != 25)
printf("%d ", b[i]);
else
printf("%d\n", b[i]);
}
}
int main() {
int T;
scanf("%d", &T);
while (T--) sol();
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, a, b, n, i, j, m;
cin >> t;
while (t--) {
cin >> n >> m;
long long a[n], p[m];
string s;
cin >> s;
for (i = 0; i < m; i++) cin >> p[i];
vector<long long> al[26];
for (i = 0; i < 26; i++) {
for (j = 0; j < s.length(); j++) {
if (s[j] - 97 == i) {
al[i].push_back(1);
} else
al[i].push_back(0);
}
}
for (i = 0; i < 26; i++) {
for (j = 1; j < al[i].size(); j++) {
al[i][j] += al[i][j - 1];
}
}
long long ans[26] = {0};
for (i = 0; i < m; i++) {
for (j = 0; j < 26; j++) {
ans[j] += al[j][p[i] - 1];
}
}
for (i = 0; i < s.length(); i++) {
ans[s[i] - 97]++;
}
for (i = 0; i < 26; i++) {
cout << ans[i] << " ";
}
cout << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read() {
char c = getchar();
T x = 0, f = 1;
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return x * f;
}
template <typename T>
inline void write(T x) {
if (x < 0) x = (~x) + 1, putchar('-');
if (x / 10) write(x / 10);
putchar(x % 10 | 48);
}
const int INF = 0x3f3f3f3f;
long long int qz[200005][30];
long long int ans[30];
int main() {
int T = read<int>();
while (T--) {
memset(ans, 0, sizeof(ans));
int n = read<int>(), m = read<int>();
for (int i = 1; i <= n; i++) {
char c;
cin >> c;
int a = c - 'a';
ans[a]++;
for (int j = 0; j < 26; j++) qz[i][j] = qz[i - 1][j];
qz[i][a] = qz[i - 1][a] + 1;
}
for (int i = 0; i < m; i++) {
int a = read<int>();
for (int j = 0; j < 26; j++) {
ans[j] += qz[a][j];
}
}
for (int i = 0; i < 26; i++) {
cout << ans[i] << " ";
}
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
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 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) {
long long g = gcd(a, b);
long long ans = (a * b) / g;
return ans;
}
long long add(long long a, long long b) {
a += b;
if (a >= 1000000007) a -= 1000000007;
return a;
}
long long sub(long long a, long long b) {
a -= b;
if (a < 0) {
a += 1000000007;
}
return a;
}
long long mul(long long a, long long b) { return (a * b) % 1000000007; }
vector<long long> primes;
bool prime[10005];
void seive() {
memset(prime, 1, sizeof(prime));
prime[0] = 0;
prime[1] = 0;
for (long long i = 2; i <= 10000; i++) {
if (prime[i] == 1) {
for (long long j = i * i; j <= 10000; j += i) prime[j] = 0;
}
}
}
long long power(long long a, long long b) {
long long ans = 1;
while (b > 0) {
if (b % 2 == 1) ans = (ans % 1000000007 * a % 1000000007) % 1000000007;
a = (a * a) % 1000000007;
b = b / 2;
}
return ans;
}
template <typename T>
std::string NumberToString(T Number) {
std::ostringstream ss;
ss << Number;
return ss.str();
}
long long gcdExtended(long long a, long long b, long long *x, long long *y);
long long modInverse(long long b, long long m) {
long long x, y;
long long g = gcdExtended(b, m, &x, &y);
if (g != 1) return -1;
return (x % m + m) % m;
}
long long modDivide(long long a, long long b, long long m) {
a = a % m;
long long inv = modInverse(b, m);
return (inv * a) % m;
}
long long gcdExtended(long long a, long long b, long long *x, long long *y) {
if (a == 0) {
*x = 0, *y = 1;
return b;
}
long long x1, y1;
long long gcd = gcdExtended(b % a, a, &x1, &y1);
*x = y1 - (b / a) * x1;
*y = x1;
return gcd;
}
void solve() {
long long n, m;
cin >> n >> m;
string s;
cin >> s;
long long p[m], i, j;
map<long long, long long> mp_indices;
for (i = 0; i < m; i++) {
cin >> p[i];
p[i]--;
mp_indices[p[i]]++;
}
long long ans[26];
for (i = 0; i < 26; i++) {
ans[i] = 0;
}
long long next = 0;
vector<pair<long long, long long> > indices;
for (auto it : mp_indices) {
indices.push_back({it.first, it.second});
}
map<char, long long> mp;
for (i = 0; i < n; i++) {
mp[s[i]]++;
if (next < indices.size() and indices[next].first == i) {
next++;
for (auto it : mp) {
char c = it.first;
long long freq = it.second;
ans[c - 'a'] += freq * indices[next - 1].second;
}
}
}
for (auto it : mp) {
char c = it.first;
long long freq = it.second;
ans[c - 'a'] += freq;
}
for (i = 0; i < 26; i++) {
cout << ans[i] << " ";
}
cout << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
bool codechef = 1;
long long t = 1;
if (codechef) {
cin >> t;
}
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int ind(char c) { return c - 'a'; }
void solve() {
int alpha[26] = {0};
int n, m;
cin >> n >> m;
string s;
cin >> s;
int* a = new int[m];
for (int i = 0; i < m; i++) {
cin >> a[i];
}
sort(a, a + m);
for (int i = 0; i < n; i++) alpha[s[i] - 'a']++;
for (int i = 0; i < a[0]; i++) alpha[s[i] - 'a'] += m;
for (int i = 0; i < m - 1; i++) {
for (int j = a[i]; j < a[i + 1]; j++) {
alpha[s[j] - 'a'] += m - i - 1;
}
}
for (int i = 0; i < 26; i++) {
cout << alpha[i] << " ";
}
cout << endl;
}
int main() {
int t;
cin >> t;
while (t > 0) {
solve();
t--;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool comp(pair<long long, long long> x, pair<long long, long long> y) {
return x.first < y.first;
}
struct compare {
bool operator()(pair<long long, long long> p1,
pair<long long, long long> p2) {
return p1.first < p2.first;
}
};
long long ans[26];
void solve() {
fill(ans, ans + 26, 0);
long long n, m;
cin >> n >> m;
string second;
cin >> second;
vector<long long> arr;
for (long long i = 0; i < m; i++) {
long long temp;
cin >> temp;
temp--;
arr.push_back(temp);
}
sort(arr.begin(), arr.end());
for (long long i = 0; i < n; i++) {
ans[(long long)(second[i] - 'a')]++;
auto it = lower_bound(arr.begin(), arr.end(), i);
auto it1 = upper_bound(arr.begin(), arr.end(), i);
if (*it == i) {
ans[(long long)(second[i] - 'a')] += arr.end() - it;
} else {
ans[(long long)(second[i] - 'a')] += arr.end() - it1;
}
}
for (long long i = 0; i < 26; i++) {
cout << ans[i] << " ";
}
cout << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t;
cin >> t;
while (t > 0) {
t--;
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b);
long long int gcd(long long int a, long long int b);
int prime(int n);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int n, m, x;
cin >> n >> m;
vector<vector<long long int> > v(n, vector<long long int>(26, 0));
long long int b[26] = {0};
string a;
cin >> a;
for (int i = 0; i < n; i++) {
if (i > 0)
for (int j = 0; j < 26; j++) {
v[i][j] = v[i - 1][j];
}
v[i][a[i] - 'a']++;
}
for (int i = 0; i < m; i++) {
cin >> x;
for (int i = 0; i < 26; i++) {
b[i] += v[x - 1][i];
}
}
for (int i = 0; i < 26; i++) {
b[i] += v[n - 1][i];
}
for (int i = 0; i < 26; i++) cout << b[i] << " ";
cout << endl;
}
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
return (a.second < b.second);
}
long long int gcd(long long int a, long long int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int prime(int n) {
int flag = 1;
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
flag = 0;
break;
}
}
return flag;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int a, b, c, d, e, f, g, h, i, j, k, l, m, t, n, o,
p = 0, q = 1, r, u, v, w, x, y, z, temp = 0, t1, t2, sum = 0, mi = 0,
mx = 0, cnt = 0;
double ans = 0;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int at = 0, dt = 0;
q = 1;
cin >> q;
while (q--) {
cin >> n >> m;
string s;
cin >> s;
vector<vector<long long int>> v(n, vector<long long int>(26, 0));
vector<long long int> u;
v[0][s[0] - 'a']++;
for (i = 1; i < n; i++) {
char ch = s[i];
for (j = 0; j < 26; j++) {
if (s[i] == char('a' + j))
v[i][j] = v[i - 1][j] + 1;
else
v[i][j] = v[i - 1][j];
}
}
u = v[n - 1];
for (i = 0; i < m; i++) {
cin >> x;
for (j = 0; j < 26; j++) {
u[j] = u[j] + v[x - 1][j];
}
}
for (i = 0; i < 26; i++) cout << u[i] << " ";
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, m;
cin >> n >> m;
string s;
cin >> s;
vector<long long> p(m);
for (long long i = 0; i < (m); ++i) {
cin >> p[i];
}
sort((p).begin(), (p).end());
vector<long long> cnt(27);
long long ptr = 0;
for (long long i = 0; i < (n); ++i) {
while (i == p[ptr]) {
m--;
ptr++;
}
cnt[s[i] - 'a'] += (m ? m + 1 : 1);
}
for (long long i = 0; i < (26); ++i) {
if (i) {
cout << ' ';
}
cout << cnt[i];
}
cout << "\n";
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
long long tt;
cin >> tt;
while (tt--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, letters[30], tries[200005];
char s[200005];
scanf(" %d", &t);
for (int j = 0; j < t; j++) {
int n, m, x;
scanf("%d %d", &n, &m);
scanf(" %s", s);
for (int i = 0; i < 30; i++) letters[i] = 0;
for (int i = 0; i < m; i++) {
scanf(" %d", &tries[i]);
tries[i]--;
}
tries[m] = -5;
sort(tries, m + tries);
int it = 0, result = 0;
m++;
for (int i = 0; i < n; i++) {
letters[s[i] - 'a'] += m;
while (m > 0 && i == tries[it]) {
it++;
m--;
}
}
for (int i = 0; i < 26; i++) {
printf("%d ", letters[i]);
}
printf("\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int INF = 1e9;
long long add(long long a, long long b) {
long long res = a + b;
if (res >= mod) res -= mod;
return res;
}
long long sub(long long a, long long b) {
long long res = a - b + mod;
if (res >= mod) res -= mod;
return res;
}
long long mul(long long a, long long b) {
return (((a % mod) * (b % mod)) % mod);
}
long long potolok(long long a, long long b) { return (a + b - 1) / b; }
long long gcd(long long x, long long y) {
if (y == 0) {
return x;
}
if (x > y) {
return gcd(y, x % y);
} else {
return gcd(x, y % x);
}
}
bool cmpr(int x, int y) {
if (abs(x) < abs(y))
return true;
else {
return false;
}
}
bool comp(pair<int, int> x, pair<int, int> y) {
if (x.first < y.first)
return true;
else if (x.first == y.first) {
if (x.second < y.second)
return true;
else
return false;
} else {
return false;
}
}
int cnt(string &s, string &p, int m, int n) {
if ((m == 0 && n == 0) || n == 0) {
return 1;
}
if (m == 0) {
return 0;
}
if (s[m - 1] == p[n - 1]) {
return cnt(s, p, m - 1, n - 1) + cnt(s, p, m - 1, n);
} else {
return cnt(s, p, m - 1, n);
}
}
int div(int n) {
int ans = 0;
vector<int> used(n + 1, 0);
for (int i = 1; i <= sqrt(n); i++) {
if (n % i == 0 && (!used[i] && !used[n / i])) {
if (i * i == n) {
ans++;
} else {
ans += 2;
}
}
}
return ans;
}
void solve() {
int n, m;
cin >> n >> m;
vector<int> p(m);
string s;
cin >> s;
for (int i = 0; i < m; i++) {
cin >> p[i];
p[i]--;
}
vector<map<char, int>> v(n);
v[0][s[0]]++;
for (int i = 1; i < n; i++) {
v[i] = v[i - 1];
v[i][s[i]]++;
}
map<char, int> ans;
for (int i = 0; i < m; i++) {
int x = p[i];
for (auto j : v[x]) {
if (!ans.count(j.first)) {
ans[j.first] = j.second;
} else {
ans[j.first] += j.second;
}
}
}
for (auto j : v[n - 1]) {
if (!ans.count(j.first)) {
ans[j.first] = j.second;
} else {
ans[j.first] += j.second;
}
}
for (char i = 'a'; i <= 'z'; i++) {
if (!ans.count(i)) {
cout << 0 << " ";
} else {
cout << ans[i] << " ";
}
}
cout << endl;
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
int tmp;
int alp[26];
for (int i = 0; i < 26; i++) {
alp[i] = 0;
}
char s[n + 1];
for (int i = 1; i <= n; i++) {
cin >> s[i];
}
vector<int> p;
for (int i = 0; i < m; i++) {
cin >> tmp;
p.push_back(tmp);
}
sort(p.begin(), p.end());
int t = m + 1;
int u = 0;
for (int i = 1; i <= n; i++) {
alp[s[i] - 'a'] += t;
while (u < m && p[u] == i) {
t--;
u++;
}
}
for (int i = 0; i < 26; i++) {
cout << alp[i] << " ";
}
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
char a[maxn];
int p[maxn];
int sum[maxn][30];
int 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", a + 1);
for (int i = 1; i <= m; i++) scanf("%d", &p[i]);
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= 25; j++) {
sum[i][j] = sum[i - 1][j];
}
sum[i][a[i] - 'a']++;
}
for (int i = 1; i <= m; i++) {
int tmp = p[i];
for (int j = 0; j <= 25; j++) {
ans[j] += sum[tmp][j];
}
}
for (int i = 0; i <= 25; i++) ans[i] += sum[n][i];
for (int i = 0; i <= 25; i++) printf("%d ", ans[i]);
printf("\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m, a[1000009], b[1000009], f[300], ans[300];
string s;
void solve() {
cin >> n >> m >> s;
memset(f, 0, sizeof(f));
memset(ans, 0, sizeof(ans));
s = " " + s;
for (int i = 1; i <= m; i++) {
cin >> a[i];
}
sort(a + 1, a + m + 1);
int j = 1;
for (int i = 1; i <= n; i++) {
f[s[i]]++;
ans[s[i]]++;
int d = 0;
while (i == a[j] && j <= m) {
d++;
j++;
}
for (int k = 'a'; k <= 'z'; k++) {
ans[k] += d * f[k];
}
}
for (int i = 'a'; i <= 'z'; i++) {
cout << ans[i] << " ";
}
cout << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int q;
cin >> q;
while (q--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
char str[200005];
int num[26];
int lazy[200005];
int ci[200005];
int main() {
int cishu;
cin >> cishu;
while (cishu--) {
memset(num, 0, sizeof(num));
memset(lazy, 0, sizeof(lazy));
memset(ci, 0, sizeof(ci));
int len, mis;
cin >> len >> mis;
for (int i = 1; i <= len; i++) cin >> str[i];
lazy[1]++;
lazy[len + 1]--;
for (int i = 1; i <= mis; i++) {
int when = 0;
cin >> when;
lazy[1]++;
lazy[when + 1]--;
}
for (int i = 1; i <= len; i++) ci[i] = ci[i - 1] + lazy[i];
for (int i = 1; i <= len; i++) {
int which = str[i] - 'a';
num[which] = num[which] + ci[i];
}
for (int i = 0; i < 26; i++) printf("%d%c", num[i], i == 25 ? '\n' : ' ');
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct hash_pair {
template <class T1, class T2>
size_t operator()(const pair<T1, T2>& p) const {
auto hash1 = hash<T1>{}(p.first);
auto hash2 = hash<T2>{}(p.second);
return hash1 ^ hash2;
}
};
void dfs(vector<int> adj[], int vis[], int cur, int mark, int iden[]) {
iden[cur] = mark;
for (int i = 0; i < adj[cur].size(); ++i) {
int c = adj[cur][i];
if (!vis[c]) {
vis[c] = 1;
dfs(adj, vis, c, mark, iden);
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
int p[m];
string s;
cin >> s;
for (int i = 0; i < m; ++i) cin >> p[i];
int dp[26][n];
for (int i = 0; i < 26; ++i) {
char c = (char)('a' + i);
for (int j = 0; j < n; ++j) {
if (j == 0) {
if (s[j] == c)
dp[i][j] = 1;
else
dp[i][j] = 0;
} else if (s[j] == c)
dp[i][j] = dp[i][j - 1] + 1;
else
dp[i][j] = dp[i][j - 1];
}
}
long long al[26] = {0};
for (int i = 0; i < m; ++i) {
for (int j = 0; j < 26; ++j) {
al[j] += dp[j][p[i] - 1];
}
}
for (int i = 0; i < 26; ++i) {
cout << al[i] + dp[i][n - 1] << ' ';
}
cout << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, m;
string s;
cin >> n >> m >> s;
long long p[m], ans[26] = {};
for (long long i = 0; i < m; i++) cin >> p[i], p[i]--;
sort(p, p + m);
long long pointer = 0;
for (long long i = 0; i < n; i++) {
while (pointer < m and p[pointer] < i) pointer++;
ans[s[i] - 'a'] += m - pointer;
}
for (long long i = 0; i < n; i++) ans[s[i] - 'a']++;
for (long long i : ans) cout << i << ' ';
cout << '\n';
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
long long t;
cin >> t;
while (t--) solve();
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int cnt[maxn][26];
char s[maxn];
int p[maxn], n, m, T;
long long ans[26];
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++) cnt[i][j] = 0;
for (int i = 1; i <= n; i++) cnt[i][s[i] - 'a']++;
for (int i = 1; i <= n; i++)
for (int j = 0; j < 26; j++) cnt[i][j] += cnt[i - 1][j];
memset(ans, 0, sizeof(ans));
for (int i = 1, x; i <= m; i++) {
scanf("%d", &x);
for (int j = 0; j < 26; j++) ans[j] += cnt[x][j];
}
for (int i = 0; i < 26; i++) ans[i] += cnt[n][i];
for (int i = 0; i < 26; i++) printf("%lld ", ans[i]);
printf("\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, m, elem;
cin >> t;
while (t--) {
cin >> n >> m;
vector<int> p, a;
string s;
cin >> s;
for (int i = 0; i < 26; i++) {
a.push_back(0);
}
for (int i = 0; i < m; i++) {
cin >> elem;
p.push_back(elem);
}
sort(p.begin(), p.end());
int k = 0;
for (int i = 0; i < n; i++) {
char ch = s[i];
while (p[k] == i + 1 && k < m) {
a[(int)ch - 97]++;
k++;
}
a[(int)ch - 97] += (m - k + 1);
continue;
}
for (int i = 0; i < 26; i++) {
cout << a[i] << " ";
}
cout << endl;
a.clear();
p.clear();
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const unsigned long long INF = 1e18;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main() {
fast();
fast();
long long t;
cin >> t;
while (t--) {
long long n, m;
cin >> n >> m;
string s;
cin >> s;
long long a[m];
for (long long i = 0; i < m; i++) {
cin >> a[i];
}
sort(a, a + m);
long long f[26] = {0};
for (long long i = 0; i < n; i++) {
long long x = upper_bound(a, a + m, i) - a;
x = m - x;
f[s[i] - 'a'] += x + 1;
}
for (long long i = 0; i < 26; i++) cout << f[i] << " ";
cout << "\n";
}
}
|
#include <bits/stdc++.h>
bool f(long long int x, long long int y) { return x > y; }
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n, m, x;
cin >> n >> m;
map<char, int> mp;
vector<int> p;
string s;
cin >> s;
for (long long int i = 0; i < m; i++) {
cin >> x;
p.push_back(x);
}
p.push_back(n);
sort(p.begin(), p.end(), f);
long long int index = m;
for (long long int i = 1; i <= n; i++) {
while (p[index] < i) {
index--;
}
mp[s[i - 1]] += index + 1;
}
for (long long int i = 0; i < 26; i++) {
cout << mp[(char)(97 + i)] << " ";
}
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long LINF = LLONG_MAX;
const int INF = INT_MAX;
const int MOD = 998244353;
void solve() {
int n, m;
string s;
cin >> n >> m >> s;
vector<int> p(m);
for (auto& v : p) cin >> v;
vector<long long> ans(26);
for (auto& v : s) ans[v - 'a']++;
vector<vector<int>> cnt(n, vector<int>(26));
cnt[0][s[0] - 'a']++;
for (int i = 1; i < n; i++) {
cnt[i] = cnt[i - 1];
cnt[i][s[i] - 'a']++;
}
for (auto& t : p) {
for (int i = 0; i < 26; i++) {
ans[i] += cnt[t - 1][i];
}
}
for (auto& v : ans) cout << v << ' ';
cout << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie();
int t;
cin >> t;
while (t--) solve();
}
|
#include <bits/stdc++.h>
int t, n, m;
std::string s;
std::vector<int> sum;
int cnt[26];
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> t;
while (t--) {
std::cin >> n >> m >> s;
sum.assign(n, 0);
for (int i = 0; i < m; ++i) {
int p;
std::cin >> p;
++sum[p - 1];
}
++sum[n - 1];
for (int i = n - 2; i >= 0; --i) sum[i] += sum[i + 1];
std::fill(cnt, cnt + 26, 0);
for (int i = 0; i < n; ++i) cnt[s[i] - 'a'] += sum[i];
for (int i = 0; i < 26; ++i) std::cout << cnt[i] << " \n"[i == 25];
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
T max(T a, T b, T c) {
return max(a, max(b, c));
}
template <class T>
T min(T a, T b, T c) {
return min(a, min(b, c));
}
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
template <class T>
void printVector(const std::vector<T> arr) {
for (auto i : arr) cout << i << " ";
cout << '\n';
}
template <class T>
void printArray(T arr[], long long int n) {
for (long long int i = 0; i < n; i++) cout << arr[i] << " ";
cout << '\n';
}
int main() {
fastio();
long long int t = 1;
cin >> t;
while (t--) {
long long int n, m;
cin >> n >> m;
string str;
cin >> str;
std::vector<long long int> arr(m);
for (long long int i = 0; i < m; i++) cin >> arr[i];
long long int count[n][26];
memset(count, 0, sizeof(count));
for (long long int i = 0; i < n; i++) {
if (i == 0) {
count[i][str[i] - 'a']++;
} else {
for (long long int j = 0; j < 26; j++) count[i][j] = count[i - 1][j];
count[i][str[i] - 'a']++;
}
}
long long int ans[26];
memset(ans, 0, sizeof(ans));
for (long long int i = 0; i < m; i++) {
long long int a = arr[i];
for (long long int j = 0; j < 26; j++) {
long long int co = count[a - 1][j];
ans[j] += co;
}
}
for (long long int j = 0; j < 26; j++) ans[j] += count[n - 1][j];
printArray(ans, 26);
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long n, m;
vector<long long> ch, cur;
map<long long, long long> add;
string s;
cin >> n >> m;
cin >> s;
ch.assign(26, 0);
cur.assign(n, 0);
for (int i = 0; i < m; i++) {
long long num;
cin >> num;
add[num - 1]++;
}
long long ans = 1;
for (int i = n - 1; i >= 0; i--) {
if (add.count(i)) {
ans += add[1LL * i];
}
cur[i] = ans;
ch[s[i] - 'a'] += cur[i];
}
for (int i = 0; i < 26; i++) {
cout << ch[i] << " ";
}
cout << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int n, m, i, j;
cin >> n >> m;
string s;
cin >> s;
vector<int> vec(n);
for (i = 0; i < m; i++) {
int x;
cin >> x;
vec[x - 1]++;
}
for (i = n - 1; i > 0; i--) {
vec[i - 1] += vec[i];
}
vector<int> ans(26);
for (i = 0; i < n; i++) {
ans[s[i] - 'a'] += vec[i];
ans[s[i] - 'a']++;
}
for (i = 0; i < 26; i++) {
cout << ans[i] << " ";
}
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int min(long long int a, long long int b) { return a < b ? a : b; }
long long int min(long long int a, long long int b, long long int c) {
a = min(a, b);
a = min(a, c);
return a;
}
long long int max(long long int a, long long int b) { return a > b ? a : b; }
long long int max(long long int a, long long int b, long long int c) {
a = max(a, b);
a = max(a, c);
return a;
}
long long int power(long long int a, long long int b) {
long long int res = 1;
while (b) {
if (b & 1) res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
long long int mpower(long long int a, long long int b, long long int m) {
long long int res = 1;
a = a % m;
while (b) {
if (b & 1) {
res = (res * a) % m;
}
a = ((a % m) * (a % m)) % m;
b >>= 1;
}
return res;
}
long long int gcd(long long int a, long long int b) {
if (b == 0) return a;
if (a == 0) return b;
if (a >= b)
return gcd(b, a % b);
else
return gcd(a, b % a);
}
long long int lcm(long long int a, long long int b) {
long long int p = a * b;
return p / gcd(a, b);
}
long long int dsum(long long int n) {
long long int ans = 0;
while (n) {
ans += (n % 10);
n /= 10;
}
return ans;
}
struct pll {
long long int x, y;
};
bool comp(pll a, pll b) {
if (a.x == b.x)
return a.y < b.y;
else
return a.x < b.x;
}
int main() {
char ch1, ch2, ch3;
string s1, s2, s3, str;
long long int i, j, k, a, b, t, c, d, n, m, sum = 0, ans = 0, temp;
cin >> t;
while (t--) {
cin >> n >> m;
cin >> str;
long long int arr[m];
for (i = 0; i < m; i++) cin >> arr[i];
vector<vector<long long int> > v(n, vector<long long int>(26, 0));
for (i = 0; i < n; i++) {
c = str[i] - 'a';
for (j = 0; j < 26 && i > 0; j++) v[i][j] = v[i - 1][j];
v[i][c]++;
}
vector<long long int> al(26, 0);
for (i = 0; i < m; i++) {
c = arr[i] - 1;
for (j = 0; j < 26; j++) {
al[j] += v[c][j];
}
}
for (i = 0; i < 26; i++) al[i] += v[n - 1][i];
for (i = 0; i < 26; i++) cout << al[i] << " ";
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, m;
string str;
vector<long long> sum;
void Input() {
cin >> n >> m >> str, sum.clear(), sum.resize(n);
fill(sum.begin(), sum.end(), 0);
for (long long i = 0; i < m; i++) {
long long d;
cin >> d;
sum[d - 1]++;
}
}
void Solve() {
long long ans[26] = {0};
for (long long i = n - 2; i >= 0; i--) sum[i] = sum[i + 1] + sum[i];
for (long long i = 0; i < n; i++) ans[str[i] - 'a'] += sum[i] + 1;
for (long long i = 0; i < 26; i++) cout << ans[i] << " ";
cout << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long T = 1;
cin >> T;
while (T--) {
Input();
Solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m, cnt, pnt;
string s;
vector<int> p;
void solve() {
cin >> n >> m;
cin >> s;
p.resize(m);
int ans[26] = {0};
for (int i = 0; i < m; i++) {
cin >> p[i];
}
cnt = m + 1;
pnt = 0;
sort(p.begin(), p.end());
for (int i = 0; i < s.length(); i++) {
ans[s[i] - 'a'] += cnt;
while (pnt != m && p[pnt] == 1 + i) {
cnt--;
pnt++;
}
}
for (int i = 0; i < 26; i++) {
cout << ans[i] << " ";
}
cout << "\n";
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
int smen[200001];
string s;
int vf[26];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t, n, m, i, x;
cin >> t;
for (int l = 1; l <= t; l++) {
cin >> n >> m >> s;
for (i = 0; i <= n; i++) smen[i] = 0;
for (i = 0; i < 26; i++) vf[i] = 0;
smen[0] = 1;
smen[n] = -1;
for (i = 1; i <= m; i++) {
cin >> x;
smen[0]++;
smen[x]--;
}
for (i = 0; i < n; i++) {
if (i) smen[i] += smen[i - 1];
vf[s[i] - 'a'] += smen[i];
}
for (i = 0; i < 26; i++) cout << vf[i] << " ";
cout << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void init() {}
void solve() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<int> v(m);
do {
for (auto& x139874 : v) {
cin >> x139874;
}
} while (0);
do {
sort(v.begin(), v.end());
} while (0);
v.push_back(n);
vector<int> tmp(26, 0);
vector<long long int> ans(26, 0);
for (int i = 0, j = 0; i < s.size() && j < v.size(); i++) {
tmp[s[i] - 'a'] += 1;
while (j < v.size() && v[j] == i + 1) {
for (int k = 0; k < 26; k++) {
ans[k] += tmp[k];
}
j += 1;
}
}
do {
for (auto& x139374 : ans) {
cout << x139374 << " ";
}
cout << "\n";
} while (0);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
init();
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
int t;
cin >> t;
while (t--) {
int n, m, x, a[30]{};
string s;
cin >> n >> m >> s;
vector<vector<int>> v(n + 5, vector<int>(30, 0));
for (int i = 1; i <= n; i++)
v[i] = v[i - 1], v[i][s[i - 1] - 'a']++, a[s[i - 1] - 'a']++;
for (int i = 0; i < m; i++) {
cin >> x;
for (int j = 0; j < 26; j++) a[j] += v[x][j];
}
for (int i = 0; i < 26; i++) cout << a[i] << " ";
cout << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
signed 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 p[m];
long long int i, j, k;
for (i = 0; i <= m - 1; i++) {
cin >> p[i];
}
sort(p, p + m);
long long int a[n];
for (i = 0; i <= n - 1; i++) {
a[i] = m - (lower_bound(p, p + m, i + 1) - p);
}
map<char, long long int> M;
for (i = 0; i <= n - 1; i++) {
M[s[i]]++;
}
for (i = 0; i <= n - 1; i++) {
M[s[i]] += a[i];
}
for (i = 97; i < 97 + 26; i++) {
cout << M[char(i)] << " ";
}
cout << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
vector<int> addv(vector<int> a, vector<int> b) {
for (int i = 0; i < 26; ++i) {
a[i] += b[i];
}
return a;
}
int main(int argc, char const *argv[]) {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<int> a[n + 1];
a[0] = vector<int>(26, 0);
for (int i = 0; i < n; ++i) {
a[i + 1] = a[i];
a[i + 1][s[i] - 'a']++;
}
vector<int> p(m, 0);
for (int i = 0; i < m; ++i) {
cin >> p[i];
}
vector<int> ans(26, 0);
for (auto it : p) {
ans = addv(ans, a[it]);
}
ans = addv(ans, a[n]);
for (auto it : ans) {
cout << it << " ";
}
cout << endl;
}
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;
long long p[200010];
char ch[200010];
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
scanf("%d%d", &n, &m);
getchar();
gets(ch);
for (int i = 1; i <= m; ++i) scanf("%d", &p[i]);
static long long cnt[26][200010] = {0};
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < 26; ++j) cnt[j][i] = cnt[j][i - 1];
cnt[ch[i - 1] - 'a'][i]++;
}
long long sav[26] = {0};
for (int i = 1; i <= m; ++i) {
for (int j = 0; j < 26; ++j) sav[j] += cnt[j][p[i]];
}
for (int j = 0; j < 26; ++j) sav[j] += cnt[j][n];
printf("%lld", sav[0]);
for (int i = 1; i < 26; ++i) printf(" %lld", sav[i]);
printf("\n");
}
return 0;
}
|
#include <bits/stdc++.h>
int t, n, m;
std::string s;
std::vector<int> sum;
int cnt[26];
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> t;
while (t--) {
std::cin >> n >> m >> s;
sum.assign(n, 0);
for (int i = 0; i < m; ++i) {
int p;
std::cin >> p;
++sum[p - 1];
}
++sum[n - 1];
for (int i = n - 2; i >= 0; --i) sum[i] += sum[i + 1];
std::fill(cnt, cnt + 26, 0);
for (int i = 0; i < n; ++i) cnt[s[i] - 'a'] += sum[i];
for (int i = 0; i < 26; ++i) std::cout << cnt[i] << " \n"[i == 25];
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long t, n, m, a[200005], b[200005], d, kt, kq[30], j;
string s;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--) {
memset(b, 0, sizeof(b));
memset(kq, 0, sizeof(kq));
memset(a, 0, sizeof(a));
cin >> n >> m >> s;
s = ' ' + s;
for (long long i = 1; i <= m; i++) {
cin >> d;
a[d]++;
}
for (long long i = n - 1; i >= 1; i--) a[i] += a[i + 1];
for (long long i = 1; i <= n; i++) {
kq[s[i] - 'a' + 1] += (a[i] + 1);
}
for (long long i = 1; i <= 26; i++) cout << kq[i] << " ";
cout << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, n, a, b, p, c, d, e, f, g, h, hh, i, j;
cin >> t;
while (t--) {
long long m;
cin >> n >> m;
string s;
cin >> s;
long long ans[27] = {0};
long long sum[n];
memset(sum, 0, sizeof(sum));
long long arr[m];
for (i = 0; i < m; i++) {
cin >> arr[i];
sum[arr[i] - 1]++;
}
for (i = n - 2; i >= 0; i--) sum[i] += sum[i + 1];
for (i = 0; i < n; i++) {
ans[s[i] - 'a'] += sum[i];
}
for (i = 0; i < n; i++) {
ans[s[i] - 'a']++;
}
for (i = 0; i < 26; i++) {
cout << ans[i] << " ";
}
cout << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
auto fastio = (ios::sync_with_stdio(false), cin.tie(nullptr));
void solve() {
long long n, m;
cin >> n >> m;
string s;
cin >> s;
vector<long long> p(m);
for (long long i = 0; i < (m); ++i) {
cin >> p[i];
}
sort((p).begin(), (p).end());
vector<long long> cnt(27);
long long ptr = 0;
for (long long i = 0; i < (n); ++i) {
while (i == p[ptr]) {
m--;
ptr++;
}
cnt[s[i] - 'a'] += (m ? m + 1 : 1);
}
for (long long i = 0; i < (26); ++i) {
if (i) {
cout << ' ';
}
cout << cnt[i];
}
cout << "\n";
}
int32_t main() {
long long tt;
cin >> tt;
while (tt--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int alphe[27][200005];
long long ans[27];
int t;
string str;
int n, m;
int temp;
vector<int> P;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cin >> t;
while (t--) {
memset(ans, 0, sizeof(ans));
P.clear();
cin >> n >> m;
cin >> str;
for (int i = 0; i < m; i++) {
cin >> temp;
P.push_back(temp);
}
for (int i = 0; i < str.size(); i++) {
if (i == 0) {
for (int i = 0; i < 26; i++) alphe[i][0] = 0;
alphe[str[i] - 'a'][i]++;
continue;
} else {
for (int j = 0; j < 26; j++) {
alphe[j][i] = alphe[j][i - 1];
}
alphe[str[i] - 'a'][i]++;
}
}
for (int i = 0; i < m; i++) {
int k = P[i] - 1;
for (int j = 0; j < 26; j++) {
ans[j] += alphe[j][k];
}
}
for (int i = 0; i < 26; i++) {
ans[i] += alphe[i][n - 1];
}
for (int i = 0; i < 26; i++) {
cout << ans[i];
if (i == 25) {
cout << endl;
} else {
cout << " ";
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
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 << "\n";
}
int main() {
long long a;
cin >> a;
while (a--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, i, p;
cin >> t;
while (t--) {
int n, m;
string s;
cin >> n >> m >> s;
vector<int> cnt(n);
for (i = 0; i < m; i++) {
cin >> p;
cnt[p - 1]++;
}
for (i = n - 1; i > 0; i--) cnt[i - 1] += cnt[i];
vector<int> sol(26);
for (i = 0; i < n; i++) sol[s[i] - 'a'] += cnt[i] + 1;
for (i = 0; i < 26; i++) cout << sol[i] << " ";
cout << endl;
}
return 0;
}
|
#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() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
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 x, y, n, m, k, i, j, sum = 0, flag = 0, mx = INT_MIN, t = 1, mn = INT_MAX;
string str, st, s;
char ch;
void solve() {
cin >> n >> m >> str;
vector<int> h(26, 0), p(m + 1, INT_MAX);
for (int i = 0; i < m; i++) cin >> p[i];
flag = 0;
sort(p.begin(), p.end());
m++;
for (int i = 0; i < str.size(); i++) {
sum = 0;
while (i == p[flag] - 1) {
flag++;
sum++;
}
h[int(str[i]) - 97] += m;
m -= sum;
}
for (int i = 0; i < 26; i++) cout << h[i] << " ";
cout << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> t;
while (t--) {
solve();
}
}
|
#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;
int p[m + 1];
for (int i = 0; i < m; i++) {
cin >> p[i];
}
p[m] = n;
sort(p, p + m + 1);
int j = 0;
vector<int> ans(26, 0);
for (int i = 0; i < s.size(); i++) {
ans[s[i] - 'a'] += m - j + 1;
while (p[j] == i + 1) {
j++;
}
}
for (int i = 0; i < 26; i++) cout << ans[i] << " ";
cout << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
c b, e;
};
template <class c>
rge<c> range(c i, c j) {
return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
~debug() { cerr << endl; }
template <class c>
typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {
cerr << boolalpha << i;
return *this;
}
template <class c>
typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {
return *this << range(begin(i), end(i));
}
template <class c, class b>
debug& operator<<(pair<b, c> d) {
return *this << "(" << d.first << ", " << d.second << ")";
}
template <class c>
debug& operator<<(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it;
return *this << "]";
}
};
void solve() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<int> p;
for (int i = 0; i < m; i++) {
int val;
cin >> val;
p.push_back(val);
}
vector<vector<int>> pref(26, vector<int>(n));
vector<int> ans(26);
for (int i = 0; i < n; i++) {
pref[s[i] - 'a'][i]++;
ans[s[i] - 'a']++;
}
for (int i = 0; i < 26; i++) {
for (int j = 0; j < n; j++) {
if (j > 0) {
pref[i][j] += pref[i][j - 1];
}
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < 26; j++) {
ans[j] += (pref[j][p[i] - 1]);
}
}
for (int i = 0; i < 26; i++) {
cout << ans[i] << " ";
}
cout << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
int t, n, m, carac, acum;
int freq[2 * 100123], stop[2 * 100123], valor;
string s;
int main() {
ios_base::sync_with_stdio(0);
cin >> t;
while (t--) {
memset(stop, 0, sizeof(stop));
memset(freq, 0, sizeof(freq));
cin >> n >> m;
cin >> s;
for (int i = 0; i < m; i++) {
cin >> valor;
stop[valor - 1]++;
}
acum = 0;
for (int i = n - 1; i >= 0; i--) {
carac = s[i] - 'a';
acum += stop[i];
freq[carac] += (acum + 1);
}
for (int i = 0; i < 26; i++) {
cout << freq[i] << (i == 25 ? "" : " ");
}
cout << endl;
}
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--) {
for (int i = 0; i < 26; i++) cnt[i] = 0;
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;
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
char s[200002];
cin.ignore();
cin.getline(s, 200002);
long long cnt[200002] = {0};
cnt[n - 1] = 1;
for (int i = 0; i < m; i++) {
int temp;
cin >> temp;
if (temp > 0) cnt[temp - 1]++;
}
for (int i = n - 1; i > 0; i--) {
cnt[i - 1] += cnt[i];
}
long long ans[26] = {0};
for (int i = 0; i < n; i++) {
ans[s[i] - 'a'] += cnt[i];
}
for (int i = 0; i < 26; i++) {
cout << ans[i] << " ";
}
cout << endl;
}
}
|
#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 (m <= 0) 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>
using namespace std;
long long GCD(long long a, long long b) {
return (a % b) == 0 ? b : GCD(b, a % b);
}
long long mod(long long x) { return ((x % 998244353 + 998244353) % 998244353); }
bool cmp(const pair<int, int> &left, const pair<int, int> &right) {
return left.first > right.first ||
(left.first == right.first && left.second < right.second);
}
int main() {
int t, cs = 1;
cin >> t;
while (t--) {
long long n, m, a, b, c, i, j, k, mx = 0, mn = 1e18;
long long p[205] = {0}, ar[200005], cnt[200005] = {0};
string s;
cin >> n >> m;
cin >> s;
for (i = 0; i < m; i++) {
scanf("%lld", &ar[i]);
cnt[ar[i] - 1]++;
}
for (i = n - 1; i > 0; i--) {
cnt[i - 1] += cnt[i];
}
for (j = 0; j < n; j++) {
p[s[j]] += cnt[j] + 1;
}
for (i = 'a'; i <= 'z'; i++) {
printf("%lld ", p[i]);
}
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int test;
int arr[26];
int main() {
cin >> test;
for (int i = 0; i < test; i++) {
int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<int> p(n);
for (int i = 0; i < 26; i++) {
arr[i] = 0;
}
for (int j = 0; j < m; j++) {
int val;
cin >> val;
p[val - 1]++;
}
int counter = 1;
for (int a = n - 1; a >= 0; a--) {
counter = counter + p[a];
arr[s[a] - 'a'] += counter;
}
for (int r = 0; r < 26; r++) {
if (r == 25) {
cout << arr[25] << endl;
} else {
cout << arr[r] << " ";
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long t, n, c2, c3, sum, m, mn, k, r;
map<long long, long long> mp;
bool isPrime(int x) {
for (int i = 2; i * i <= x; i++)
if (x % i == 0) return false;
return true;
}
int main(void) {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
;
cin >> t;
while (t--) {
map<long long, long long> cum;
map<long long, long long> freq;
map<long long, long long> out;
cin >> n >> m;
string s;
cin >> s;
long long *a = new long long[m + 1];
for (int i = 0; i < m; i++) {
cin >> a[i];
freq[0]++;
freq[a[i]]--;
}
cum[0] = freq[0];
for (int i = 1; i < n; i++) {
cum[i] = freq[i];
cum[i] += cum[i - 1];
}
for (int i = 0; i < s.length(); i++) cum[i]++;
for (int i = 0; i < n; i++) out[s[i] - 'a'] += cum[i];
for (int i = 0; i < 26; i++) {
cout << out[i] << " ";
}
cout << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n = 0;
cin >> n;
long long mp = 0, mc = 0, is = 1;
do {
long long p, c;
cin >> p >> c;
if ((p < mp || c < mc || c > p || p - mp < c - mc) && is) {
cout << "NO" << endl;
is = 0;
}
mp = p;
mc = c;
} while (--n);
if (is) cout << "YES" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 5;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
int t;
cin >> t;
while (t--) {
int n, p, c;
cin >> n;
vector<pair<int, int>> v;
for (int i = 0; i < n; i++) {
cin >> p >> c;
v.push_back({p, c});
}
bool ok = 1;
for (int i = 0; i < n; i++) {
if (i + 1 < n && v[i].first == v[i + 1].first &&
v[i].second == v[i + 1].second)
continue;
if ((i + 1 < n && v[i].first > v[i + 1].first) ||
(i + 1 < n && v[i].second > v[i + 1].second) ||
v[i].first < v[i].second ||
(i + 1 < n &&
(v[i + 1].first - v[i].first) < (v[i + 1].second - v[i].second))) {
ok = 0;
break;
}
}
cout << (ok ? "YES" : "NO") << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 15;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
int n;
int main() {
int T;
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
int la = 0, lb = 0;
bool f = 1;
for (int i = 0, a, b; i < n; i++) {
scanf("%d%d", &a, &b);
if (a < la || b < lb) f = 0;
if (a - la < b - lb) f = 0;
la = a;
lb = b;
}
if (f)
puts("YES");
else
puts("NO");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n;
long long x, y, contp, contw;
cin >> t;
for (int i = 0; i < t; i++) {
cin >> n;
string r = "YES";
contw = 0, contp = 0;
for (int j = 0; j < n; j++) {
cin >> x >> y;
if ((x < contp || y < contw)) r = "NO";
if (y >= contw && x >= contp) {
if (y - contw > x - contp) r = "NO";
}
contw = y, contp = x;
}
cout << r << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<pair<int, int> > a(n, make_pair(0, 0));
for (int i = 0; i < n; i++) {
int x, b;
cin >> x >> b;
a[i] = make_pair(x, b);
}
if (a[0].first < a[0].second) {
cout << "NO" << endl;
return;
}
for (int i = 1; i < n; i++) {
if (a[i].first == a[i - 1].first && a[i].second == a[i - 1].second &&
a[i].first >= a[i].second)
continue;
else if (a[i].first > a[i - 1].first && a[i].second >= a[i - 1].second &&
(a[i].second - a[i - 1].second) <= (a[i].first - a[i - 1].first) &&
a[i].first >= a[i].second)
continue;
else {
cout << "NO" << endl;
return;
}
}
cout << "YES" << endl;
return;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int b[100013];
int aa[100013];
int main() {
std::ios::sync_with_stdio(false);
std::ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
for (int q = 1; q <= t; ++q) {
int n;
cin >> n;
int cnt = 1;
int p1 = 0, p2 = 0;
for (int w = 1; w <= n; ++w) {
int r1, r2;
cin >> r1 >> r2;
if (r2 > r1 || r1 - p1 < 0 || r2 - p2 < 0 || r1 - p1 < r2 - p2) cnt = 0;
p1 = r1;
p2 = r2;
}
if (cnt == 0) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, flag;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
scanf("%d", &n);
flag = 1;
int p, c, x, y;
p = 0;
c = 0;
for (int j = 0; j < n; j++) {
scanf("%d%d", &x, &y);
if (x < p || y < c || y - c > x - p) flag = 0;
p = x;
c = y;
}
flag == 1 ? printf("YES\n") : printf("NO\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long N = 500030;
const long long mod = 998244353;
bool comp(pair<int, int> p1, pair<int, int> p2) {
return (p1.first > p1.first ||
((p1.first == p2.first) && (p1.second > p2.second)));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<pair<int, int> > vp;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
vp.push_back({x, y});
}
bool b = false;
for (int i = 0; i < n; i++) {
if (vp[i].first < vp[i].second) b = true;
}
int x = vp[0].first - vp[0].second;
for (int i = 1; i < n; i++) {
if (vp[i].first - vp[i].second < x) {
b = true;
break;
}
if (vp[i].first < vp[i - 1].first || vp[i].second < vp[i - 1].second)
b = true;
if (vp[i].first == vp[i - 1].first && (vp[i].second != vp[i - 1].second))
b = true;
x = vp[i].first - vp[i].second;
}
if (b)
cout << "NO\n";
else
cout << "YES\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
long long int a, b;
long long int c = 0, d = 0;
long long int f = 0;
for (long long int i = 0; i < n; i++) {
cin >> a >> b;
if (a < c || b < d || a - c < b - d) f = 1;
c = a, d = b;
}
if (f)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int tt;
cin >> tt;
while (tt--) {
int n;
cin >> n;
std::vector<pair<int, int>> vec(n);
bool flag = true;
for (int i = 0; i < n; i++) {
cin >> vec[i].first >> vec[i].second;
if (vec[i].first < vec[i].second) {
flag = false;
}
}
for (int i = 1; i < n; i++) {
if (vec[i].first < vec[i - 1].first ||
vec[i].second < vec[i - 1].second) {
flag = false;
}
if (vec[i].first - vec[i - 1].first < vec[i].second - vec[i - 1].second) {
flag = false;
}
}
flag ? cout << "YES\n" : cout << "NO\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int num = 1e3 + 10;
int a[num], b[num];
int main() {
int t, n;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
a[0] = b[0] = 0;
int f = 1;
for (int i = 1; i <= n; i++) {
scanf("%d%d", &a[i], &b[i]);
if (b[i] < b[i - 1]) f = 0;
if (a[i] < a[i - 1]) f = 0;
if (a[i] < b[i]) f = 0;
if (a[i] == a[i - 1]) {
if (b[i] != b[i - 1]) f = 0;
}
if (a[i] > a[i - 1]) {
if (a[i] - a[i - 1] < b[i] - b[i - 1]) f = 0;
}
}
printf(f ? "YES" : "NO");
if (t) printf("\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool comp(string a, string b) { return a.length() < b.length(); }
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> p;
vector<int> c;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
p.push_back(x);
c.push_back(y);
}
bool flag = true;
if (p[0] < c[0]) {
cout << "NO" << endl;
continue;
}
for (int i = 1; i < n; i++) {
if (p[i] - p[i - 1] < 0) {
flag = false;
break;
}
if (p[i] - p[i - 1] < c[i] - c[i - 1]) {
flag = false;
break;
}
if (c[i] - c[i - 1] < 0) {
flag = false;
break;
}
if (c[i] > p[i]) {
flag = false;
break;
}
}
if (n == 1) {
if (p[0] == c[0] || p[0] >= c[0]) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
continue;
}
if (flag == false) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1e2 + 10;
int a[maxn];
int b[maxn];
int main() {
int T;
scanf("%d", &T);
while (T--) {
int n;
scanf("%d", &n);
int flag = 0;
for (int i = 1; i <= n; i++) {
scanf("%d%d", &a[i], &b[i]);
int tmp1 = a[i] - a[i - 1];
int tmp2 = b[i] - b[i - 1];
if (tmp1 < 0 || tmp2 < 0)
flag = -1;
else if (tmp1 < tmp2)
flag = -1;
}
if (flag == -1)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
vector<int> v(t);
for (int i = 0; i < t; i++) {
int n;
cin >> n;
v[i] = 1;
vector<vector<int> > test(n, vector<int>(2));
for (int a = 0; a < n; a++) {
for (int b = 0; b < 2; b++) {
cin >> test[a][b];
}
}
if (test[0][1] > test[0][0])
v[i] = 0;
else {
for (int a = 0; a < n - 1; a++) {
for (int b = 0; b < 2; b++) {
if (test[a + 1][0] < test[a][0] || test[a + 1][1] < test[a][1]) {
v[i] = 0;
break;
} else if ((test[a + 1][1] - test[a][1]) >
(test[a + 1][0] - test[a][0])) {
v[i] = 0;
break;
}
}
}
}
}
for (int i = 0; i < t; i++) {
if (v[i] == 1)
cout << "\nYES";
else
cout << "\nNO";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a, b, a1, b1, k = 0;
cin >> a1 >> b1;
if (a1 < b1) k = -1;
for (int i = 0; i < n - 1; i++) {
cin >> a >> b;
if (a < a1 || (b < b1) || (a - a1 < b - b1) || (a < b)) k = -1;
a1 = a;
b1 = b;
}
if (k == -1)
cout << "NO";
else
cout << "YES";
cout << endl;
}
}
|
#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;
cin >> n;
int p[n], c[n];
for (int i = 0; i < n; i++) {
cin >> p[i] >> c[i];
}
bool possible = true;
if (c[0] > p[0]) possible = false;
for (int i = 1; i < n; i++) {
if (c[i] < c[i - 1] || p[i] < p[i - 1] ||
c[i] - c[i - 1] > p[i] - p[i - 1]) {
possible = false;
break;
}
}
if (possible) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x7fffffffffffffff;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const int N = 1e5 + 5;
clock_t start, finish;
void time_in() { start = clock(); }
void time_out() {
finish = clock();
double tim = (double)(finish - start) / CLOCKS_PER_SEC;
printf("Running time is %lf\n", tim);
}
inline long long mul(long long a, long long b) {
long long s = 0;
while (b) {
if (b & 1) s = (s + a) % 1000000007;
a = (a << 1) % 1000000007;
b >>= 1;
}
return s % 1000000007;
}
inline long long pow_mul(long long a, long long b) {
long long s = 1;
while (b) {
if (b & 1) s = mul(s, a);
a = mul(a, a);
b >>= 1;
}
return s;
}
inline long long poww(long long a, long long b) {
long long s = 1;
while (b) {
if (b & 1) s = (s * a) % 1000000007;
a = (a * a) % 1000000007;
b >>= 1;
}
return s % 1000000007;
}
inline int read() {
char c = getchar();
int sgn = 1, ret = 0;
while (c != '-' && (c < '0' || c > '9')) c = getchar();
if (c == '-') sgn = -1, c = getchar();
while (c >= '0' && c <= '9') ret = ret * 10 + c - 48, c = getchar();
return ret * sgn;
}
void write(int x) {
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
inline long long phi(long long x) {
long long ans = x;
for (long long i = 2; i * i <= x; i++)
if (x % i == 0) {
ans -= ans / i;
while (x % i == 0) x /= i;
}
if (x > 1) ans -= ans / x;
return ans;
}
long long inv(long long down) {
return down == 1
? 1
: ((1000000007 - 1000000007 / down) * inv(1000000007 % down)) %
1000000007;
}
int a[105] = {0}, b[105] = {0};
int main() {
int T;
scanf("%d", &T);
while (T--) {
int n, f = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d %d", &a[i], &b[i]);
if (a[i] < a[i - 1] || b[i] < b[i - 1]) f = 1;
if (b[i] - b[i - 1] > a[i] - a[i - 1]) f = 1;
}
if (f)
printf("NO\n");
else
printf("YES\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long mxi = 100005;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
;
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long t1 = -1, t2 = -1;
long long fl = 0;
int cur1, cur2;
for (int i = 0; i < n; i++) {
long long x, y;
cin >> x >> y;
if (!i) {
t1 = max(t1, x);
t2 = max(t2, y);
cur1 = x;
cur2 = y;
}
if (x < t1 || x < y || y < t2 || (x - cur1) < (y - cur2)) {
fl = 1;
}
cur1 = x;
cur2 = y;
t1 = max(t1, x);
t2 = max(t2, y);
}
if (fl) {
cout << "NO\n";
} else {
cout << "YES\n";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int tc, n, p1, c1, p2, c2;
bool valid;
scanf("%d", &tc);
while (tc--) {
scanf("%d", &n);
p1 = c1 = 0;
valid = true;
while (n--) {
scanf("%d %d", &p2, &c2);
if ((p2 < p1) || (c2 < c1) || (p2 - c2 < p1 - c1)) valid = false;
p1 = p2;
c1 = c2;
}
if (valid)
puts("YES");
else
puts("NO");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int p[n], c[n];
for (int i = 0; i < n; i++) {
cin >> p[i] >> c[i];
}
bool k = true;
for (int i = 0; i < n; i++)
if (p[i] < c[i]) k = false;
for (int i = 1; i < n; i++) {
if (p[i] < p[i - 1] || c[i] < c[i - 1] || c[i] > p[i] ||
c[i] - c[i - 1] > p[i] - p[i - 1]) {
k = false;
break;
}
}
if (k)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n;
int p[N], c[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T;
cin >> T;
while (T--) {
cin >> n;
bool success = true;
for (int i = 1, d = 0; i <= n; i++) {
cin >> p[i] >> c[i];
if (p[i] < c[i] || p[i] < p[i - 1] || c[i] < c[i - 1] || p[i] - c[i] < d)
success = false;
d = p[i] - c[i];
}
cout << (success ? "YES" : "NO") << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int p = 0, q = 0, ok = 1;
while (n--) {
int a, b;
cin >> a >> b;
if (a - p < b - q) ok = false;
if (p > a || q > b) ok = false;
if (a < b) ok = false;
p = a, q = b;
}
cout << (ok ? "YES" : "NO") << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, p = 0;
cin >> n;
int a[n];
int c = 0;
int b[n];
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
for (int i = 0; i < n; i++) {
if (a[i] >= b[i]) {
p++;
} else {
p = 0;
cout << "NO" << endl;
break;
}
}
if (n == 1 && p != 0) {
if (a[0] >= b[0]) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
if (p == n) {
for (int i = 0; i < n - 1; i++) {
if (b[i + 1] > b[i]) {
long long int x = a[i + 1] - a[i];
if (a[i + 1] > a[i] && x >= (b[i + 1] - b[i])) {
c = 1;
} else {
c = 0;
cout << "NO" << endl;
break;
}
}
if (b[i + 1] == b[i]) {
if (a[i + 1] >= a[i]) {
c = 1;
} else if (a[i + 1] < a[i]) {
c = 0;
cout << "NO" << endl;
break;
}
}
if (a[i + 1] < a[i]) {
c = 0;
cout << "NO" << endl;
break;
}
if (b[i + 1] < b[i]) {
c = 0;
cout << "NO" << endl;
break;
}
if (a[i + 1] > a[i]) {
if (b[i + 1] >= b[i]) {
c = 1;
} else {
c = 0;
cout << "NO" << endl;
break;
}
}
if (a[i + 1] == a[i]) {
if (b[i + 1] == b[i]) {
c = 1;
} else {
c = 0;
cout << "NO" << endl;
break;
}
}
}
if (c == 1) {
cout << "YES" << endl;
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long q;
cin >> q;
while (q--) {
long long i, j, k, l, m, n, NO = 0;
cin >> n;
vector<pair<long long, long long> > vec;
for (i = 1; i <= n; i++) {
cin >> k >> l;
vec.push_back(make_pair(k, l));
if (i == 1 && vec[0].first < vec[0].second)
NO++;
else {
for (j = 1; j < vec.size(); j++) {
if (vec[j].first < vec[j - 1].first ||
vec[j].second < vec[j - 1].second ||
vec[j].first < vec[j].second ||
(vec[j].first - vec[j - 1].first <
vec[j].second - vec[j - 1].second))
NO++;
}
}
}
if (NO > 0)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct pc {
int p;
int c;
};
int main() {
int t;
cin >> t;
for (int i = 0; i < t; i++) {
int n;
cin >> n;
vector<pc> v;
v.resize(n);
bool correct = true;
for (int j = 0; j < n; j++) {
cin >> v[j].p >> v[j].c;
}
for (int j = 0; j < n; j++) {
if (v[j].p < v[j].c) {
correct = false;
break;
}
if (j > 0 && ((v[j].p - v[j].c) < (v[j - 1].p - v[j - 1].c) ||
(v[j].p < v[j - 1].p) || (v[j].c < v[j - 1].c))) {
correct = false;
break;
}
}
if (correct)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n;
cin >> n;
vector<long long int> p(n), c(n);
for (long long int i = 0; i < n; i++) {
cin >> p[i] >> c[i];
}
bool flag = true;
if (p[0] < c[0]) flag = false;
for (long long int i = 1; i < n; i++) {
if (p[i] < c[i]) {
flag = false;
break;
} else if (p[i] < p[i - 1] || c[i] < c[i - 1]) {
flag = false;
break;
} else if (p[i] - p[i - 1] < c[i] - c[i - 1]) {
flag = false;
break;
}
}
if (flag)
cout << "YES\n";
else
cout << "NO\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void ZZ(const char* name, Arg1&& arg1) {
std::cerr << name << " = " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void ZZ(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
std::cerr.write(names, comma - names) << " = " << arg1;
ZZ(comma, args...);
}
template <typename Arg1>
void outn(Arg1&& arg1) {
cout << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void outn(Arg1&& arg1, Args&&... args) {
cout << arg1 << " ";
outn(args...);
}
template <typename Arg1>
void outs(Arg1&& arg1) {
cout << arg1 << " ";
}
template <typename Arg1, typename... Args>
void outs(Arg1&& arg1, Args&&... args) {
cout << arg1 << " ";
outs(args...);
}
template <typename Arg1>
void inp(Arg1&& arg1) {
cin >> arg1;
}
template <typename Arg1, typename... Args>
void inp(Arg1&& arg1, Args&&... args) {
cin >> arg1;
inp(args...);
}
inline long long int mulm(long long int a, long long int b, long long int m) {
a = ((a % m) * (b % m)) % m;
return a;
}
template <typename T>
T expo(T e, T n) {
T x = 1, p = e;
while (n) {
if (n & 1) x = x * p;
p = p * p;
n >>= 1;
}
return x;
}
template <typename T>
T powerm(T e, T n, T m) {
T x = 1, p = e;
while (n) {
if (n & 1) x = mulm(x, p, m);
p = mulm(p, p, m);
n >>= 1;
}
return x;
}
inline long long int subm(long long int a, long long int b, long long int m) {
a = (a - b + m) % m;
return a;
}
inline long long int addm(long long int a, long long int b, long long int m) {
a = (a + b) % m;
return a;
}
inline void unset_bit_at(long long int& n, long long int b) {
n &= ~(1ll << b);
}
inline void set_bit_at(long long int& n, long long int b) { n |= (1ll << b); }
inline long long int is_setat(long long int n, long long int b) {
return (n >> b) & 1;
}
inline long long int get_lastsetbit(long long int n) { return n & (-n); }
inline long long int pow2(long long int n) { return (1ll << n); }
const long long int MOD = 1000000007;
const long long int MX6 = 5000005;
const long long int MAX = 1234567;
const long long int MX5 = 500005;
const long long int INF = 1e18 + 7;
const long long int MX3 = 5005;
long long int n;
bool dp[1005][1005];
void solve() {
inp(n);
vector<pair<long long int, long long int> > stat(n);
bool ok = true;
for (long long int i = 0; i < n; i++) {
cin >> stat[i].first >> stat[i].second;
}
for (long long int i = 0; i < n; i++) {
if (stat[i].second > stat[i].first) {
outs("NO");
return;
}
}
for (long long int i = 1; i < n; i++) {
if (stat[i].first == stat[i - 1].first) {
if (stat[i].second != stat[i - 1].second) {
outs("NO");
return;
}
} else if (stat[i].first > stat[i - 1].first) {
if (stat[i].second < stat[i - 1].second) {
outs("NO");
return;
} else if (stat[i].second > stat[i - 1].second) {
long long int playdiff = stat[i].first - stat[i - 1].first;
long long int clrdiff = stat[i].second - stat[i - 1].second;
if (clrdiff > playdiff) {
outs("NO");
return;
}
}
} else {
outs("NO");
return;
}
if (stat[i].first - stat[i].second < stat[i - 1].first - stat[i].second) {
outs("NO");
return;
}
}
outs("YES");
}
int32_t main() {
long long int t;
t = 1;
cin.sync_with_stdio(0), cin.tie(0);
cin >> t;
while (t--) {
solve();
cout << "\n";
;
}
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.