QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#818474#5098. 第一代图灵机lgvc0 1018ms170928kbC++234.5kb2024-12-17 20:46:482024-12-17 20:46:50

Judging History

This is the latest submission verdict.

  • [2024-12-17 20:46:50]
  • Judged
  • Verdict: 0
  • Time: 1018ms
  • Memory: 170928kb
  • [2024-12-17 20:46:48]
  • Submitted

answer

#include <bits/stdc++.h>
#define LL long long
static char buf[1000000],*paa=buf,*pd=buf;
static char buf2[1000000],*pp=buf2;
#define getchar() paa==pd&&(pd=(paa=buf)+fread(buf,1,1000000,stdin),paa==pd)?EOF:*paa++
inline void pc(char ch){
    if(pp-buf2==1000000) fwrite(buf2,1,1000000,stdout),pp=buf2;
    *pp++=ch;
}
inline void pcc(){
    fwrite(buf2,1,pp-buf2,stdout);
    pp=buf2;
}
inline int read(void){
    register int x(0);register char c(getchar());
    while(c<'0'||c>'9')c=getchar();
    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x;
}
void write(LL x){
    static int sta[20];
    int top=0;
    do{
        sta[top++]=x%10,x/=10;
    }while(x);
    while(top) pc(sta[--top]+48);
}
void we(LL x){
    write(x);
    pc('\n');
}
int N,M,Q,ti,c[200009],la[200009],pre[200009],aa[200009],bb[200009];
std::set<int> ss[200009];
LL a[200009];
#define ls (n<<1)
#define rs ((n<<1)|1)
#define md ((l+r)>>1)
struct n_t{
    int p,v;
};
std::vector<n_t> op[530000];
int ck,ma[530000],laz[530000];LL vv[530000],ans[200009];
struct o_t{
    int la,ma,n;
    LL vv;
} oo[20000009];
void uu(int n,int l,int r,int L,int R,int p,int v) {
    if(r<L||R<l) return;
    if(L<=l&&r<=R) {
     //   printf("%d %d %d %d\n",l,r,p,v);
        if(v) op[n].push_back((n_t){p,v});
        return;
    }
    uu(ls,l,md,L,R,p,v);
    uu(rs,md+1,r,L,R,p,v);
}
void up(int n,int l,int r,int L,int R,int v) {
    if(r<L||R<l) return;
    if(L<=l&&r<=R) {
        laz[n]=ma[n]=v;
        vv[n]=a[r]-a[v];
        return;
    }
    oo[++ck]=(o_t){laz[ls],ma[ls],ls,vv[ls]};
    oo[++ck]=(o_t){laz[rs],ma[rs],rs,vv[rs]};
    if(laz[n]) {
        laz[ls]=laz[n];
        laz[rs]=laz[n];
        ma[ls]=laz[n];
        ma[rs]=laz[n];
        vv[ls]=a[md]-a[laz[n]];
        vv[rs]=a[r]-a[laz[n]];
        laz[n]=0;
    }
    up(ls,l,md,L,R,v);
    up(rs,md+1,r,L,R,v);
    ma[n]=ma[rs];
    vv[n]=std::max(vv[ls],vv[rs]);
}
LL qr(int n,int l,int r,int L,int R) {
    if(r<L||R<l) return 0;
    if(L<=l&&r<=R) {
        return vv[n];
    }
    if(laz[n]) return a[std::min(r,R)]-a[laz[n]];
    return std::max(qr(ls,l,md,L,R),qr(rs,md+1,r,L,R));
}
int fd(int n,int l,int r,int v) {
    if(ma[n]<v) return r+1;
    if(l==r) return l;
    int x=fd(ls,l,md,v);
    if(x==md+1) x=fd(rs,md+1,r,v);
    return x;
}
void bd(int n,int l,int r) {
    vv[n]=a[r];
    if(l==r) return;
    bd(ls,l,md);
    bd(rs,md+1,r);
}
void sv(int n,int l,int r) {
    int tp=ck;
    oo[++ck]=(o_t){laz[1],ma[1],1,vv[1]};
    for(int i=0;i<op[n].size();i++) {
        int tq=fd(1,1,N,op[n][i].v);
        if(tq>op[n][i].p) {
            up(1,1,N,op[n][i].p,tq-1,op[n][i].v);
        }
    }
    if(l==r) {
        int lx=aa[l],rx=bb[l];
        if(lx) {
            int tq=fd(1,1,N,lx);
            if(tq>rx) ans[l]=a[rx]-a[lx-1];
            else ans[l]=std::max(a[tq-1]-a[lx-1],qr(1,1,N,tq,rx));
        } else ans[l]=-1;
    } else {
        sv(ls,l,md);
        sv(rs,md+1,r);
    }
    while(ck>tp) {
        ma[oo[ck].n]=oo[ck].ma;
        laz[oo[ck].n]=oo[ck].la;
        vv[oo[ck].n]=oo[ck].vv;
        ck--;
    }
}
#undef ls
#undef rs
#undef md
void upr(int x) {
    auto it=ss[c[x]].find(x);
    if(la[x]<ti) uu(1,1,Q,la[x],ti-1,x,pre[x]);
    la[x]=ti;
    if(it==ss[c[x]].begin()) {
        pre[x]=0;
    } else {
        it--;
        pre[x]=(*it);
    }
}
signed main(void) {
    N=read();M=read();Q=read();
    for(int i=1;i<=N;i++) {
        a[i]=read();
        a[i]+=a[i-1];
    }
    for(int i=1;i<=N;i++) {
        c[i]=read();
        pre[i]=la[c[i]];
        la[c[i]]=i;
        ss[c[i]].insert(i);
    }
    for(int i=1;i<=N;i++) la[i]=1;
    for(int i=1;i<=Q;i++) {
        ti++;
        int op=read();
        if(op==2) {
            int x=read(),w=read(),i1=0,i2=0;
            auto it=ss[c[x]].find(x);
            it++;
            if(it!=ss[c[x]].end()) {
                i1=(*it);
            }
            ss[c[x]].erase(x);
            c[x]=w;
            ss[w].insert(x);
            auto it2=ss[w].find(x);
            it2++;
            if(it2!=ss[w].end()) {
                i2=(*it2);
            }
            if(i1) upr(i1);
            if(i2) upr(i2);
            upr(x);
        } else {
            aa[i]=read();
            bb[i]=read();
        }
    }
    for(int i=1;i<=N;i++) {
        uu(1,1,Q,la[i],Q,i,pre[i]);
    }
    bd(1,1,N);
    sv(1,1,N);
    for(int i=1;i<=Q;i++) {
        if(ans[i]>=0) we(ans[i]);
    }
    pcc();
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 6ms
memory: 25804kb

input:

5000 200 5000
2315 3433 1793 4621 4627 4561 289 4399 3822 2392 392 4581 2643 2441 4572 4649 2981 3094 4206 2057 761 2516 2849 3509 3033 658 4965 3316 3269 4284 4961 753 1187 2515 1377 1725 4743 4761 3823 3464 4859 989 2401 953 875 1481 2181 103 2067 2625 3296 4721 61 3843 1607 997 4385 1284 4299 441...

output:

118571
94450
82683
95154
99551
94493
73344
100567
109882
109882
100567
94450
100567
100567
93784
118571
94493
95154
78050
118571
109882
100567
100567
39374
93703
118571
109882
100567
100567
95724
94450
100567
118571
100567
100567
100567
109882
100567
100567
26617
100567
109882
109882
118571
100567
1...

result:

wrong answer 2nd lines differ - expected: '90725', found: '94450'

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 1018ms
memory: 170928kb

input:

200000 10 200000
55651 97298 108697 86619 60721 199951 10610 162267 154301 138848 39191 18605 101369 57073 34977 101576 71252 143401 89587 160521 166491 38442 150761 35579 25571 121311 38033 38483 144639 41401 179161 54872 157905 137601 46863 187656 171901 43715 41036 150741 69057 102031 130561 4772...

output:

1556773
1460011
1420674
1420674
1597591
1597591
1597591
1460011
1420674
1597591
1311896
1341514
1556773
1597591
1556773
1460011
1597591
1597591
1462527
1556773
1556773
1460011
1556773
1597591
1420674
1460011
1556773
1460011
1556773
1401640
1460011
1597591
1597591
1556773
1556773
1460011
1460011
1341...

result:

wrong answer 1st lines differ - expected: '1232419', found: '1556773'

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 177ms
memory: 46532kb

input:

200000 20000 200000
30681 32496 35471 48191 159123 69792 120915 150673 187226 158493 36275 26856 107976 124777 145229 69745 183961 14497 144808 153612 185893 137681 66417 46802 19345 113322 168046 128149 191001 135433 13201 139214 59489 81178 42343 163158 110121 119201 97501 53079 158755 192241 1132...

output:

46702944
49502395
44342383
44342383
38615532
46575131
46575131
46702944
49502395
46702944
43348689
38402892
46702944
49502395
49502395
49502395
46575131
49502395
49502395
46702944
49502395
46575131
46702944
40723098
46702944
44342383
49502395
33511235
46702944
44749669
44749669
38025842
46702944
467...

result:

wrong answer 2nd lines differ - expected: '46702944', found: '49502395'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%