QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#106190#5415. RopewayzhuidaoWA 4ms3432kbC++202.6kb2023-05-16 20:28:062023-05-16 20:28:11

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-16 20:28:11]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:3432kb
  • [2023-05-16 20:28:06]
  • 提交

answer

#include<bits/stdc++.h>
#include<numeric>
using namespace std;
template<typename typC,typename typD> bool cmin(typC &x,const typD &y) { if (y<x) { x=y; return 1; } return 0; }
template<typename typC,typename typD> bool cmax(typC &x,const typD &y) { if (x<y) { x=y; return 1; } return 0; }
#define ll long long
#define pb emplace_back
#define fs first
#define sc second
#define pi pair<ll,ll>
#define mpi make_pair
#define re(a) {cout<<a<<endl;return;}
#define all(v) v.begin(),v.end()
#define fr(i,a,n)  for(int i=a;i<=n;i++)
const int N = 2e2+ 7;
const ll inf = 1e15;
const int mod =1e9+7;
//#define cin fin
//ifstream fin("in.txt",ios::in);
//function<void(int,int)>dfs=[&](int x,int y)->void{};
struct Smaldeque{
    int k;
    deque<pair<int,ll>>dq;
    void push(int p,ll px){
        while(!dq.empty()){
            if(px>dq.back().second){
                dq.push_back({p,px});
                break;
            }
            else    dq.pop_back();
        }
        if(dq.empty()){
            dq.push_back({p,px});
        }
        if(p-dq.front().first>=k){
            dq.pop_front();
        }
    };
    int mi(){
        return dq.front().second;
    }
};
void solve() {
    ll n,k;    cin>>n>>k;
    vector<ll>a(n+3,0),b(n+2,0),pre(n+3,0),suf(n+3,0);
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    a[n+1]=0;
    string s;   cin>>s;
    ll ans=0;
    for(int i=0;i<s.size();i++)
        if(s[i]=='1'){
            ans+=a[i+1];
            a[i+1]=0;
        }
    Smaldeque dq1,dq2;
    dq1.k=k;    dq2.k=k;
    dq1.push(0,0);
    dq2.push(0,0);
    for(int i=1;i<=n+1;i++){
        pre[i]=dq1.mi()+a[i];
        dq1.push(i,pre[i]);
    }
    for(int i=n+1;i>=0;i--){
        suf[i]=dq2.mi()+a[i];
        dq2.push(n+2-i,suf[i]);
    }
    int q;  cin>>q;
    while(q--){
        ll add=0;
        ll p,v;    cin>>p>>v;
        if(s[p-1]=='1') cout<<ans-b[p]+v<<"\n";
        else{
            Smaldeque dqq;
            dqq.k=k;
            for(ll i=max(0ll,p-k+1);i<p;i++){
                dqq.push(i,pre[i]);
            }
            dqq.push(p,pre[p]-a[p]+v);
            add=pre[p]+suf[p]-2*a[p]+v;
            for(int i=p+1;i<=min(p+k-1,(ll)n+1);i++){
                add=min(dqq.mi()+suf[i],add);
                dqq.push(i,dqq.mi()+a[i]);
            }
            cout<<ans+add<<"\n";
        }
    }
}
signed main() {
    ios::sync_with_stdio(0);cin.tie(0);
//  #ifdef LOCAL
//  freopen("in.txt", "r", stdin);
//  #endif
    int _ = 1;
    cin >> _;//处理多组样例T
    while (_--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3380kb

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: 4ms
memory: 3432kb

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
42
849950346
8...

result:

wrong answer 32nd numbers differ - expected: '54', found: '42'