//関数使用時用入力44行目- #include #include using namespace std; using namespace atcoder; using ll=long long; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define int_max 2147483647 #define int_min -2147483647 #define uint_max 4294967295 #define ll_max 9223372036854775807 #define ll_min -9223372036854775807 #define ull_max 18446744073709551615 #define rep(i,n) for(ll i=0;i<(n);i++) #define reps(i,n) for(ll i=1;i<=(n);i++) #define REP(i,j,n) for(ll i=(j);i<(n);i++) #define all(a) (a).begin(), (a).end() #define veci vector #define veci2 vector> //veci2 A(a,veci(b)) #define vecll vector #define vecll2 vector> #define vecst vector #define repc(i,n,A) rep(i,n)cin>>A[i] #define repc2(i,n,A,B) rep(i,n)cin>>A[i]>>B[i] #define repc2vec(i,j,a,b,A) rep(i,a)rep(j,b)cin>>A[i][j] #define pb push_back #define mp make_pair #define Endl endl #define F first #define S second #define yes(b) ((b)?"yes":"no") #define Yes(b) ((b)?"Yes":"No") #define YES(b) ((b)?"YES":"NO") template inline T gcd(T a,T b) {return (b==0)?a:gcd(b,a%b);}//最大公約数 template inline T lcm(T a, T b) {return (a*b)/gcd(a,b);}//最小公倍数 veci dx={-1,0,1,-1,1,-1,0,1}; veci dy={-1,-1,-1,0,0,1,1,1}; veci DX={-1,1,0,0}; veci DY={0,0,-1,1}; int mod = 998244353; //ここからコード入力(関数使用時用) //関数 /*ll nibutan(ll K){ //二分探索 a=要素数 [m]の前配列名 ll ng=-1; ll ok=a; while(ok-ng>1){ ll m=(ng+ok)/2; if([m]>K)ok=m; else ng=m; } return ok; }*/ //ここからコード入力(   ´・ω・`    ) int main(){ int A,B,tmp1,tmp2; cin>>A>>B; vector>C(A); rep(i,A){ cin>>tmp1; C[i].F=tmp1; C[i].S=i; } sort(all(C)); mapD; mapE; rep(i,A){ if(i!=0){ if(tmp1==C[i].F)D[C[i].S]=tmp2; else{ D[C[i].S]=i; tmp1=C[i].F; tmp2=C[i].S; } }else{ D[C[i].S]=i; tmp1=C[i].F; tmp2=i; } } reps(i,A){ if(i!=1){ if(tmp1==C[A-i].F)E[C[A-i].S]=tmp2; else{ E[C[A-i].S]=A-i; tmp1=C[A-i].F; tmp2=A-i; } }else E[C[A-i].S]=A-i; tmp1=C[A-i].F; tmp2=A-i; } rep(i,B){ cin>>tmp1>>tmp2; if(D[tmp1-1]