QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#176632 | #5415. Ropeway | brz | TL | 1385ms | 291224kb | C++20 | 2.3kb | 2023-09-11 20:42:09 | 2023-09-11 20:42:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define maxn 500010
#define cn getchar
template<class TY>void read(TY &x){
x=0;int f1=1;char ch=cn();
while(ch<'0'||ch>'9'){if(ch=='-')f1=-1;ch=cn();}
while(ch>='0'&&ch<='9')x=x*10+(ch-'0'),ch=cn(); x*=f1;
}
template<class TY>void write2(TY x){
if(x>9)write2(x/10);
putchar(x%10+'0');
}
template<class TY>void write(TY x){
if(x<0)putchar('-'),x=-x;
write2(x);
}
int n,k,q,a[maxn];
char s[maxn];
struct node{
int l,r,mid;
long long mi;
node *zuo,*you;
node(int x,int y):l(x),r(y),mid(l+r>>1),mi(1e18),zuo(NULL),you(NULL){
if(l==r)return;
zuo=new node(l,mid);
you=new node(mid+1,r);
}
void change(int x,long long z){
if(l==r){
mi=z;
return;
}
if(x<=mid)zuo->change(x,z);
else you->change(x,z);
mi=min(zuo->mi,you->mi);
}
long long query(int x,int y){
if(l==x&&r==y)return mi;
if(y<=mid)return zuo->query(x,y);
else if(x>mid)return you->query(x,y);
else return min(zuo->query(x,mid),you->query(mid+1,y));
}
}*rt[2];
int le[maxn],ri[maxn];
int main()
{
int Te;read(Te);while(Te--){
read(n);read(k);
for(int i=1;i<=n;i++)
read(a[i]); a[n+1]=0;
char ch=getchar(); n=0;
while(ch<'0'||ch>'1')ch=getchar();
while(ch>='0' && ch<='1')s[++n]=ch, ch=getchar();
le[0]=0; rt[0]=new node(0,n+1);
rt[0]->change(0,0);
for(int i=1;i<=n+1;i++){
if(s[i]=='1')le[i]=i;
else le[i]=le[i-1];
long long p=a[i] + rt[0]->query(max(le[i-1],i-k),i-1);
rt[0]->change(i,p);
}
ri[n+1]=n+1; rt[1]=new node(0,n+1);
rt[1]->change(n+1,0);
for(int i=n;i>=0;i--){
if(s[i]=='1')ri[i]=i;
else ri[i]=ri[i+1];
long long p=a[i] + rt[1]->query(i+1,min(i+k,ri[i+1]));
rt[1]->change(i,p);
}
long long Cans = rt[0]->query(n+1,n+1);
read(q);
for(int i=1;i<=q;i++){
int x,y;read(x);read(y);
if(s[x]=='1')write(Cans + y-a[x]),puts("");
else{
long long ans=0;
ans += rt[0]->query(max(x-k,le[x]),x-1) + rt[1]->query(x+1,min(x+k,ri[x])) + y;
for(int j=max(le[x],x-k+1);j<x;j++){
ans = min(ans, rt[0]->query(j,j) + rt[1]->query(x+1,min(j+k,ri[x])));
// printf("%d : %lld\n",j,rt[0]->query(j,j) + rt[1]->query(x+1,min(j+k,ri[x])));
}
write(ans);puts("");
}
}
}
}
/*
1
10 3
5 10 7 100 4 3 12 5 100 1
0001000010
1
6 15
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7612kb
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: 0
Accepted
time: 0ms
memory: 8844kb
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 2521569560 2521569560 2240907690 2577284958 2521569560 2766700195 2511807344 2521569560 2438434986 2669077215 2682112324 470735446 470735446 211705888 564509290 715543137 470735446 470735446 18 19 19 19 20 19 54 849950346 8...
result:
ok 5277 numbers
Test #3:
score: 0
Accepted
time: 6ms
memory: 9388kb
input:
50 183 160 22617237 21369258 39718669 4582413 28629717 25947766 1690897 19844235 35568283 42909820 21829213 70588436 8472484 53107624 21547259 11440081 6630789 5896457 19770793 30204510 29796593 27689811 39350369 21646987 36362667 38164292 13428410 54681069 24526477 58941286 70890011 43730474 388615...
output:
5303746210 5262479222 5346682277 5299354906 5290045662 5350552810 5343191051 5268759163 5299354906 5340227887 5299354906 5253956732 5289945955 5230918240 5287812187 5299354906 5299354906 5273800386 5299354906 5299354906 5353471727 5283662384 5230330060 5319166005 5338060400 5304825609 5268929476 526...
result:
ok 9541 numbers
Test #4:
score: 0
Accepted
time: 1385ms
memory: 291224kb
input:
3 500000 891 806445768 895003544 461699845 184479965 853541910 593542573 667984604 465354540 303586741 243665567 285056069 294245042 675066412 456713460 215929340 756894934 773828574 317143965 451366539 891390118 436168373 633752416 78781758 298770626 35280548 226923750 96421159 523108871 265102517 ...
output:
5202946193 5202946193 5202946193 5202946193 5202946193 5202946193 5202946193 5202946193 5202946193 5202946193 5202946193 5202946193 5202946193 5202946193 5202946193 5202946193 5202946193 5202946193 5202946193 5202946193 5202946193 5202946193 5202946193 5202946193 5202946193 5202946193 5202946193 520...
result:
ok 9000 numbers
Test #5:
score: -100
Time Limit Exceeded
input:
4 500000 3000 303543765 129078653 192039183 226458565 208138322 436645868 210834986 135457074 162914826 137413668 192916902 146302909 434058637 370665799 433071720 460608259 413021067 44008462 416238964 258228162 317315155 28299542 422136622 102236305 489978791 223662501 132197157 47793593 265792210...
output:
50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 50490529 504...