QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#120220#6608. Descent of Dragonsshr_WA 1ms9096kbC++144.2kb2023-07-06 15:07:222023-07-06 15:07:22

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-06 15:07:22]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9096kb
  • [2023-07-06 15:07:22]
  • 提交

answer

# include <bits/stdc++.h>
using namespace std;
int n,m;
struct operation { int opt,l,r,x;} op[500010];
struct Blocks {
    int n,B,a[500010],v[1010],ans[500010];
    struct Block {
        int ans,lm;
        struct List {
            short hd[500010],tl[500010];
            struct node { int pre,nxt,x;} f[1010];
        } li;
    } b;
    int get_k_(int x) { return (x-1)/B+1;}
    int get_l_(int k) { return (k-1)*B+1;}
    int get_r_(int k) { return min(k*B,n);}
    void pushdown_(int k) {
        if (!b.lm) return;
        int l=get_l_(k),r=get_r_(k);
        int vr=0;
        for (int i=1;i<=r-l+1;i++) if (!b.li.f[i].pre) v[++vr]=b.li.f[i].x;
        for (int j=1;j<=vr;j++) for (int i=b.li.hd[v[j]];i;i=b.li.f[i].nxt) a[i+l-1]=v[j];
        for (int i=1;i<=r-l+1;i++) b.li.f[i].x=b.li.f[i].pre=b.li.f[i].nxt=0;
        for (int i=1;i<=vr;i++) b.li.hd[v[i]]=b.li.tl[v[i]]=0;
        b.ans=0;
    }
    void pushup_(int k) {
        if (!b.lm) return;
        int l=get_l_(k),r=get_r_(k);
        for (int i=l;i<=r;i++) b.ans=max(b.ans,a[i]);
        for (int i=l;i<=r;i++) 
            if (b.li.tl[a[i]]) b.li.f[b.li.tl[a[i]]].nxt=i-l+1, b.li.f[i-l+1].pre=b.li.tl[a[i]], b.li.tl[a[i]]=i-l+1;
            else b.li.hd[a[i]]=b.li.tl[a[i]]=i-l+1, b.li.f[i-l+1].x=a[i];
        b.lm=0;
    }
    void init_(int _n) { n=_n, B=sqrt(n), memset(a,0,sizeof(a));}
    void work_(int m,operation *op,vector<int> &v) {
        for (int i=1;get_l_(i)<=n;i++) {
            pushup_(i);
            for (int j=1;j<=m;j++) if (get_k_(op[j].l)<=i&&i<=get_k_(op[j].r)) {
                int lk=get_k_(op[j].l),rk=get_k_(op[j].r);
                if (op[j].opt==1) {
                    if (lk==rk) {
                        pushdown_(i);
                        for (int k=op[j].l;k<=op[j].r;k++) if (a[k]==op[j].x) a[k]++;
                        pushup_(i);
                    }
                    else if (i==lk) {
                        pushdown_(i);
                        for (int k=op[j].l;k<=get_r_(lk);k++) if (a[k]==op[j].x) a[k]++;
                        pushup_(i);
                    }
                    else if (i==rk) {
                        pushdown_(i);
                        for (int k=get_l_(rk);k<=op[j].r;k++) if (a[k]==op[j].x) a[k]++;
                        pushup_(i);
                    }
                    else if (b.li.hd[op[j].x]) {
                        if (!b.li.hd[op[j].x+1]) b.li.f[b.li.hd[op[j].x]].x++, b.li.hd[op[j].x+1]=b.li.hd[op[j].x], b.li.tl[op[j].x+1]=b.li.tl[op[j].x];
                        else b.li.f[b.li.tl[op[j].x+1]].nxt=b.li.hd[op[j].x], b.li.f[b.li.hd[op[j].x]].pre=b.li.tl[op[j].x+1], b.li.tl[op[j].x+1]=b.li.hd[op[j].x];
                        b.li.hd[op[j].x]=b.li.tl[op[j].x]=0, b.ans=max(b.ans,op[j].x+1), b.lm=1;
                    }
                }
                else {
                    if (lk==rk) {
                        pushdown_(i);
                        for (int k=op[j].l;k<=op[j].r;k++) ans[j]=max(ans[j],a[k]);
                        pushup_(i);
                    }
                    else if (i==lk) {
                        pushdown_(i);
                        for (int k=op[j].l;k<=get_r_(lk);k++) ans[j]=max(ans[j],a[k]);
                        pushup_(i);
                    }
                    else if (i==rk) {
                        pushdown_(i);
                        for (int k=get_l_(rk);k<=op[j].r;k++) ans[j]=max(ans[j],a[k]);
                        pushup_(i);
                    }
                    else ans[j]=max(ans[j],b.ans);
                }
            }
            pushdown_(i);
        }

        for (int i=1;i<=m;i++) if (op[i].opt==2) v.push_back(ans[i]);
    }
} B;
int main() {
    // freopen("in.in","r",stdin);
    // freopen("out.out","w",stdout);
    // freopen("debt.in","r",stdin);
    // freopen("debt.out","w",stdout);

    scanf("%d%d",&n,&m);
    for (int i=1;i<=m;i++) {
        scanf("%d",&op[i].opt);
        if (op[i].opt==1) scanf("%d%d%d",&op[i].l,&op[i].r,&op[i].x);
        else scanf("%d%d",&op[i].l,&op[i].r);
    }

    B.init_(n);
    vector<int> ans;
    B.work_(m,op,ans);

    for (auto o : ans) printf("%d\n",o);

    fprintf(stderr,"%lf\n",clock()/1.0/CLOCKS_PER_SEC);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 9096kb

input:

5 5
1 3 5 0
1 1 4 1
1 1 5 2
2 2 2
2 4 5

output:

0
2

result:

wrong answer 2nd numbers differ - expected: '3', found: '2'