QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#449927#5098. 第一代图灵机27455185850 307ms80220kbC++202.4kb2024-06-21 19:37:022024-06-21 19:37:02

Judging History

This is the latest submission verdict.

  • [2024-06-21 19:37:02]
  • Judged
  • Verdict: 0
  • Time: 307ms
  • Memory: 80220kb
  • [2024-06-21 19:37:02]
  • 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];
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,b[l])];
    int z=T[x].l+T[x].r>>1;
    if(l<=T[x<<1].w) return max(find(x<<1,l),T[x<<1|1].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[b[l]];
        T[x].w=b[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[b[T[x].l]];
        T[x].w=b[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,int k)
{
    if(T[x].l>=l&&T[x].r<=r) return find(x,k);
    int z=T[x].l+T[x].r>>1;
    ll s=0;
    if(l<=z) s=max(s,sum(x<<1,l,r,k));
    if(r>z) s=max(s,sum(x<<1|1,l,r,k));
    return s;
}
int main()
{
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=n;++i)
    {
        scanf("%lld",&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)
    {
        int x;
        scanf("%d",&x);
        b[i]=*Set[x].end();
        Set[x].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,l));
        }
        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())
            {
                b[*next(p)]=b[x];
                add(1,*next(p));
            }
            Set[b[x]].erase(x);
            Set[k].insert(x);
            p=Set[k].find(x);
            b[x]=*prev(p);
            add(1,x);
            if(next(p)!=Set[k].end())
            {
                b[*next(p)]=x;
                add(1,*next(p));
            }
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

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:


result:


Subtask #2:

score: 0
Time Limit Exceeded

Test #3:

score: 0
Time Limit Exceeded

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:


result:


Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 307ms
memory: 80220kb

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:

6621675747
13369649242
931218999
2620448320
750317409
9534864228
3004960664
9839523563
13389184978
2836654870
125346024
546916664
3319068498
13401800941
12305896651
3918520748
4220403622
4196630492
17911495231
4642609744
12144115606
5386102380
3380303636
1694853309
11951165806
2557854406
14743095279...

result:

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

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%