Codeforces Round 923 (Div. 3) 1927 D. Find the Different Ones! Solution


 

Problem Link :  Problem Link : https://codeforces.com/contest/1927/problem/d

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t;
  8. cin >> t;
  9. while (t--) {
  10. int n ; cin >> n ;
  11. int a[n+1] ;
  12. for ( int i = 1 ; i <= n ; i++){
  13. cin >> a[i] ;
  14. }
  15. set<int>st ;
  16. for( int i = 2 ; i <= n ; i++){
  17. if(a[i] != a[i-1]){
  18. st.insert(i) ;
  19. }
  20. }
  21. int q ; cin >> q ;
  22. while(q--){
  23. int x , y ; cin >> x >> y ;
  24. auto it = st.upper_bound(x) ;
  25. if( it == st.end() or *it > y){
  26. cout <<"-1 -1\n";
  27. }
  28. else{
  29. int ans = *it ;
  30. cout << ans - 1 <<" "<< ans <<'\n';
  31. }
  32. }
  33. }
  34. return 0 ;
  35. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.