Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using pii=pair<int,int>;
- vector <vector<int>> mp(2001,vector<int>(2001));
- int main(){
- int n,t;
- scanf("%d%d",&n,&t);
- int ar[n+1],srt[n+1];
- for(int i=1;i<=n;i++) {
- scanf("%d",&ar[i]);
- mp[0][ar[i]] = i;
- srt[i]=ar[i];
- }
- sort(srt+1,srt+n+1);
- int stop;
- for(int i=1;i<n;i++){
- bool check=true;
- for(int j=1;j<n;j++){
- if(ar[j]>ar[j+1]){
- swap(ar[j],ar[j+1]);
- if(ar[j]!=srt[j]) check=false;
- }
- mp[i][ar[j]]=j;
- }
- mp[i][ar[n]]=n;
- if(check) {
- stop=i;
- break;
- }
- }
- while(t--){
- int k,x;
- scanf("%d%d",&k,&x);
- if(k>stop) printf("%d\n",mp[stop][x]);
- else printf("%d\n",mp[k][x]);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment