fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int solve(vector<int>& a , int n , int x , int y){
  5. int ans = 0;
  6. for(int i=0;i<n;i++){
  7. int countX=0,countY=0;
  8. for(int j=i;j<n;j++){
  9. if(a[j]==x)countX++;
  10. else countY++;
  11.  
  12. if(countX==countY)ans++;
  13. }
  14. }
  15. return ans;
  16. }
  17.  
  18. int main() {
  19. int n;
  20. cin>>n;
  21. vector<int>a(n);
  22. for(int i=0;i<n;i++){
  23. cin>>a[i];
  24. }
  25. int x,y;
  26. cin>>x>>y;
  27. cout<<solve(a,n,x,y);
  28. return 0;
  29. }
Success #stdin #stdout 0.01s 5280KB
stdin
6
2 3 3 2 2 3
2 3
stdout
7