QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#67123#5098. 第一代图灵机Graphcity0 742ms56880kbC++203.4kb2022-12-10 09:40:592022-12-10 09:41:01

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-10 09:41:01]
  • Judged
  • Verdict: 0
  • Time: 742ms
  • Memory: 56880kb
  • [2022-12-10 09:40:59]
  • Submitted

answer

#include<bits/stdc++.h>
#define ll long long
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rof(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const int Maxn=2e5;
const ll inf=1e18;

inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9')
    {
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}

int n,m,q,val[Maxn+5],col[Maxn+5],pre[Maxn+5];
ll sum[Maxn+5]; set<int> st[Maxn+5];

struct Node
{
    int id,l,r,pos,mx; ll val,rval,ans,hzh;
    inline void Print()
    {
        printf("%d %d %d: %d %d %lld %lld %lld %lld\n",id,l,r,pos,mx,val,rval,ans,hzh);
    }
} t[Maxn*4+5];
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)

inline ll GetHzh(int p,int k)
{
    int l=t[p].l,r=t[p].r,mid=(l+r)>>1;
    if(l==r) return sum[l]-sum[max(k,pre[l])];
    if(k<=t[ls(p)].mx) return max(t[p].rval,GetHzh(ls(p),k));
    else return max(sum[mid]-sum[k],GetHzh(rs(p),k));
}
inline ll GetAns(int p,int k)
{
    int l=t[p].l,r=t[p].r,mid=(l+r)>>1;
    if(l==r) return sum[l]-sum[max(pre[l],k-1)];
    if(t[ls(p)].mx<=k) return max(sum[mid]-sum[k-1],GetAns(rs(p),k));
    else return max(GetAns(ls(p),k),t[rs(p)].hzh);
}
inline Node operator+(Node a,Node b)
{
    if(!a.l) return b;
    Node c;
    c.mx=max(a.mx,b.mx);
    c.val=a.val+b.val;
    c.l=a.l,c.r=b.r;
    c.rval=GetHzh(b.id,a.mx);
    c.hzh=max(a.hzh,c.rval);
    c.pos=b.pos;
    if(b.pos==b.l) c.pos=max(a.pos,b.mx+1);
    c.ans=max(a.ans,b.ans);
    c.ans=max(c.ans,GetAns(b.id,a.pos));
    return c;
}
inline void push_up(int p) {t[p]=t[ls(p)]+t[rs(p)],t[p].id=p;}
inline void Build(int l,int r,int p)
{
    t[p].l=l,t[p].r=r;
    if(l==r) {t[p]=(Node){p,l,r,l,pre[l],val[l],-inf,val[l],sum[l]-sum[pre[l]]}; return;}
    int mid=(l+r)>>1;
    Build(l,mid,ls(p)),Build(mid+1,r,rs(p)),push_up(p);
}
inline void Modify(int l,int r,int p,int pos,int k)
{
    // if(l==r) printf("opt %d: %d\n",pos,k);
    if(l==r) {t[p].mx=k,t[p].hzh=sum[l]-sum[k]; return;}
    int mid=(l+r)>>1;
    if(pos<=mid) Modify(l,mid,ls(p),pos,k);
    else Modify(mid+1,r,rs(p),pos,k);
    push_up(p);
}
inline Node Count(int nl,int nr,int l,int r,int p)
{
    if(l<=nl && nr<=r) return t[p];
    int mid=(nl+nr)>>1; Node res; res.l=0;
    if(l<=mid) res=res+Count(nl,mid,l,r,ls(p));
    if(r>mid) res=res+Count(mid+1,nr,l,r,rs(p));
    return res;
}

int main()
{
  //  freopen("a.in","r",stdin);
  //  freopen("a.out","w",stdout);

    n=read(),m=read(),q=read();
    For(i,1,m) st[i].insert(0);
    For(i,1,n) val[i]=read();
    For(i,1,n) col[i]=read();
    For(i,1,n)
    {
        sum[i]=sum[i-1]+val[i];
        pre[i]=*--st[col[i]].end(),st[col[i]].insert(i);
    }
    For(i,1,m) st[i].insert(n+1);
    Build(1,n,1);
    while(q--)
    {
        int opt=read(),a=read(),b=read();
        if(opt==1) printf("%d\n",Count(1,n,a,b,1).ans);
        if(opt==2)
        {
            if(col[a]==b) continue;
            int x=*st[col[a]].upper_bound(a);
            int y=*--st[col[a]].lower_bound(a);
            int z=*--st[b].lower_bound(a);
            int s=*st[b].upper_bound(a);
            if(x<=n) pre[x]=y,Modify(1,n,1,x,y);
            col[a]=b,pre[a]=z,Modify(1,n,1,a,z);
            if(s<=n) pre[s]=a,Modify(1,n,1,s,a);
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 14ms
memory: 14128kb

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:

5084776
4645024
1559296
3173131
3500569
2609592
2875851
4645024
4645024
4645024
3808524
4645024
3808524
4645024
713828
3173131
2609592
2384821
1102783
3173131
4645024
3808524
4645024
39374
4645024
3808524
2116522
3808524
4645024
2116522
4645024
3808524
4645024
4645024
4645024
4645024
4645024
3808524...

result:

wrong answer 1st lines differ - expected: '118571', found: '5084776'

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 742ms
memory: 54808kb

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:

25680831
21231823
16495960
25428645
25428645
25428645
25428645
25428645
16056578
25428645
15485774
16898813
25680831
25428645
25680831
25428645
24020745
16718085
25428645
25428645
25428645
21231823
25680831
24020745
25428645
21231823
25428645
21231823
25264266
24777847
13327617
25428645
25428645
252...

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 619ms
memory: 56880kb

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:

606389862
101401984
2123297427
-1174189945
-1001997332
842037075
269780654
1415754120
101401984
-2000514790
891985364
-477162578
1784566068
-2136294827
1569368559
-477162578
269780654
-477162578
754576651
-702494350
-1931915162
-1723051928
1187908634
1987669844
424505740
-1217287493
754576651
-10252...

result:

wrong answer 1st lines differ - expected: '46702944', found: '606389862'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%