Advertisement
Zeinab_Hamdy

Untitled

Apr 9th, 2023
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define ull unsigned ll
  5. #define nl "\n"
  6. #define sz(x) int(x.size())
  7. #define NumOfDigit(w) log10(w) + 1
  8. #define fill(arr, val)  memset(arr, val , sizeof(arr))
  9. #define PI 3.141592654
  10. #define ceil(w, m) (((w) / (m)) + ((w) % (m) ? 1 : 0))
  11. #define all(v) v.begin(), v.end()
  12. #define rall(v) v.rbegin(), v.rend()
  13. #define fi first
  14. #define se second
  15. #define cin(v) for (auto&i:v) cin >> i;
  16. #define cout(v) for (auto&i:v) cout << i << " ";
  17. #define fixed(n) fixed << setprecision(n)
  18. //#define MOD  1e9 + 7
  19.  
  20.  
  21. void IO(){
  22.     ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  23. }
  24. void files(){
  25.     //freopen("filename.in" , "r" ,stdin);
  26.             #ifndef ONLINE_JUDGE
  27.               freopen("input.txt", "r", stdin);  freopen("output.txt", "w", stdout);
  28.             #endif
  29. }
  30.  
  31.  
  32.  
  33. void solve(){
  34. int n , m;
  35. cin >> n >> m ;
  36. vector < int > a(n) , b(m) , freq(305) , freq2(305);
  37.  
  38.  
  39. for(int i=0;i<n;i++){
  40.     cin >> a[i] ;
  41.     freq[a[i]]++;
  42. }
  43.  
  44. for(auto& i : b){
  45.     cin >> i;
  46.     freq2[i]++;
  47. }
  48.  
  49. for(int i=0;i<305;i++){
  50.     if(freq2[i] > freq[i]) return void(cout <<"NO\n");
  51.     if(freq2[i]==0 and freq[i]==1) return void(cout <<"NO\n");
  52. }
  53.  
  54. int j=0 ,sze ;
  55. for(int i=0;i<m;i++){
  56.     int t= j;
  57.     if( i !=0 and b[i]==b[i-1]){
  58.         if(sze>0) sze--;
  59.         else return void(cout <<"NO\n");
  60.         continue;
  61.     }
  62.    
  63.      while(j < n and a[j]!=b[i]) j++;
  64.  
  65.     while(j < n and a[j]==b[i]) j++;
  66.    
  67.      sze= j-t+1;
  68.     if(sze == 1 and i >0 and b[i]!=b[i-1]) return void(cout <<"NO\n");
  69.     sze--;
  70. }
  71. if( j == n)
  72.     cout <<"YES\n";
  73. else
  74.     cout <<"NO\n";
  75.  
  76. }
  77. int main(){
  78.                  IO();       //  files();
  79.  
  80.     int testCase=1;  // one test case
  81.    cin >> testCase ;      
  82.  while(testCase--)
  83.         solve();  // my code
  84.        
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement