QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#588320#6733. Moniphant SleepjunjunRE 0ms0kbC++143.6kb2024-09-25 09:31:262024-09-25 09:31:27

Judging History

你现在查看的是最新测评结果

  • [2024-09-25 09:31:27]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-09-25 09:31:26]
  • 提交

answer

#include<cstdio>
#include<cassert>
#define fix(x) ((x)>=INF?INF:(x))
#define ls(u) ((u)<<1)
#define rs(u) (((u)<<1)|1)
const int N=500005,INF=0x3f3f3f3f;
int n,q;
template<typename T>void read(T&x){
    x=0;
    char c=getchar();
    for(;c<'0'||c>'9';c=getchar());
    for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+(c^48);
}
struct Func{
    int a,b,c,d;//[0,b]:y=a [b,inf):y=x-b+c {inf}:y=d;
    Func(int _a=0,int _b=-1,int _c=-1,int _d=INF){
        a=_a,b=_b,c=_c,d=_d;
    }
    int operator()(int x){
        if(x==INF)return d;
        if(x<=b)return a;
        return fix(x+c-b);
    }
    void fit(){
        if(a<0)a=INF;
        if(c<-1)b-=c+1,c=-1;
        if(d<0)d=INF;
        a=fix(a),b=fix(b),c=fix(c),d=fix(d);
    }
    Func operator+(Func y){
        if(b==INF&&y.b==INF)return Func(fix(a+y.a),INF,0,fix(d+y.d));
        if(b==INF)return Func(fix(a+y.a),y.b,fix(a+y.c),fix(d+y.d));
        if(y.b==INF)return Func(fix(a+y.a),b,fix(c+y.a),fix(d+y.d));
        return Func();
    }
};
Func F(Func x,Func y){
    Func res;
    if(x.b==INF){
        res=Func(x.a,INF,0,x(y.d)),res.fit();
        return res;
    }
    if(y.b==INF){
        res=Func(x(y.a),INF,0,x(y.d)),res.fit();
        return res;
    }
    res.d=x(y.d),res.b=y.b,res.a=x(y.a);
    if(x.b>y.c)res.b+=x.b-y.c,res.a=x.a;
    res.c=x(y(res.b+1))-1,res.fit();
    return res;
}
Func flat(Func x){
    if(x.a==INF)x.a=0;
    if(x.d==INF)x.d=0;
    return x;
}
struct Tag{
    Func f,g;
    int d;
    bool add;
    Tag(Func _f=Func(0,INF,0,0),Func _g=Func(0,-1,-1,INF),int _d=0,bool _add=0){
        f=_f,g=_g,d=_d,add=_add;
    }
    Tag operator+(Tag y){
        Tag res;
        if(y.add)res.f=f+flat(F(y.f,g)),res.add=1;
        else res.f=f,res.add=add;
        res.d=d+y.d,res.g=F(y.g,g);
        return res;
    }
}ch[5];
struct Tree{
    int l,r;
    Tag t;
}tr[N<<2];
void init(){
    ch[1]=Tag(Func(0,INF,0,0),Func(0,-1,0,INF),1,0),ch[2]=Tag(Func(0,INF,0,0),Func(INF,0,-1,INF),-1,0);
    ch[3]=Tag(Func(0,INF,0,0),Func(0,-1,-1,0),0,0),ch[4]=Tag(Func(0,-1,-1,0),Func(INF,INF,0,INF),0,1);
}
inline void push(int u,Tag x){
    tr[u].t=tr[u].t+x;
}
inline void pushdown(int u){
    push(ls(u),tr[u].t),push(rs(u),tr[u].t),tr[u].t=Tag();
}
void build(int u,int l,int r){
    tr[u].l=l,tr[u].r=r;
    if(l==r)return;
    int mid=(l+r)>>1;
    build(ls(u),l,mid),build(rs(u),mid+1,r);
}
void modify(int u,int l,int r,int x){
    if(l<=tr[u].l&&r>=tr[u].r){
        push(u,ch[x]);
        return;
    }
    pushdown(u);
    int mid=(tr[u].l+tr[u].r)>>1;
    if(l<=mid)modify(ls(u),l,r,x);
    if(r>mid)modify(rs(u),l,r,x);
}
int query(int u,int p){
    if(tr[u].l==tr[u].r)return tr[u].t.d-tr[u].t.f(INF);
    pushdown(u);
    int mid=(tr[u].l+tr[u].r)>>1;
    if(p<=mid)return query(ls(u),p);
    else return query(rs(u),p);
}
int main(){
    freopen("dream.in","r",stdin),freopen("dream.out","w",stdout),read(n),read(q),build(1,1,n),init();
    for(int op,l,r;q--;){
        read(op),read(l),read(r);
        if(op==5)printf("%d\n",query(1,l)+500000);
        else modify(1,l,r,op);
        // for(int u=1;u<=9;u++){
        //     printf("%d %d\n",tr[u].l,tr[u].r);
        //     printf("%d %d %d %d\n",tr[u].t.f.a,tr[u].t.f.b,tr[u].t.f.c,tr[u].t.f.d);
        //     printf("%d %d %d %d\n",tr[u].t.g.a,tr[u].t.g.b,tr[u].t.g.c,tr[u].t.g.d);
        //     printf("%d %d\n",tr[u].t.d,(int)tr[u].t.add);
        //     puts("!!!");
        // }
        // puts("???");
    }
    return fflush(stdout),fclose(stdin),fclose(stdout),0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

1 9
1 1 1
1 1 1
1 1 1
3 1 1
2 1 1
1 1 1
1 1 1
4 1 1
5 1 1

output:


result: