QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#93617 | #5415. Ropeway | week | WA | 7ms | 9564kb | C++14 | 1.8kb | 2023-04-01 22:40:25 | 2023-04-01 22:40:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N= 5e5 + 10;
const int INF = 1e18;
typedef pair<int,int> PII;
int n,m,K,a[N];
string s;
int f[N],g[N],h[N];
int dp(int x,int y)
{
int old = a[x];
a[x] = y;
deque<PII> d;
int L = max(1ll,x - K);
int R = max(1ll,x - 1);
if(x - K <= 0) d.push_back({0,0});
for(int i=L; i<=R; i++)
{
if(s[i - 1] == '1') d.clear();
while(d.size() && d.back().first >= f[i]) d.pop_back();
d.push_back({f[i],i});
}
int res = INF;
for(int i=x; i<x + K && i <= n + 1; i++)
{
while(d.front().second < i - K) d.pop_front();
h[i] = d.front().first + a[i];
res = min(res, h[i] + g[i]);
if(s[i - 1] == '1') d.clear();
while(d.size() && d.back().first >= h[i]) d.pop_back();
d.push_back({h[i],i});
}
a[x] = old;
return res;
}
void solve(){
cin >> n >> K;
for(int i=1; i<=n; i++) cin >> a[i];
a[n + 1] = 0;
g[n + 1] = 0;
cin >> s;
s = s + "1";
deque<PII> d;
d.push_back({0,0});
for(int i=1; i<=n + 1; i++){
while(d.front().second < i - K) d.pop_front();
f[i] = d.front().first + a[i];
if(s[i - 1] == '1') d.clear();
while(d.size() && d.back().first >= f[i]) d.pop_back();
d.push_back({f[i],i});
}
d.clear();
d.push_back({0,n+1});
for(int i=n; i>=1; i--){
while(d.front().second > i + K) d.pop_front();
g[i] = d.front().first + a[i];
if(s[i - 1] == '1') d.clear();
while(d.size() && d.back().first >= g[i]) d.pop_back();
d.push_back({g[i],i});
}
for(int i=1; i<=n + 1; i++) g[i] -= a[i];
int q;
cin >> q;
while(q--)
{
int x,y;
cin >> x >> y;
cout << dp(x,y) << endl;
}
}
signed 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: 9564kb
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: 7ms
memory: 9520kb
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 2526111150 2577284958 2521569560 2766700195 2797010804 2521569560 2438434986 2669077215 2682112324 470735446 470735446 211705888 564509290 715543137 470735446 470735446 18 19 19 19 20 19 54 849950346 8...
result:
wrong answer 10th numbers differ - expected: '2240907690', found: '2526111150'