QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#404455 | #8057. Best Carry Player 4 | KLPP# | WA | 69ms | 3756kb | C++17 | 2.1kb | 2024-05-03 23:12:59 | 2024-05-03 23:13:01 |
Judging History
answer
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int lld;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)
const int MAX=1'000'000;
const lld INF=1e9;
class ST{
lld sumA[4*MAX];
lld sumB[4*MAX];
lld val[4*MAX];
public:
void build(int a, int b, int node){
if(a==b){
sumA[node]=0;
sumB[node]=0;
val[node]=0;
return;
}
int mid=(a+b)/2;
build(a,mid,2*node);
build(mid+1,b,2*node+1);
sumA[node]=sumA[2*node]+sumA[2*node+1];
sumB[node]=sumB[2*node]+sumB[2*node+1];
val[node]=min(val[2*node]+sumB[2*node+1],sumA[2*node]+val[2*node+1]);
}
void update(int a, int b, int node, int pos, pair<lld,lld> V){
if(pos<a || b<pos)return;
if(a==b){
sumA[node]=V.first;
sumB[node]=V.second;
val[node]=min(V.first,V.second);
return;
}
int mid=(a+b)/2;
update(a,mid,2*node,pos,V);
update(mid+1,b,2*node+1,pos,V);
sumA[node]=sumA[2*node]+sumA[2*node+1];
sumB[node]=sumB[2*node]+sumB[2*node+1];
val[node]=min(val[2*node]+sumB[2*node+1],sumA[2*node]+val[2*node+1]);
}
lld query(){
return val[1];
}
};
ST S;
void solve(){
int n;
cin>>n;
vector<lld> a(n);
vector<lld> b(n);
rep(i,0,n)cin>>a[i];
a[0]=INF;
rep(i,0,n)cin>>b[i];
b[0]=INF;
reverse(a.begin(),a.end());
//reverse(b.begin(),b.end());
S.build(0,n-1,1);
rep(i,0,n){
S.update(0,n-1,1,i,{a[i],b[i]});
}
int last=-1;
lld ans=0;
rep(i,1,n){
while(last+1<i && a[last+1]>0){
last++;
}
if(last>-1){
b[i]--;
a[last]--;
S.update(0,n-1,1,i,{a[i],b[i]});
S.update(0,n-1,1,last,{a[last],b[last]});
ans=max(ans,1+S.query());
b[i]++;
a[last]++;
S.update(0,n-1,1,i,{a[i],b[i]});
S.update(0,n-1,1,last,{a[last],b[last]});
}
}
cout<<ans<<"\n";
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int tt=1;
cin>>tt;
while(tt--){
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3756kb
input:
5 2 1 2 3 4 3 1 0 1 0 1 0 4 1 0 0 1 1 1 1 1 5 123456 114514 1919810 233333 234567 20050815 998244353 0 0 0 10 5 3 5 3 2 4 2 4 1 5 9 9 8 2 4 4 3 5 3 0
output:
5 1 2 467900 29
result:
ok 5 number(s): "5 1 2 467900 29"
Test #2:
score: -100
Wrong Answer
time: 69ms
memory: 3520kb
input:
100000 5 0 1 1 1 1 0 0 1 0 0 5 0 0 0 0 0 1 1 1 0 0 5 0 0 2 1 1 0 2 1 0 1 5 0 0 0 0 0 1 2 1 0 0 5 0 1 0 1 1 0 0 1 1 1 5 2 0 0 0 1 1 0 0 0 3 5 2 0 0 1 1 0 2 1 1 1 5 0 0 0 0 2 0 0 0 0 1 5 0 0 0 0 0 0 1 1 0 0 5 4 0 0 0 0 0 0 0 1 0 5 0 0 0 0 1 2 1 1 0 0 5 0 2 3 0 0 0 0 0 1 0 5 1 1 1 0 1 1 0 1 0 1 5 0 0 0...
output:
2 0 4 0 4 3 3 2 0 0 1 0 2 0 3 1 1 0 0 0 0 0 0 0 4 0 0 2 3 3 1 5 0 0 0 0 0 0 0 0 0 3 5 3 2 0 0 0 0 2 0 0 0 4 0 0 0 1 0 0 0 4 1 1 2 2 0 3 3 0 0 0 1 0 0 2 1 2 0 2 4 0 0 5 0 2 1 0 1 0 2 1 3 0 0 0 0 3 0 0 2 2 0 0 3 0 0 0 0 0 1 0 3 0 0 0 0 0 0 0 0 0 0 0 4 1 0 3 1 2 0 0 2 0 0 2 0 1 3 0 0 0 0 3 0 1 0 0 0 0 ...
result:
wrong answer 5th numbers differ - expected: '3', found: '4'