QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#786645#5415. RopewayharlemWA 3ms11812kbC++142.4kb2024-11-26 22:37:392024-11-26 22:37:40

Judging History

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

  • [2024-11-26 22:37:40]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:11812kb
  • [2024-11-26 22:37:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
typedef double db;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
template <typename Type>
using vec=vector<Type>;
template <typename Type>
using grheap=priority_queue<Type>;
template <typename Type>
using lrheap=priority_queue<Type,vector<Type>,greater<Type> >;
#define fir first
#define sec second
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=x;i>=y;i--)

const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7/*998244353*/;

const int N=5e5+5,K=3e3+5;

int n,k,q;
ll a[N];
bool mst[N];
ll f[N],g[N],t[N];
int hd,tl;
int pq[N];
void init(){
    pq[hd=tl=0]=0;
    f[0]=0;
    rep(i,1,n+1){
        while(hd<=tl&&i-pq[hd]>k)hd++;
        f[i]=f[pq[hd]]+a[i];
        while(hd<=tl&&f[pq[tl]]>=f[i])tl--;
        pq[++tl]=i;
        if(mst[i])hd=tl;
    }
    reverse(a+1,a+1+n);
    reverse(mst+1,mst+1+n);
    g[0]=0;
    pq[hd=tl=0]=0;
    rep(i,1,n+1){
        while(hd<=tl&&i-pq[hd]>k)hd++;
        g[i]=g[pq[hd]]+a[i];
        while(hd<=tl&&g[pq[tl]]>=g[i])tl--;
        pq[++tl]=i;
        if(mst[i])hd=tl;
    }
    reverse(g,g+1+n+1);
    reverse(a,a+1+n+1);
    reverse(mst+1,mst+1+n);
}

int p;
ll v;

void solve(){
    cin>>n>>k;
    rep(i,1,n)cin>>a[i];
    char c;
    rep(i,1,n){cin>>c;mst[i]=c-'0';}
    init();
    cin>>q;
    while(q--){
        cin>>p>>v;
        if(mst[p]){
            cout<<f[p]-a[p]+g[p]-a[p]+v<<"\n";
        }else{
            t[p]=f[p]-a[p]+v;
            int lb=p;
            ll ans=f[p]-a[p]+g[p]-a[p]+v;
            per(i,p-1,max(0,p-k)){
                t[i]=min(t[i+1],f[i]);
                chmin(lb,i);
                if(mst[i])break;
            }
            rep(i,p+1,min(n+1,p+k)){
                chmin(ans,t[i-k]+g[i]);
                if(mst[i])break;
            }
            cout<<ans<<"\n";
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int t;cin>>t;
    while(t--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 11772kb

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: 3ms
memory: 11812kb

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
566700980
202733816
2240907690
2577284958
202733816
2766700195
2511807344
202733816
2438434986
2669077215
2682112324
453440398
470735449
211705888
564509290
715543137
470735449
341886459
18
19
19
19
20
18
54
15465560
154655...

result:

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