QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#813975 | #9877. Segment Tree | ucup-team3161# | WA | 79ms | 9852kb | C++17 | 2.7kb | 2024-12-14 14:10:46 | 2024-12-14 14:10:47 |
Judging History
answer
// what is matter? never mind.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define ull unsigned long long
#define int long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
return f?-x:x;
}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,ll>pii;
typedef vector<int>vi;
#define maxn 2000005
#define inf 0x3f3f3f3f3f3f3f3f
struct mat{
int a[2][2];
mat(){
memset(a,63,sizeof a);
}
};
int n,m,a[maxn];
mat get(int w){
mat a;
a.a[0][0]=a.a[1][1]=0;
a.a[0][1]=a.a[1][0]=w;
return a;
}
int tr[maxn<<2];
int pl[maxn],pr[maxn];
void up(int p){
tr[p]=tr[p<<1]+tr[p<<1|1];
tr[p]=min(tr[p],a[p]);
}
void build(int p,int l,int r){
// cout<<"build "<<p<<" "<<l<<" "<<r<<endl;
pl[p]=l,pr[p]=r;
if(l+1==r){
tr[p]=a[p];
return;
}
int mid=l+r>>1;
build(p<<1,l,mid);
build(p<<1|1,mid,r);
up(p);
}
void upd(int p,int to){
a[p]=to;
up(p);
while(p>>=1) up(p);
}
map<int,int>mp[2];
void wk(int u,int o){
auto ins=[&](int x,int w){
if(!mp[o].count(x)) mp[o][x]=w;
else mp[o][x]=min(mp[o][x],w);
};
int l=u,r=u+1,dl=0,dr=0;
int p=u+(1<<n);
if(u==(1<<n)) l=u-1,r=u,dr=0,p=u-1+(1<<n),dl=a[p];
else dl=0,dr=a[p];
ins(l,dl);
ins(r,dr);
while(p>1){
int q=p>>1;
int nl=inf,nr=inf;
if(p%2==0) {
nl=dl,nr=dr+tr[q<<1|1];
}else{
nr=dr,nl=dl+tr[q<<1];
}
nr=min(nr,nl+a[q]);
nl=min(nl,nr+a[q]);
dl=nl,dr=nr,p=q;
ins(pl[q],dl);
ins(pr[q],dr);
}
}
int ask(int u,int v){
For(i,0,1) mp[i].clear();
wk(u,0);
wk(v,1);
int res=inf;
for(auto [t,ds]:mp[0]){
if(mp[1].count(t)) res=min(res,ds+mp[1][t]);
}
return res;
}
signed main()
{
cin>>n;
For(i,1,(1<<(n+1))-1)cin>>a[i];
build(1,0,(1<<n));
cin>>m;
For(_,1,m){
// cout<<"NOW "<<_<<endl;
int op,x,y;
cin>>op>>x>>y;
if(op==1){
upd(x,y);
}else{
cout<<ask(x,y)<<endl;
}
}
return 0;
}
/*
[li,ri]
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 9852kb
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: 79ms
memory: 9776kb
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:
6045895 1281562 187581 2512448 130126 6420140 2615908 668057 0 2592644 0 4042733 0 2733055 2905234 0 974064 371692 0 2539201 0 4938742 0 0 6346997 3327130 0 330478 2783848 3409112 2827247 0 4704960 0 7152753 0 2599805 765614 0 0 2950083 2911344 0 0 0 0 3732584 3507956 1083350 3799685 2110208 4630525...
result:
wrong answer 1st words differ - expected: '8344965', found: '6045895'