QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#557498#8672. 排队-xcxxx-Compile Error//C++143.0kb2024-09-11 09:59:192024-09-11 09:59:19

Judging History

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

  • [2024-09-11 09:59:19]
  • 评测
  • [2024-09-11 09:59:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int rd() {int x=0,f=1;char c=getchar();while(!isdigit(c))f=(c=='-'?-1:f),c=getchar();while(isdigit(c))x=x*10+c-'0',c=getchar();return x*f;}
const int N=1000005,inf=0x3f3f3f3f;
int n,Q,l[N],r[N],ans[N];
vector<int> ins[N],ers[N];
struct ChristmasTree {
    #define ls (p<<1)
    #define rs (p<<1|1)
    #define mid ((T[p].l+T[p].r)>>1)
    struct node {
        int l,r,mx,mn,tag;
        void upd(int x) {mx+=x,mn+=x,tag+=x;}
    }T[N<<2];
    void pushup(int p) {
        T[p].mx=max(T[ls].mx,T[rs].mx);
        T[p].mn=min(T[ls].mn,T[rs].mn);
    }
    void pushdown(int p) {
        T[ls].upd(T[p].tag);
        T[rs].upd(T[p].tag);
        T[p].tag=0;
    }
    void build(int l=1,int r=Q,int p=1) {
        T[p].l=l,T[p].r=r;
        T[p].mx=-inf,T[p].mn=inf;
        if(l==r) return;
        build(l,mid,ls);
        build(mid+1,r,rs);
    }
    void modify(int l,int r,int p=1) {
        if(T[p].l==l&&T[p].r==r) {
            T[p].upd(1);
            return;
        }
        pushdown(p);
        if(r<=mid) modify(l,mid,ls);
        else if(mid<l) modify(mid+1,r,rs);
        else modify(l,mid,ls),modify(mid+1,r,rs);
        pushup(p);
    }
    int qfst(int l,int r,int k,int p=1) {
        if(l==r) return l;
        pushdown(p);
        if(T[ls].mn<=k) return qfst(l,mid,k,ls);
        else return qfst(mid+1,r,k,rs);
    }
    int qlst(int l,int r,int k,int p=1) {
        if(l==r) return l;
        pushdown(p);
        if(T[rs].mx>=k) return qlst(mid+1,r,k,rs);
        else return qlst(l,mid,k,ls);
    }
    void insert(int pos,int p=1) {
        // fprintf(stderr,"insert [%d,%d] %d\n",T[p].l,T[p].r,pos);
        if(T[p].l==T[p].r) {
            T[p].mx=T[p].mn=0;
            return;
        }
        pushdown(p);
        if(pos<=mid) insert(pos,ls);
        else insert(pos,rs);
        pushup(p);
    }
    void erase(int pos,int p=1) {
        // fprintf(stderr,"erase [%d,%d] %d\n",T[p].l,T[p].r,pos);
        if(T[p].l==T[p].r) {
            T[p].mx=-inf,T[p].mn=inf;
            return;
        }
        pushdown(p);
        if(pos<=mid) erase(pos,ls);
        else erase(pos,rs);
        pushup(p);
    }
    int ask(int pos,int p=1) {
        if(T[p].l==T[p].r) return T[p].mx;
        pushdown(p);
        if(pos<=mid) return ask(pos,ls);
        else return ask(pos,rs);
    }
}tree;
signed main() {
    n=rd(),Q=rd();
    for(int i=1;i<=n;i++) l[i]=rd(),r[i]=rd();
    for(int i=1;i<=Q;i++) ins[rd()].push_back(i),ers[rd()].push_back(i);
    tree.build();
    for(int i=1;i<=n;i++) {
        // fprintf(stderr,"i=%d\n",i);
        for(int p:ins[i]) tree.insert(p);
        int L=tree.qfst(1,n,r[i]),R=tree.qlst(1,n,l[i]);
        tree.modify(L,R);
        for(int j=1;j<=4*Q;j++) pushdown(j);
        for(int p:ers[i]) {
            ans[p]=tree.ask(p);
            tree.erase(p);
        }
    }
    for(int i=1;i<=Q;i++) printf("%d\n",ans[i]);
    return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:93:33: error: ‘pushdown’ was not declared in this scope
   93 |         for(int j=1;j<=4*Q;j++) pushdown(j);
      |                                 ^~~~~~~~