QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#520790 | #5415. Ropeway | potential | WA | 3ms | 9840kb | C++20 | 3.5kb | 2024-08-15 15:48:48 | 2024-08-15 15:48:49 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
# define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
# define int long long
# define lowbit(x) (x & (-x))
# define fi first
# define se second
// # define endl '\n'
inline int Read();
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
const int N = 1e6 + 10;
map <int, int> mp;
vector <int> v;
int a[N], dp[N], dp2[N], dp3[N];
string b;
deque <int> q;
void Solve(){
int n, k, m;
cin >> n >> k;
for(int i = 1; i <= n; i ++){
cin >> a[i];
dp[i] = 1e18;
dp2[i] = 1e18;
dp3[3] = 0;
}
dp3[0] = dp3[n + 1] = 0;
dp[n + 1] = dp2[0] = 1e18;
dp[0] = dp2[n + 1] = 0;
a[0] = a[n + 1] = 0;
cin >> b;
b = "1" + b + "1";
q.push_back(0);
for(int i = 1; i <= n + 1; i ++){
while(q.size() && i - q.front() > k) q.pop_front();
dp[i] = dp[q.front()] + a[i];
while(q.size() && dp[q.back()] > dp[i] && b[q.back()] == '0') q.pop_back();
if(b[i] == '1'){
while(q.size()) q.pop_back();
}
q.push_back(i);
}
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();
dp2[i] = dp2[q.front()] + a[i];
while(q.size() && dp2[q.back()] > dp2[i] && b[q.back()] == '0') q.pop_back();
if(b[i] == '1'){
while(q.size()) q.pop_back();
}
q.push_back(i);
}
// for(int i = 1; i <= n; i ++){
// cout << a[i] <<" ";
// }
// cout << "\n********************\n";
// for(int i = 0; i <= n + 1; i ++){
// cout << dp[i] <<" ";
// }
// cout << "****\n";
// cout << "\n********************\n";
// for(int i = 0; i <= n + 1; i ++){
// cout << dp2[i] <<" ";
// }
// cout << "\n********************\n";
cin >> m;
while(m --){
int x, y;
cin >> x >> y;
while(q.size()) q.pop_back();
for(int i = max(x - k, 0ll); i <= min(x + k, n + 1); i ++){
if(i < x) {
dp3[i] = dp[i];
while(q.size() && dp3[q.back()] > dp3[i] && b[q.back()] == '0') q.pop_back();
if(b[i] == '1'){
while(q.size()) q.pop_back();
}
q.push_back(i);
continue;
}
while(q.size() && i - q.front() > k) q.pop_front();
if(i != x) dp3[i] = dp3[q.front()] + a[i];
else dp3[i] = dp3[q.front()] + y;
while(q.size() && dp3[q.back()] > dp3[i] && b[q.back()] == '0') q.pop_back();
if(b[i] == '1'){
while(q.size()) q.pop_back();
}
q.push_back(i);
}
int ans = 1e18;
// for(int i = max(x - k, 0ll); i < min(x + k, n + 1); i ++){
// cout <<"i =" << i <<" " << dp3[i] <<"\n";
// }
// cout << "****************\n";
for(int i = x; i <= min(x + k, n + 1); i ++){
ans = min(ans, dp3[i] + dp2[i] - a[i]);
}
cout << ans <<"\n";
}
}
signed main(){
IOS;
int T = 1;
cin >> T;
while (T--)
Solve();
return 0;
}
inline int Read(){
int x = 0, f = 1; char c = getchar();
while (c < '0' || c > '9'){ if (c == '-') f = -1; c = getchar();}
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 9736kb
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: 9840kb
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 2992305006 470735446 2733275448 3086078850 3237112697 470735446 2992305006 1000000000000000000 1000000...
result:
wrong answer 19th numbers differ - expected: '470735446', found: '2992305006'