There are nnn points in an array with index from 111 to nnn, and there are two operations to those points.
1: 1 x1 \ x1 x marking the point xxx is not available
2: 2 x2 \ x2 x query for the index of the first available point after that point (including xxx itself) .
Input
nqn\quad qnq
z1x1z_1 \quad x_1z1x1
⋮\vdots⋮
zqxqz_q\quad x_qzqxq
qqq is the number of queries, zzz is the type of operations, and xxx is the index of operations. 1≤x<n<1091≤x<n<10^91≤x<n<109, 1≤q<1061 \leq q<10^6 1≤q<106 and zzz is 111 or 222
Output
Output the answer for each query.
样例输入
5 3 1 2 2 2 2 1
样例输出
3 1
题意:每个人都有一个能力值ai,假如ai+m小于aj而且i<J那他就生气 然后生气度为j-i-1 找到每个人的最大生气度
思路:把所有数都放到优先队列,然后从后往前,从n到1,a[i]-m与队列顶部元素比较,顶部元素比a[i]小且坐标小于i,那么他们配对,弹出顶部元素,然后继续比较,直到顶部元素大于a[i],i--。最后剩下未弹出的就是输出-1
#include<stdio.h>
#include<math.h>
#include<vector>
#include<cstring>
#include<queue>
#include<iostream>
#include<algorithm>
#define maxn 7500000
using namespace std;
#include <unordered_map>
#include<map>
unordered_map<int,int>fa;
unordered_map<int,int>q1;
void init()
{
q1.clear();
fa.clear();
/*for(int i=1;i<=maxn-100;i++)
{
fa[i]=i;
//d[i]=1;
}*/
}
int Find(int x)
{
if(fa.count(x)==0) return x;
fa[x]=Find(fa[x]);
return fa[x];
}
void Merge(int x,int y)
{
x=Find(x);y=Find(y);
if(x!=y)
{
if(x>y)
{
fa[y]=x;
//d[y]+=d[x];
}
else fa[x]=y;
}
}
int main()
{
int n,q;
init();
scanf("%d %d",&n,&q);
while(q--)
{
int z1,x1;
scanf("%d %d",&z1,&x1);
//if(q!=1) printf("")
if(z1==1)
{
q1[x1]=1;
if(q1.count(x1-1)!=0)
{
//printf("x1=%d -1\n",x1);
Merge(x1,x1-1);
}
if(q1.count(x1+1)!=0)
{
//printf("x1=%d +1\n",x1);
Merge(x1,x1+1);
}
}
else
{
int w=Find(x1);
if(w==x1)
{
if(q1.count(w)!=0)
{
if(w==n) printf("-1\n");
else printf("%d\n",x1+1);
}
else printf("%d\n",x1);
}
else
{
if(w==n) printf("-1\n");
else printf("%d\n",w+1);
}
}
}
}