题面
简化题面后
题意为给定一个数组,每次操作会改变一个数或查询一个数排序后的位置
无脑版:直接平衡树维护
可以发现在一个数组中如果只有一个数是无序的,那么可以直接用插排
O
(
N
)
O(N)
O(N)排序
code:by rsjw
#include <cstdio>
#include <algorithm>
using namespace std;
//King Asgore will lead us to the Bright!
//King Asgore will lead us to the Hope!
//King Asgore will lead us to the Dream!
//Now with a smile,
//Won't you be happy about this?
//Won't you be excited about this?
struct Asgore {
int num,val;
bool operator<(const Asgore &ri)const {
if(val==ri.val) return num<ri.num;
return val<ri.val;
}
} a[8010];
int f[8010];
void fl(int x) {
f[a[x].num]=x;
}
int main() {
freopen("sort.in","r",stdin);
freopen("sort.out","w",stdout);
int n,T,x,v,i,op;
scanf("%d%d",&n,&T);
for(i=1; i<=n; i++) scanf("%d",&a[i].val),a[i].num=i;
sort(a+1,a+n+1);
for(i=1; i<=n; i++) fl(i);
while(T--) {
scanf("%d%d",&op,&x);i=f[x];
if(op==1) {
scanf("%d",&v);
if(a[i].val>v) {
a[i].val=v;
for(; i>1; i--)
if(a[i]<a[i-1])
swap(a[i],a[i-1]),fl(i),fl(i-1);
else
break;
} else if(a[i].val<v) {
a[i].val=v;
for(; i<n; i++)
if(a[i+1]<a[i])
swap(a[i],a[i+1]),fl(i),fl(i+1);
else
break;
}
} else if(op==2) printf("%d\n",i);
}
return 0;
}