fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7.  
  8. const int M = 1000000007;
  9. const int N = 3e5+9;
  10. const int INF = 2e9+1;
  11. const int LINF = 2000000000000000001;
  12.  
  13. inline int power(int a, int b, int mod=M) {
  14. int x = 1;
  15. a %= mod;
  16. while (b) {
  17. if (b & 1) x = (x * a) % mod;
  18. a = (a * a) % mod;
  19. b >>= 1;
  20. }
  21. return x;
  22. }
  23.  
  24.  
  25. //_ ***************************** START Below *******************************
  26.  
  27.  
  28.  
  29.  
  30. vector<tuple<int,int,string>> a;
  31.  
  32. vector<string> consistency(int n){
  33.  
  34. vector<int>f1(26, 0);
  35. vector<int>f2(26, 0);
  36.  
  37. f1[0]++;
  38. f2[0]++;
  39.  
  40. vector<string> ans;
  41. for(int i=0; i<n; i++){
  42.  
  43. int tar = get<0>(a[i]);
  44. int freq = get<1>(a[i]);
  45. string wrd = get<2>(a[i]);
  46.  
  47.  
  48. for(auto& ch : wrd){
  49. if(tar == 1) f1[ch-'a'] += freq;
  50. else f2[ch-'a'] += freq;
  51. }
  52.  
  53. int s = 0;
  54. while(s<26 && f1[s] == 0) s++;
  55.  
  56. int e = 25;
  57. while(e>s && f2[e] == 0) e--;
  58.  
  59. //* guranteed case =>
  60. //* either s = xxxx yyyyy zzz .... OR s = xxxx
  61. //* and t = xx or xxxx or xxxxx
  62. if(e==s){
  63. bool moreInS = false;
  64. for(int j=s+1; j<26; j++){
  65. if(f1[j] != 0) {
  66. moreInS = true;
  67. break;
  68. }
  69. }
  70. if(moreInS) ans.push_back("NO");
  71.  
  72. else if(f2[s] > f1[s]) ans.push_back("YES");
  73. else ans.push_back("NO");
  74. }
  75. else{
  76. ans.push_back("YES");
  77. }
  78.  
  79. }
  80.  
  81.  
  82. return ans;
  83.  
  84. }
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. vector<string> practice(int n){
  101.  
  102.  
  103. }
  104.  
  105.  
  106.  
  107.  
  108.  
  109. void solve() {
  110.  
  111. int n;
  112. cin>> n;
  113.  
  114. a.resize(n);
  115. for(int i=0; i<n; i++){
  116. int x, y;
  117. string z;
  118. cin >> x >> y >> z;
  119. a[i] = {x,y,z};
  120. }
  121.  
  122. auto ans = consistency(n);
  123. for(auto& it : ans) cout << it << endl;
  124.  
  125.  
  126. }
  127.  
  128.  
  129.  
  130.  
  131.  
  132. int32_t main() {
  133. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  134.  
  135. int t = 1;
  136. cin >> t;
  137. while (t--) {
  138. solve();
  139. }
  140.  
  141. return 0;
  142. }
Success #stdin #stdout 0.01s 5288KB
stdin
3
5
2 1 aa
1 2 a
2 3 a
1 2 b
2 3 abca
2
1 5 mihai
2 2 buiucani
3
1 5 b
2 3 a
2 4 paiu
stdout
YES
NO
YES
NO
YES
NO
YES
NO
NO
YES