QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#820225 | #9877. Segment Tree | Prosperity | WA | 11ms | 3712kb | C++23 | 1.9kb | 2024-12-18 20:14:21 | 2024-12-18 20:14:22 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline ll read(){
ll s=0,k=1;
char c=getchar();
while(c>'9'||c<'0'){
if(c=='-') k=-1;
c=getchar();
}
while(c>='0'&&c<='9'){
s=(s<<3)+(s<<1)+(c^48);
c=getchar();
}
return s*k;
}
const int N=262200;
int n,q;
struct Tree{
ll s,v,f[2];
}t[N<<2];
struct node{
int id,l,r;
};
void build(int s,int l,int r){
if(l==r) {
t[s].s=t[s].v;
return ;
}
int mid=l+r>>1;
build(s<<1,l,mid);
build(s<<1|1,mid+1,r);
t[s].s=min(t[s].v,t[s<<1].s+t[s<<1|1].s);
}
void update(int s,int l,int r,int L,int R){
if(L<=l&&r<=R){
t[s].f[0]=t[s].s;
t[s].f[1]=0;
return ;
}
int mid=l+r>>1;
if(L<=mid) update(s<<1,l,mid,L,R);
else t[s<<1].f[0]=0,t[s<<1].f[1]=t[s<<1].s;
if(R>mid) update(s<<1|1,mid+1,r,L,R);
else t[s<<1|1].f[0]=0,t[s<<1|1].f[1]=t[s<<1|1].s;
t[s].f[0]=t[s<<1].f[0]+t[s<<1|1].f[0];
t[s].f[1]=t[s<<1].f[1]+t[s<<1|1].f[1];
ll f0=t[s].f[1]+t[s].s,f1=t[s].f[0]+t[s].s;
t[s].f[0]=min(t[s].f[0],f0);
t[s].f[1]=min(t[s].f[1],f1);
}
int main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
n=read();
n=1<<n;
{
queue<node>q;
q.push({1,1,n});
while(!q.empty()){
node x=q.front();
q.pop();
t[x.id].v=read();
if(x.l==x.r) continue;
int mid=x.l+x.r>>1;
q.push({x.id<<1,x.l,mid});
q.push({x.id<<1|1,mid+1,x.r});
}
}
build(1,1,n);
q=read();
while(q--){
int op=read();
if(op==1){
int x=read();
ll w=read();
int i,s=1;
for(i=20;i>=0;i--) if(x>>i&1) break;
i--;
for(;i>=0;i--){
if(x>>i&1) s=s<<1|1;
else s=s<<1;
}
t[s].v=w;
if((s<<1)<=n<<2) t[s].s=min(t[s].v,t[s<<1].s+t[s<<1|1].s);
s>>=1;
while(s){
t[s].s=min(t[s].v,t[s<<1].s+t[s<<1|1].s);
s>>=1;
}
}
else{
int s=read(),R=read();
update(1,1,n,s+1,R);
printf("%lld\n",t[1].f[0]);
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3660kb
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: 11ms
memory: 3712kb
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:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 1st words differ - expected: '8344965', found: '0'