题目链接 hdoj 5493
题意 t组样例 给出n个人的身高 和左边或者右边比他高的人有k个
我们怎么分析呢? 首先 我们按照身高排序 当排到第i个人的时候 说明 后面的人一定比他高 前面的人不可能比他高 所以要满足这个k他在后面没排的人里面要吗是 第 n - i - k + 1 名(右边有k个) ,要吗是 k + 1名(左边有k个) 所以我们又想要字典序最小 我们只需要每次都去min这两个 然后不断的去完成这个队列 并且输出 如何找到这第tmp 个排名呢 就是我们树状数组和二分的经典运用了
/*
hdoj 5493
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
using namespace std;
const int MAX_N = 100024;
struct node {
int h,k;
bool operator < (const node other) const
{
if(h==other.h) return k < other.k;
return h < other.h;
}
}arr[MAX_N];
int ans[MAX_N];
int c[MAX_N];
void add(int x,int v){
for(;x<MAX_N