1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| #include <cstdio> #include <cstring> #include <cmath> #include <iostream> #include <iomanip> #include <set> #include <queue> #include <map> #include <algorithm> #include <vector> #define rep(i,a,n) for(int i=a;i<n;++i) #define per(i,a,n) for(int i=n-1;i>=a;--i) #define cl(x,a) memset(x,a,sizeof(x)) #define all(x) x.begin(),x.end() #define pb push_back #define np next_permutation #define mp make_pair #define fi first #define se second #define INF 0x3f3f3f3f #define eps 1e-8 using namespace std; const int maxn=1e5+5; const int maxl=26; const int maxm=1e5+5; typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pii; int num[100]; int main(){ ios::sync_with_stdio(false); int t,n,m,l,mmax=0; cin>>t; while(t--){ cin>>n>>m; queue<pii> q; cl(num,0); rep(i,0,n){ cin>>l; mmax=max(mmax,l); q.push(mp(i,l)); num[l]++; } int ans=0; while(!q.empty()){ pii temp=q.front();q.pop(); if(temp.second<mmax){ q.push(temp); } else{ ans++; if(!(--num[mmax])) while(!(num[mmax]) && mmax){mmax--;} if(temp.first==m) {cout<<ans<<endl;break;} } } } }
|