#include<bits/stdc++.h> #define endl '\n' #define int long long // #define x first // #define y second usingnamespace std; // typedef pair<int, int> PII;
voidsolve(){ int n; cin >> n; vector<int> a(n + 1); unordered_map<int, char> mp; for (int i = 1; i <= n; i++) { cin >> a[i]; } string s; cin >> s; s = " " + s; bool flag = true; for (int i = 1; i <= n; i++) { char c = s[i]; if (mp.count(a[i]) == 0) { mp[a[i]] = c; } else { if (mp[a[i]] != c) { flag = false; } } } if (flag) { cout << "YES" << endl; } else { cout << "NO" << endl; } }
signedmain(){ ios::sync_with_stdio(false), cin.tie(nullptr); int _ = 1; cin >> _; while (_--) { solve(); } return0; }
#include<bits/stdc++.h> #define endl '\n' #define int long long // #define x first // #define y second usingnamespace std; // typedef pair<int, int> PII;
voidsolve(){ int n, q; cin >> n >> q; vector<int> a(n + 1); int sum = 0; int odd = 0, even = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; if (a[i] % 2 == 0) even++; else odd++; } for (int i = 1; i <= q; i++) { int a, b; cin >> a >> b; if (a == 0) { // even += b sum += b * even; if (b % 2 == 1) { odd += even; even = 0; } } else { // odd += b sum += b * odd; if (b % 2 == 1) { even += odd; odd = 0; } } cout << sum << endl; } }
signedmain(){ ios::sync_with_stdio(false), cin.tie(nullptr); int _ = 1; cin >> _; while (_--) { solve(); } return0; }
#include<bits/stdc++.h> #define endl '\n' #define int long long // #define x first // #define y second usingnamespace std;
// typedef pair<int, int> PII;
voidsolve(){ int n; char c; string s; cin >> n >> c >> s; s = s + s; int res = -1; for (int i = 0; i < 2 * n; i++) { // 找到c if (s[i] == c) { // 找到最近的 g int j = i; for (; j < 2 * n; j++) { if (s[j] == 'g') { // 更新距离 res = max(res, j - i); break; } } i = j; } } cout << res << endl; }
signedmain(){ ios::sync_with_stdio(false), cin.tie(nullptr); int _ = 1; cin >> _; while (_--) { solve(); } return0; }