【BZOJ1012】最大数maxnumber,疯狂CE的线段树练习

传送门
思路:比较裸的线段树,单点修改区间查询,树状数组应该也可以做,不过上来CE不能忍(╯‵□′)╯︵┻━┻,最后发现read不能定义数组?只好改成orz了
代码:

/************************************************************** Problem: 1012 User: xiaoyimi Language: C++ Result: Accepted Time:900 ms Memory:10652 kb ****************************************************************/

#include<cstring>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define LL long long
using namespace std;
LL d,t;
int m,n,l,r;
LL orz[200001][2],tree[800010];
inline void update(LL x,int root,int begin,int end)
{
    if (begin==end) {tree[root]=x;return;}
    int mid=(begin+end)/2;
    if (l<=mid) update(x,root*2,begin,mid);
    else update(x,root*2+1,mid+1,end);
    tree[root]=max(tree[root*2],tree[root*2+1]);
}
inline LL get(int root,int begin,int end)
{
    if (l<=begin&&end<=r) return tree[root];
    int mid=(begin+end)/2;
    LL k=0;
    if (l<=mid) k=max(k,get(root*2,begin,mid));
    if (r>mid) k=max(k,get(root*2+1,mid+1,end));
    return k;
}
main()
{
    scanf("%d%lld",&m,&d);
    for (int i=1;i<=m;i++)
    {
        char ch=getchar();
        while (ch!='A'&&ch!='Q') ch=getchar();
        if (ch=='A') n++,orz[i][0]=2;
        else orz[i][0]=1;
        scanf("%lld",&orz[i][1]);
    }
    for (int i=1;i<=m;i++)
    if (orz[i][0]==1)
    l=r-orz[i][1]+1,t=get(1,1,n),printf("%lld\n",t);
    else l=++r,orz[i][1]=(orz[i][1]+t)%d,update(orz[i][1],1,1,n);
}

你可能感兴趣的:(【BZOJ1012】最大数maxnumber,疯狂CE的线段树练习)