QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#841208#9877. Segment TreeWuyanruWA 13ms24060kbC++142.5kb2025-01-03 15:13:422025-01-03 15:13:51

Judging History

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

  • [2025-01-03 15:13:51]
  • 评测
  • 测评结果:WA
  • 用时:13ms
  • 内存:24060kb
  • [2025-01-03 15:13:42]
  • 提交

answer

#include<bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f3f3fll
#define debug(x) cerr<<#x<<"="<<x<<endl
using namespace std;
using ll=long long;
using ld=long double;
using pli=pair<ll,int>;
using pi=pair<int,int>;
template<typename A>
using vc=vector<A>;
template<typename A,const int N>
using aya=array<A,N>;
inline int read()
{
    int s=0,w=1;char ch;
    while((ch=getchar())>'9'||ch<'0') if(ch=='-') w=-1;
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}
inline ll lread()
{
    ll s=0,w=1;char ch;
    while((ch=getchar())>'9'||ch<'0') if(ch=='-') w=-1;
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}
ll num1[1048576];
ll num2[1048576];
ll a[1048576];
ll b[1048576];
int n,m;
vc<int>id;
inline void run(int p)
{
    while(p)
    {
        if(p<(1<<n)) b[p]=min(a[p],b[p*2]+b[p*2|1]);
        p>>=1;
    }
}
inline ll clear()
{
    ll ans=inf;
    for(int i:id)
    {
        // printf("i=%d : %lld %lld\n",i,num1[i],num2[i]);
        ans=min(ans,num1[i]+num2[i]);
        num1[i]=num2[i]=inf;
    }
    id.clear();
    return ans;
}
inline ll DIS(int x,int y)
{
    int v=min(__builtin_ctz(x),__builtin_ctz(y));
    x>>=v,y>>=v;v=n-v;
    return b[(1<<v)+x];
}
inline void init(int x,ll *num)
{
    // printf("init %d\n",x);
    num[x]=0;id.push_back(x);
    vc<int>now;now.push_back(x);
    for(int i=0;i<=n;i++)
    {
        vc<int>lst=now;now.clear();
        for(int p:lst) if(p%(1<<i)==0)
        {
            now.push_back(p);
            if(p!=0&&p>=x)
            {
                if(num[p-(1<<i)]==inf) id.push_back(p-(1<<i)),now.push_back(p-(1<<i));
                num[p-(1<<i)]=min(num[p-(1<<i)],num[p]+DIS(p-(1<<i),p));
            }
            if(p!=(1<<n)&&p<=x)
            {
                if(num[p+(1<<i)]==inf) id.push_back(p+(1<<i)),now.push_back(p+(1<<i));
                num[p+(1<<i)]=min(num[p+(1<<i)],num[p]+DIS(p,p+(1<<i)));
            }
        }
    }

}
int main()
{
    n=read();
    for(int i=1;i<(1<<(n+1));i++) a[i]=b[i]=read();
    for(int i=(1<<n)-1;i;i--) b[i]=min(a[i],b[i*2]+b[i*2|1]);

    memset(num1,0x3f,sizeof(num1));
    memset(num2,0x3f,sizeof(num2));
    m=read();
    for(int i=1;i<=m;i++)
    {
        int op=read(),x=read(),y=read();
        if(op==1) a[x]=y,run(x);
        else
        {
            init(x,num1),init(y,num2);
            printf("%lld\n",clear());
        }
    }
    return 0;
}
/*
3
7 1 14 3 9 4 8 2 6 5 5 13 8 2 3
1
2 3 5
*/

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 24060kb

input:

3
7 1 14 3 9 4 8 2 6 5 5 13 8 2 3
10
2 0 1
2 0 4
2 4 6
2 4 8
2 3 5
1 6 30
2 3 5
2 4 6
1 1 10000000
2 0 8

output:

2
1
4
8
17
18
13
15

result:

ok 8 tokens

Test #2:

score: -100
Wrong Answer
time: 13ms
memory: 23944kb

input:

1
7914575 2436426 4979445
199989
1 1 6190629
1 1 1407775
1 1 2804784
1 2 2631932
1 1 3078537
1 3 286918
1 2 3238506
1 3 3361868
1 2 9296263
1 3 4836991
1 3 2177068
1 3 4291757
1 1 594328
1 2 8996221
1 1 5531545
1 3 3575467
1 3 3206504
1 1 8344965
1 3 6045895
2 0 2
1 2 6248153
1 1 5797489
1 1 9766466...

output:

7415871
7415871
2624007
2512448
4979445
4979445
4979445
6363152
2436426
4380822
2436426
4979445
2436426
7415871
4979445
2436426
7415871
2808118
2436426
4979445
2436426
7415871
2436426
2436426
7400947
4979445
2436426
7415871
4979445
4979445
4979445
2436426
4979445
2436426
4979445
2436426
4979445
3806...

result:

wrong answer 1st words differ - expected: '8344965', found: '7415871'