QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#722130 | #5415. Ropeway | Repeater# | WA | 1ms | 5176kb | C++20 | 2.5kb | 2024-11-07 17:57:03 | 2024-11-07 17:57:03 |
Judging History
answer
#include<iostream>
using namespace std;
#include<vector>
#include<string>
using i64 = long long;
const int N = 5e5 + 1;
vector<int> Log(N);
void init(){
Log[1] = 0;
for(int i = 2; i < N; ++i){
Log[i] = Log[i >> 1] + 1;
}
return;
}
void build(vector<i64>& a, vector<vector<i64>>& st){
st.assign(a.size(), vector<i64>(Log[a.size()]));
for(int i = 0; i < a.size(); ++i) st[i][0] = a[i];
for(int i = 1; i < Log[a.size()]; ++i){
int d = 1 << (i - 1);
for(int j = 0; j + (1 << i) < a.size(); ++j){
st[j][i] = min(st[j][i - 1], st[j + d][i - 1]);
}
}
return;
}
i64 tquery(int l, int r, vector<vector<i64>>& st){
int L = Log[r - l + 1];
return min(st[l][L], st[r - (1 << L) + 1][L]);
}
void solve(){
i64 n, k;
cin >> n >> k;
vector<i64> a(n + 1);
for(int i = 1; i <= n; ++i) cin >> a[i];
string s;
cin >> s;
vector<i64> pref(n + 2), suff(n + 2);
vector<i64> q(n + 2);
int l = 0, r = -1;
q[++r] = 0;
for(int i = 1; i <= n + 1; ++i){
pref[i] = a[i] + pref[q[l]];
if(i != n + 1){
if(s[i - 1] == '0')
while(l <= r && pref[q[r]] > pref[i]) --r;
else r = l - 1;
q[++r] = i;
while(l <= r && i - q[l] >= k) ++l;
}
}
l = 0, r = -1;
q[++r] = 0;
for(int i = n; i >= 0; --i){
suff[i] = a[i] + suff[q[l]];
if(i != 0){
if(s[i - 1] == '0')
while(l <= r && suff[q[r]] > suff[i]) --r;
else r = l - 1;
q[++r] = i;
while(l <= r && q[l] - i >= k) ++l;
}
}
vector<vector<i64>> st;
build(pref, st);
vector<i64> fn(n + 2), sn(n + 2);
int t1 = 0, t2 = n + 1;
fn[0] = 0;
for(int i = 1; i <= n; ++i){
if(s[i] == '1') t1 = i;
if(s[n - i + 1] == '1') t2 = n - i + 1;
fn[i] = t1;
sn[n - i + 1] = t2;
}
int query = 0;
cin >> query;
for(int i = 0; i < query; ++i){
i64 p, v;
cin >> p >> v;
i64 ans = pref[p] + suff[p] - 2 * a[p] + v;
if(s[p - 1] == '0')
for(int j = p + 1; j <= min(p + k - 1, min(sn[p], n + 1)); ++j){
ans = min(ans, tquery(max(0LL, max(fn[p], j - k)), p - 1, st) + suff[j]);
}
cout << ans << "\n";
}
return;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
init();
int t = 1;
cin >> t;
while(t--) solve();
return 0;
}
/*
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
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5024kb
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: 0ms
memory: 5176kb
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 2584701013 2712540666 2240907690 2577284958 2826535456 2766700195 2511807344 2814193324 2438434986 2669077215 2682112324 498292963 511149674 211705888 564509290 715543137 492281467 639116182 18 19 19 19 20 21 51 309981921 3...
result:
wrong answer 8th numbers differ - expected: '2521569560', found: '2584701013'