QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#449939#5098. 第一代图灵机27455185850 434ms84636kbC++202.4kb2024-06-21 19:53:482024-06-21 19:53:49

Judging History

This is the latest submission verdict.

  • [2024-06-21 19:53:49]
  • Judged
  • Verdict: 0
  • Time: 434ms
  • Memory: 84636kb
  • [2024-06-21 19:53:48]
  • Submitted

answer

#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
typedef long long ll;
const int N=1000001;
int n,m,q,b[N],g[N];
ll a[N];
set<int> Set[N];
struct tree
{
    int l,r,w;
    ll s;
}T[N<<2];
ll find(int x,int l)
{
    if(l>=T[x].r) return 0;
    if(T[x].l==T[x].r) return a[T[x].l]-a[max(l,g[T[x].l])];
    int z=T[x].l+T[x].r>>1;
    if(l<=T[x<<1].w) return max(find(x<<1,l),T[x].s);
    else return max(a[z]-a[l],find(x<<1|1,l));
}
void pushup(int x)
{
    T[x].w=max(T[x<<1].w,T[x<<1|1].w);
    T[x].s=find(x<<1|1,T[x<<1].w);
}
void build(int x,int l,int r)
{
    T[x].l=l,T[x].r=r;
    if(l==r)
    {
        T[x].s=a[l]-a[g[l]];
        T[x].w=g[l];
        return;
    }
    int z=l+r>>1;
    build(x<<1,l,z);
    build(x<<1|1,z+1,r);
    pushup(x);
}
void add(int x,int q)
{
    if(T[x].l==T[x].r)
    {
        T[x].s=a[T[x].l]-a[g[T[x].l]];
        T[x].w=g[T[x].l];
        return;
    }
    int z=T[x].l+T[x].r>>1;
    if(q<=z) add(x<<1,q);
    else add(x<<1|1,q);
    pushup(x);
}
ll sum(int x,int l,int r)
{
    if(T[x].l>=l&&T[x].r<=r) return find(x,l-1);
    int z=T[x].l+T[x].r>>1;
    ll s=0;
    if(l<=z) s=max(s,sum(x<<1,l,r));
    if(r>z) s=max(s,sum(x<<1|1,l,r));
    return s;
}
int main()
{
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&a[i]);
        a[i]+=a[i-1];
    }
    for(int i=1;i<=m;++i) Set[i].insert(0);
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&b[i]);
        g[i]=*prev(Set[b[i]].end());
        Set[b[i]].insert(i);
    }
    build(1,1,n);
    for(int i=1;i<=q;++i)
    {
        int z;
        scanf("%d",&z);
        if(z==1)
        {
            int l,r;
            scanf("%d%d",&l,&r);
            printf("%lld\n",sum(1,l,r));
        }
        else if(z==2)
        {
            int x,k;
            scanf("%d%d",&x,&k);
            auto p=Set[b[x]].find(x);
            if(next(p)!=Set[b[x]].end())
            {
                g[*next(p)]=g[x];
                add(1,*next(p));
            }
            Set[b[x]].erase(x);
            b[x]=k;
            Set[k].insert(x);
            p=Set[k].find(x);
            g[x]=*prev(p);
            add(1,x);
            if(next(p)!=Set[k].end())
            {
                g[*next(p)]=x;
                add(1,*next(p));
            }
        }
    }
    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 8ms
memory: 57812kb

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:

1802092
432992
143033
1935376
2493673
628229
726388
1097802
2646132
210951
2384821
432992
2594334
760980
191740
1065662
277160
304232
83889
952599
1253911
2493673
662724
39374
648685
952599
437547
232685
244579
235297
501619
2088743
930351
277160
459079
423488
946455
466602
662724
34330
1770070
1146...

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 434ms
memory: 83952kb

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:

1690492
3095094
2055958
2055958
3568627
3568627
4612047
1838697
3461156
3600625
4145064
3428628
2055958
3772595
3224217
1311003
3568627
3568627
1640768
3259709
3592859
11855676
3313362
4562540
1214212
1494075
3151073
2506068
1690492
2862763
5370489
3568627
3568627
2378654
6011621
3534117
3095094
215...

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 325ms
memory: 84636kb

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:

5462471951
1427989353
931158568
2492172111
750265809
9534839833
3002888614
2762055353
2269661720
947390860
125441385
519479345
3304436888
3827615780
2535393597
1880621346
2518215380
3532955410
3144714126
4641346300
2355976068
3578662240
1298170005
1694313410
1848528011
2552767418
3977254608
16594241...

result:

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

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%