1058: [ZJOI2007]报表统计

洛谷上卡的太凶了。写线段树爆空间,写set爆时间,怎么都卡不过。

但是发现set在BZOJ上是能过的,于是就去A了一发。

一点都不爽,整天不知道在干什么,效率奇低无比。

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<set>
using namespace std;
#define rep(i,j,k) for(i=j;i<=k;++i)
#define per(i,j,k) for(i=j;i>=k;--i)
#define ll long long
#define db double
#define mkp(x,y) make_pair(x,y)
#define pii pair<int,int>
#define X first
#define Y second
#define cl T[num].lc
#define cr T[num].rc
const int N=500005,inf=500000001;
int a[N],b[N],n,m;
multiset<int>st1,st3;
multiset<int>::iterator wz[N];
set<int>st2;
int main(){
    int i,x,y;char s[13];
    multiset<int>::iterator ii;
    scanf("%d%d",&n,&m);
    st3.insert(-inf);st3.insert(inf);
    rep(i,1,n){
        scanf("%d",&a[i]);
        ii=st3.lower_bound(a[i]);
        st2.insert(*ii-a[i]);st2.insert(a[i]-*(--ii));
        st3.insert(b[i]=a[i]);
    }
    a[n+1]=-inf;
    rep(i,1,n)wz[i]=st1.insert(abs(a[i]-a[i+1]));
    while(m--){
        scanf("%s",s);
        if(s[0]=='I'){
            scanf("%d%d",&x,&y);
            st1.erase(wz[x]);
            st1.insert(abs(y-b[x]));wz[x]=st1.insert(abs(a[x+1]-y));
            ii=st3.lower_bound(y);
            st2.insert(*ii-y);st2.insert(y-*(--ii));
            st3.insert(b[x]=y);
        }
        else if(s[4]=='G')
            printf("%d\n",*st1.lower_bound(0));
        else
            printf("%d\n",*st2.lower_bound(0));
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值