QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#841184#9877. Segment TreeWuyanruWA 0ms24344kbC++142.3kb2025-01-03 15:04:032025-01-03 15:04:11

Judging History

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

  • [2025-01-03 15:04:11]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:24344kb
  • [2025-01-03 15:04:03]
  • 提交

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)
    {
        ans=min(ans,num1[i]+num2[i]);
        num1[i]=num2[i]=inf;
    }
    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)
{
    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)
            {
                if(num[p-(1<<i)]==inf) 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))
            {
                if(num[p+(1<<i)]==inf) 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;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 24344kb

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
7
5
18
13
15

result:

wrong answer 4th words differ - expected: '8', found: '7'