QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#694412#5415. RopewayHurrikaleWA 2ms9788kbC++142.4kb2024-10-31 17:54:142024-10-31 17:54:14

Judging History

你现在查看的是最新测评结果

  • [2024-10-31 17:54:14]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9788kb
  • [2024-10-31 17:54:14]
  • 提交

answer

#include<cstdio>
#include<queue>
#include<algorithm>
#define ll long long
#define LPos (Pos<<1)
#define RPos (LPos|1)
#define Mid ((L+R)>>1)
using namespace std;
ll Read()
{
	ll Output=0;
	char Input=getchar();
	while(Input<'0'||Input>'9')
	Input=getchar();
	while(Input>='0'&&Input<='9')
	{
		Output=Output*10+Input-'0';
		Input=getchar();
	}
	return Output;
}
int T;
ll A[500010];
int N,K;
char String[500010];
ll Prefix[500010],Suffix[500010];
int Queue[500010],Left,Right;
void Solve()
{
    N=Read(),K=Read();
    for(int i=1;i<=N;++i)
    A[i]=Read();
    A[N+1]=0;
    int Last=0;
    Queue[Right=1]=0;
    Left=1;
    Suffix[N+1]=Prefix[0]=0;
    scanf("%s",String+1);
    String[0]=String[N+1]='1';
    for(int i=1;i<=N+1;++i)
    {
        Last=max(Last,i-K);
        while(Left<=Right&&Queue[Left]<Last)
        ++Left;
        Prefix[i]=Prefix[Queue[Left]]+A[i];
        if(String[i]=='1')
        Last=i;
        while(Left<=Right&&Prefix[i]<=Prefix[Queue[Right]])
        --Right;
        Queue[++Right]=i;
    }
    Queue[Right=1]=N+1;
    Left=1,Last=N+1;
    for(int i=N;i>=0;--i)
    {
        Last=min(Last,i+K);
        while(Left<=Right&&Queue[Left]>Last)
        ++Left;
        Suffix[i]=Suffix[Queue[Left]]+A[i];
        if(String[i]=='1')
        Last=i;
        while(Left<=Right&&Suffix[i]<=Suffix[Queue[Right]])
        --Right;
        Queue[++Right]=i;
    }
    int Q=Read();
    for(int i=1;i<=Q;++i)
    {
        int P=Read(),V=Read();
        ll Ans=Prefix[P]+Suffix[P]-(A[P]<<1)+V;
        if(String[P]=='1')
        {
            printf("%lld\n",Ans);
            continue;
        }
        Queue[Right=1]=max(P-K+1,0);
        for(int j=max(P-K+1,0);j<P;++j)
        {
            while(Right&&Prefix[j]<=Prefix[Queue[Right]])
            --Right;
            Queue[++Right]=j;
        }
        Left=1;
        for(int j=P+1;j<=P+K-1&&j<=N+1;++j)
        {
            while(j-Queue[Left]>K)
            ++Left;
            Ans=min(Ans,Prefix[Queue[Left]]+Suffix[j]);
        }
        printf("%lld\n",Ans);
    }
// puts("Pre");
// for(int i=0;i<=N+1;++i)
// printf("%lld ",Prefix[i]);
// puts("\nSuf");
// for(int i=0;i<=N+1;++i)
// printf("%lld ",Suffix[i]);
// putchar('\n');
}
int main()
{
	T=Read();
    while(T--)
    {
        // Clear();
        Solve();
    }
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 9788kb

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: 2ms
memory: 7772kb

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
1765265336
2318835744
2240907690
2577284958
2318835744
2766700195
2511807344
2318835744
2438434986
2669077215
2682112324
341886459
470735446
211705888
564509290
715543137
470735446
146144035
18
19
19
19
20
15
54
15465560
15...

result:

wrong answer 8th numbers differ - expected: '2521569560', found: '1765265336'