QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#273575 | #5415. Ropeway | Feet_McYeet | WA | 2ms | 3448kb | C++20 | 3.0kb | 2023-12-03 01:46:13 | 2023-12-03 01:46:13 |
Judging History
answer
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <iterator>
#include <algorithm>
// #include <bit>
#include <numeric>
#include <iomanip>
using namespace std;
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<short, short> pss;
#define el << '\n'
#define nl cout << '\n'
#define cina(a,n) for (int i=0; i<n; i++) cin >> a[i]
#define spc << ' '
#define forn(i,n) for (int i=0; i<n; i++)
#define forl(i,s,e) for (int i=s; i<e; i++)
#define pb push_back
#define fi first
#define se second
#define MAX *max_element
#define MIN *min_element
#define rsz resize
#define sz(x) ((int) x.size())
#define all(x) x.begin(), x.end()
#define bsi(x, v) (int) (lower_bound(x.begin(), x.end(), v) - x.begin())
const int inf = 1000000000;
const ll inf2 = 4000000000000000000;
void smin(int& a, int b) {if (b<a) a=b;}
void smax(int& a, int b) {if (b>a) a=b;}
void smin(ll& a, ll b) {if (b<a) a=b;}
void smax(ll& a, ll b) {if (b>a) a=b;}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t; cin >> t;
while (t--) {
int n, k; cin >> n >> k;
int a[n]; cina(a,n);
string ss; cin >> ss;
bool s[n]; forn(i,n) s[i] = (ss[i] == '1');
ll pv[n+1], sv[n+1];
int la[n], ra[n];
forn(i,n+1) pv[i] = sv[i] = 0;
int lb = 0;
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
pq.push({0,0});
forn(i,n) {
smax(lb, i-k+1);
while (pq.top().se < lb) pq.pop();
pv[i+1] = pq.top().fi + a[i];
pq.push({pv[i+1], i+1});
la[i] = lb;
if (s[i]) lb = i+1;
}
while (sz(pq)) pq.pop();
lb = n;
pq.push({0,n});
for (int i = n-1; i>=0; i--) {
smin(lb, i+k);
while (pq.top().se > lb) pq.pop();
sv[i] = pq.top().fi + a[i];
pq.push({sv[i], i});
ra[i] = lb;
if (s[i]) lb = i;
}
// forn(i,n+1) cout << pv[i] spc;
// nl;
// forn(i,n+1) cout << sv[i] spc;
// nl;
// forn(i,n) cout << ra[i] spc;
// nl;
// forn(i,n) cout << la[i] spc;
// nl;
int q; cin >> q;
while (q--) {
int p, v; cin >> p >> v;
p--;
if (s[p]) {
cout << pv[p+1] + sv[p] - 2*a[p] + v;
continue;
}
ll ans = pv[p+1] + sv[p] - 2*a[p] + v;
ll rm = inf2;
forl(i,1,k) {
// cout << p+i spc << p-k+i+1 el;
if (p+i<=ra[p]) smin(rm, sv[p+i]);
if (p-k+i+1>=la[p]) smin(ans, rm+pv[p-k+i+1]);
}
cout << ans el;
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3444kb
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: 3448kb
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:
24728864312299111966279605544526502021482417273966250869456122854795132521569560 2521569560 224090769025772849582521569560 276670019525118073442521569560 243843498626690772152682112324470735446 470735446 211705888564509290715543137470735446 470735446 181919192019 54849950346 849950346 849950346 8499...
result:
wrong output format Expected integer, but "247288643122991119662796055445...6250869456122854795132521569560" found