fork download
  1. #include <iostream>
  2. #include <stack>
  3. using namespace std;
  4. #define ll long long
  5. int main()
  6. {
  7. int T;
  8. cin>>T;
  9. while(T--)
  10. {
  11. ll int N,M;
  12. cin>>N>>M;
  13. stack<ll int> S;
  14. ll int H[N],C[N];
  15. for(ll int i=0;i<N;i++){cin>>H[i];}
  16. for(ll int i=0;i<N;i++){cin>>C[i];}
  17. /// i made a stack which will keep the track of the color of wall
  18. ///stack the take index as input
  19. S.push(0);
  20.  
  21. for(ll int i=1;i<N;i++)
  22. {
  23. if(H[i]<H[S.top()])
  24. {
  25. if(C[i]!=C[S.top()]){S.push(i);}
  26. }
  27. else{
  28. while(H[i]>=H[S.top()])
  29. {
  30. S.pop();
  31. if(S.empty()){break;}
  32. }
  33. if(!S.empty()){
  34. if(C[S.top()]!=C[i]){
  35. S.push(i);}}
  36. else{S.push(i);}
  37. }
  38. }
  39. ll int ans=0;
  40. while(!S.empty())
  41. {
  42. S.pop();
  43. ans++;
  44. }
  45. cout<<ans<<endl;
  46. }
  47. return 0;
  48. }
  49.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:19:6: error: ‘s’ was not declared in this scope
      s.push(0);
      ^
stdout
Standard output is empty