Submission #725793

#TimeUsernameProblemLanguageResultExecution timeMemory
725793CutebolAbracadabra (CEOI22_abracadabra)C++17
10 / 100
1414 ms21120 KiB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
   
using namespace std;
//using namespace __gnu_pbds;
   
//void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
//#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define Shenhe ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
#define int long long
#define pb push_back
#define ss second
#define sz size()
#define ff first

const int N = 2e5 + 5 ;
const int mod = 1e9+7 ;
const int inf = 1e18 ;
 
int n , q ;
int a[N] ;
int b[1005][1055] ;

void solve(){
	
	cin >> n >> q ;
	for ( int i = 0 ; i < n ; i ++ ) cin >> b[0][i] ;
	for ( int i = 1 ; i < n ; i ++ ){
		int l = 0 , r = n/2 ;
		for ( int j = 0 ; j < n ; j ++ ){
			if ( b[i-1][l] < b[i-1][r] ) b[i][j] = b[i-1][l] , l ++ ;
			else b[i][j] = b[i-1][r] , r ++ ;
			if ( l == n/2 ){
				j ++ ;
				for ( ; j < n ; j ++ ){
					b[i][j] = b[i-1][r] ;
					r ++ ;
				}
				break ;
			}
			if ( r == n ){
				j ++ ;
				for ( ; j < n ; j ++ ){
					b[i][j] = b[i-1][l] ;
					l ++ ;
				}
				break ;
			}
		}
	}
	while ( q -- ){
		int t , x ;
		cin >> t >> x ;
		cout << b[min(t,n-1)][x-1] << endl ;
	}
}
 
signed main(){
	Shenhe ;
	int t = 1 ;
//	cin >> t ;
	while ( t -- ) solve() ;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...