QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#705734 | #5415. Ropeway | njupt_zy | WA | 0ms | 3660kb | C++17 | 5.8kb | 2024-11-03 01:12:58 | 2024-11-03 01:12:59 |
Judging History
answer
#include<iostream>
#include<vector>
#include<string>
#include<queue>
using namespace std;
#define int long long
long long cccnt=0;
int t,n,k,qu;
string s;
struct node{
long long val, ord;
};
void solve(){
deque<node> q;
cin>>n>>k;
vector<long long> a(n*2+10), predp(n*2+10), sufdp(n*2+10);
for(int i = 1;i<=n;i++){
cin>>a[i];
}
cin>>s;
s = s + " ";
if(s[0]=='1')q.push_back(node{a[1],1});
else{
q.push_back(node{0,0});
q.push_back(node{a[1],1});
}
predp[0]=0;
predp[1]=a[1];
for(int i = 2;i<=n+1;i++){
while(!q.empty() && q.front().ord < i-k)q.pop_front();
{
predp[i] = a[i] + q.front().val;
if(s[i-1] == '1'){
q.clear();
}
while(!q.empty() && q.back().val > predp[i])q.pop_back();
}
q.push_back(node{predp[i], i});
}
q.clear();
if(s[n-1]=='1')q.push_back(node{a[n],n});
else{
q.push_back(node{0,n+1});
q.push_back(node{a[n],n});
}
sufdp[n+1]=0;
sufdp[n]=a[n];
for(int i = n-1;i>=0;i--){
while(!q.empty() && q.front().ord > i + k)q.pop_front();
{
sufdp[i] = a[i] + q.front().val;
if(i !=0 &&s[i-1] == '1'){
q.clear();
}
while(!q.empty() && q.back().val > sufdp[i])q.pop_back();
}
q.push_back(node{sufdp[i], i});
}
cin>>qu;
while(qu--){
cccnt++;
int flag=0;
long long p,v;
cin>>p>>v;
if(s[p-1] == '1'||k==1){
flag=1;
if(cccnt=544)cout<<flag<<'\n';
//if(predp[n+1]-a[p]+v==22)cout<<flag<<0<<0<<0<<k<<s[p-1]<<'\n';
cout<<predp[n+1] - a[p]+v<<'\n';
continue;
}
if(a[p]>=v)
{
flag=2;
if(cccnt=544)cout<<flag<<'\n';
long long l=max(0ll,p-k);
long long prex=1e18;
for(int i=p-1;i>=l;i--)
{
if(i!=0&&s[i-1]=='1')
{
prex=predp[i];
break;
}
prex=min(prex,predp[i]);
}
long long r=min((long long)(n+1),p+k);
long long sufx=1e18;
for(int i=p+1;i<=r;i++)
{
if(i!=n+1&&s[i-1]=='1')
{
sufx=sufdp[i];
break;
}
sufx=min(sufx,sufdp[i]);
}
if(min(v+prex+sufx,predp[n+1])==22)cout<<flag<<'\n';
cout<<min(v+prex+sufx,predp[n+1])<<'\n';
continue;
}
else
{
long long l=max(0ll,p-k+1);
long long r=min((long long)n+1,p+k-1);
long long res=1e18;
q.clear();
for(int i=l;i<p;i++)
{
if(i!=0&&s[i-1]=='1')
{
l=i;
}
}
for(int i=r;i>p;i--)
{
if(i!=n+1&&s[i-1]=='1')
{
r=i;
}
}
if(r-l<=k)
{
flag=3;
if(cccnt=544)cout<<flag<<'\n';
if(min(predp[l]+sufdp[r],predp[n+1]+v-a[p])==525696072)cout<<flag<<0<<0<<0<<l<<0<<0<<0<<r<<0<<0<<0<<p<<0<<0<<0<<v<<0<<0<<0<<n<<0<<0<<0<<k<<'\n';
if(l!=0&&r!=n+1)cout<<min(predp[l]+sufdp[r],predp[n+1]+v-a[p])<<'\n';
else if(l==0&&r==n+1)cout<<0<<'\n';
else if(l==0)
{
if(s[r-1]=='1')cout<<min(predp[l]+sufdp[r],predp[n+1]+v-a[p])<<'\n';
else
{
long long res=1e18;
for(int i=1;i<=r;i++)
{
if(i!=p)res=min(res,sufdp[i]);
else res=min(res,sufdp[i]+v-a[p]);
}
cout<<res<<'\n';
}
}
else
{
if(s[l-1]=='1')cout<<min(predp[l]+sufdp[r],predp[n+1]+v-a[p])<<'\n';
else
{
long long res=1e18;
for(int i=l;i<=n;i++)
{
if(i!=p)res=min(res,predp[i]);
else res=min(res,predp[i]+v-a[p]);
}
cout<<res<<'\n';
}
}
//else cout<<predp[n+1]+v-a[p]<<'\n';
continue;
}
else
{
flag=4;
if(cccnt=544)cout<<flag<<'\n';
int j=l+k;
long long sufx=1e18;
for(int i=p+1;i<=j;i++)
{
sufx=min(sufx,sufdp[i]);
}
long long res=1e18;
for(int i=l;i<p;i++)
{
res=min(predp[i]+sufx,res);
//cout<<"!"<<i<<" "<<sufdp[i]<<" "<<sufx<<" "<<res<<endl;
if(j<r)//j<=r
{
j++;
sufx=min(sufx,sufdp[j]);
}
}
if(min(res,predp[n+1]+v-a[p])==22)cout<<flag<<s[l-1]<<s[r-1]<<0<<0<<0<<l<<0<<0<<0<<r<<0<<0<<0<<p<<0<<0<<0<<v<<0<<0<<0<<n<<0<<0<<0<<k<<'\n';
cout<<min(res,predp[n+1]+v-a[p])<<'\n';
continue;
}
}
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>t;
while(t--){
solve();
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3660kb
input:
3 10 3 5 10 7 100 4 3 12 5 100 1 0001000010 2 2 3 6 15 5 6 1 1 1 1 1 00000 1 3 100 5 6 1 1 1 1 1 00100 1 3 100
output:
2 206 4 214 3 0 1 100
result:
wrong answer 1st numbers differ - expected: '206', found: '2'