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++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- int n ; cin >> n ;
- int a[n+1] ;
- for ( int i = 1 ; i <= n ; i++){
- cin >> a[i] ;
- }
- set<int>st ;
- for( int i = 2 ; i <= n ; i++){
- if(a[i] != a[i-1]){
- st.insert(i) ;
- }
- }
- int q ; cin >> q ;
- while(q--){
- int x , y ; cin >> x >> y ;
- auto it = st.upper_bound(x) ;
- if( it == st.end() or *it > y){
- cout <<"-1 -1\n";
- }
- else{
- int ans = *it ;
- cout << ans - 1 <<" "<< ans <<'\n';
- }
- }
- }
- return 0 ;
- }
No comments