QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#240600 | #5415. Ropeway | stcmuyi | WA | 2ms | 3632kb | C++14 | 2.6kb | 2023-11-05 16:44:37 | 2023-11-05 16:44:38 |
Judging History
answer
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define i64 long long
#define int long long
#define endl '\n'
#define lb(x) ((x) & (-x))
using namespace std;
const i64 mod = 1e18;
const int maxn = 1e15;
signed main()
{
IOS;
int t; cin >> t;
while(t--)
{
int n,k; cin >> n >> k;
vector<int> a(n+2);
for(int i = 1; i <= n; ++i) cin >> a[i];
string s; cin >> s;
s = " " + s;
s.push_back('0');
vector<int> per(n+2,mod);
per[0] = 0;
deque<int> q;
q.push_back(0);
for(int i = 1; i <= n+1; ++i)
{
while(q.size() && i - q.front() > k) q.pop_front();
per[i] = per[q.front()] + a[i];
while(q.size() && per[q.back()] >= per[i]) q.pop_back();
if(s[i] == '1')
{
while(q.size()) q.pop_back();
}
q.push_back(i);
}
vector<int> suf(n+2,mod);
suf[n+1] = 0;
while(q.size()) q.pop_back();
q.push_back(n+1);
for(int i = n; i >= 0; --i)
{
while(q.size() && q.front() - i > k) q.pop_front();
suf[i] = suf[q.front()] + a[i];
while(q.size() && suf[q.back()] >= suf[i]) q.pop_back();
if(s[i] == '1')
{
while(q.size()) q.pop_back();
}
q.push_back(i);
}
int op; cin >> op;
while(op--)
{
int x,y; cin >> x >> y;
deque<pair<int,int> > g;
for(int i = max(0LL,x-k); i < x; ++i)
{
while(g.size() && g.front().first > per[i]) g.pop_front();
if(s[i] == '1')
{
while(g.size()) g.pop_back();
}
g.push_back({per[i],i});
}
int mx = mod;
for(int i = x; i <= min(x+k,n+1); ++i)
{
while(g.size() && i - g.front().second > k) g.pop_front();
int res = g.front().first;
if(i == x) res += y;
else res += a[i];
mx = min(mx,res + suf[i] - a[i]);
if(s[i] == '1')
{
while(g.size()) g.pop_back();
}
g.push_back({res,i});
}
cout << mx << endl;
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
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: 3632kb
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 54 849950346 8...
result:
wrong answer 307th numbers differ - expected: '778415182', found: '865701124'