QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#546911 | #5415. Ropeway | Wuyanru | WA | 0ms | 16160kb | C++14 | 2.3kb | 2024-09-04 15:44:55 | 2024-09-04 15:44:56 |
Judging History
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>;
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 dp[500001];
ll fp[500001];
int L[500001];
int R[500001];
char s[500005];
int id[500001];
int a[500001];
ll ans[500001];
int n,k,c;
inline ll get(int l,int r)
{
dp[l]=0;deque<int>que;que.push_back(l);
for(int i=l+1;i<=r;i++)
{
while(i-que.front()>k) que.pop_front();
dp[i]=dp[que.front()]+a[i];
while(dp[que.back()]>dp[i]) que.pop_back();
que.push_back(i);
}
while(que.size()) que.pop_back();
fp[r]=0;que.push_back(r);
for(int i=r-1;i>=l;i--)
{
while(que.front()-i>k) que.pop_front();
fp[i]=fp[que.front()]+a[i];
while(fp[que.back()]>fp[i]) que.pop_back();
que.push_back(i);
}
assert(dp[r]-a[r]==fp[l]-a[l]);
return dp[r]-a[r];
}
inline void solve()
{
n=read(),k=read(),a[0]=a[n+1]=c=0;
for(int i=1;i<=n;i++) a[i]=read();
scanf("%s",s+1);s[0]=s[n+1]='1';
ll sum=0;
for(int l=0,r;l<=n;l=r)
{
r=l+1;
while(s[r]!='1') r++;
// printf("l=%d r=%d\n",l,r);
c++;for(int j=l+1;j<r;j++) id[j]=c;
sum+=(ans[c]=get(l,r))+a[r];
L[c]=l,R[c]=r;
}
int q=read();
for(int i=1;i<=q;i++)
{
int x=read(),y=read();
if(s[x]=='1') printf("%lld\n",sum-a[x]+y);
else
{
int I=id[x];ll oth=sum-ans[I];
ll o=oth+dp[x]+fp[x]-2*a[x]+y;
ll mi=inf;
for(int j=x+k-1;j>x;j--)
{
if(j-k>=L[I]) mi=min(mi,dp[j-k]);
if(j<=R[I]) o=min(o,oth+mi+fp[j]);
}
printf("%lld\n",o);
}
}
}
int main()
{
int T=read();
while(T--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 16060kb
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:
206 214 0 100
result:
ok 4 number(s): "206 214 0 100"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 16160kb
input:
500 19 6 285203460 203149294 175739375 211384407 323087820 336418462 114884618 61054702 243946442 19599175 51974474 285317523 222489944 26675167 300331960 1412281 324105264 33722550 169011266 1111111110110100011 18 3 127056246 5 100630226 14 301161052 2 331781882 5 218792226 2 190274295 12 49227476 ...
output:
2472886431 2299111966 2796055445 2650202148 2417273966 2508694561 2285479513 2573544034 2555292110 2240907690 2577284958 2555292110 2766700195 2511807344 2555292110 2438434986 2669077215 2682112324 498292963 488030494 211705888 564509290 715543137 488030494 639116182 18 19 19 19 20 20 54 849950346 8...
result:
wrong answer 8th numbers differ - expected: '2521569560', found: '2573544034'