Codeforces Round #814 (Div. 2) C . Fighting Tournament(模拟)

https://codeforces.com/contest/1719/problem/C

n名运动员参加锦标赛,编号从1到n .布伦卡将第i名运动员的实力确定为整数ai,其中1≤ai≤n .所有的实力值都是不同的,即数组a是长度为n的排列.我们知道,在一场搏击中,如果ai>aj,那么第i名参与者总是赢第j名.

锦标赛是这样的:最初,所有n名运动员按照id的升序排列,然后有无限多个战斗回合。在每一轮比赛中,只有一场比赛:排在最前面的两个人出来比赛。胜利者回到队伍的前面,失败者回到后面。

布伦卡决定问汤娅一些问题。在每一个问题中,Burenka都会询问第i个参与者在比赛的前k轮中,对于某些给定的数字i和k,获得了多少次胜利。Tonya不太擅长分析,所以他请你帮助他回答所有问题。

给定号码数以及回合数,问在这k次回合中这个人赢了多少次?
input
3
3 1
3 1 2
1 2
4 2
1 3 4 2
4 5
3 2
5 2
1 2 3 5 4
5 1000000000
4 6
output
2
0
1
0
4
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
int a[N],b[N];
string s;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        LL n,q;
        cin>>n>>q;
        LL maxn=0;
        map<int,int> mp;
        map<int,int> num;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            num[i]=a[i];
            if(i==1) maxn=a[1];
            else
            {
                if(a[i]>maxn) maxn=a[i];
                mp[maxn]++;
            }
        }
        for(int i=1;i<=n;i++) cout<<mp[a[i]]<<" "; cout<<endl;
        while(q--)
        {
            int idx,t;
            cin>>idx>>t;
            int sum=num[idx];
            //如果是回合都还达不到这个位置或者说本来就是为0的,就安心输出0就好了哇
            if(t<idx-1||!mp[sum]) cout<<"0"<<endl;
            else if((idx==1&&t>=mp[sum])||(idx!=1&&t>=(idx+mp[sum]-1)))
            {//如果是妥妥的会超出外边
                if(idx==1&&sum==maxn) cout<<t<<endl;
                else if(t<=n-1||sum!=maxn) cout<<mp[sum]<<endl;
                else cout<<t-(idx-2)<<endl;
                //最大数字的话就直接-了
            }
            else//如果是卡在操作内的话
            {
                if(idx!=1) cout<<t-idx+2<<endl;
                else cout<<t-idx+1<<endl;
            }
        }
    }
    return 0;
}
posted @ 2022-08-17 14:13  高尔赛凡尔娟  阅读(133)  评论(0编辑  收藏  举报