QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#216660 | #5415. Ropeway | dd | WA | 4ms | 3552kb | C++20 | 4.4kb | 2023-10-15 20:48:00 | 2023-10-15 20:48:01 |
Judging History
answer
//#pragma GCC optimize ("Ofast,unroll-loops")
//#pragma GCC target ("avx2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define notall(x) x.begin()+1,x.end()
#define all(x) x.begin(),x.end()
#define mul_t int _t;cin>>_t;while(_t--)
const int int_inf = 1000000100;
const ll ll_inf = 1000000000000000100;
//writers
template<class T>
void writeln(const T &t) {
cout << t << '\n';
}
template<class T, class...args>
void writeln(const T &t, const args &...rest) {
cout << t << ' ';
writeln(rest...);
}
template<class T1>
void writeln(const vector<T1> &v) {
for (auto c : v)
cout << c << ' ';
cout << ' ' << '\n';
}
template<class T1, class T2>
void writeln(const vector<T1> &v, T2 n) {
for (T2 i = 1; i <= n; i++)
cout << v[i] << ' ';
cout << ' ' << '\n';
}
template<class T1, class T2>
void writeln(const pair<T1, T2> p) {
cout << p.first << ' ' << p.second << ' ' << '\n';
}
#define int ll
struct SegmentTree {
vector<long long> st, arr;
int size;
SegmentTree(int n) {
size = n;
st.assign(4 * n, ll_inf);
arr.assign(n, ll_inf);
}
void build(int node, int start, int end) {
if (start == end) {
st[node] = arr[start];
} else {
int mid = (start + end) / 2;
build(2 * node, start, mid);
build(2 * node + 1, mid + 1, end);
st[node] = min(st[2 * node], st[2 * node + 1]);
}
}
void update(int node, int start, int end, int idx, long long val) {
if (start == end) {
arr[idx] = val;
st[node] = val;
} else {
int mid = (start + end) / 2;
if (start <= idx && idx <= mid) {
update(2 * node, start, mid, idx, val);
} else {
update(2 * node + 1, mid + 1, end, idx, val);
}
st[node] = min(st[2 * node], st[2 * node + 1]);
}
}
long long query(int node, int start, int end, int left, int right) {
if (right < start || end < left) {
return ll_inf;
}
if (left <= start && end <= right) {
return st[node];
}
int mid = (start + end) / 2;
long long p1 = query(2 * node, start, mid, left, right);
long long p2 = query(2 * node + 1, mid + 1, end, left, right);
return min(p1, p2);
}
};
void solve(){
ll n,k;
cin>>n>>k;
vector<ll>a(n+2);
for(int i=1;i<=n;i++)cin>>a[i];
string s;
cin>>s;
set<int>must;
vector<int>num1;
s="1"+s+"1";
for(int i=0;i<=n+1;i++)if(s[i]=='1')must.insert(i),num1.push_back(i);
ll q;
//两个端点
auto cacl=[&](ll l,ll r)->ll
{
if(r<=l+1)return 0;
SegmentTree tr(r-l+1);
tr.build(1,0,r-l);
vector<ll>dp(r-l+1,ll_inf),b(r-l+1);
for(int i=0,j=l;j<=r;i++,j++)b[i]=a[j];
dp[0]=b[0];
//writeln("nowis",l,r);
tr.update(1,0,r-l,0,dp[0]);
for(int i=1;i<=r-l;i++)
{
ll nowl=max(0ll,i-k);
dp[i]=b[i]+tr.query(1,0,r-l,nowl,i-1);
tr.update(1,0,r-l,i,dp[i]);
}
// cout<<"b ";
// writeln(b);
// cout<<"dp ";
// writeln(dp);
return dp[r-l];
};
ll ans=0;
for(auto c:num1)ans+=a[c];
ll sz=num1.size();
for(int i=0;i<sz-1;i++)
{
ll l=num1[i],r=num1[i+1];
ll nowadd=cacl(l,r);
ans+=nowadd;
ans-=(a[l]+a[r]);
}
// writeln(ans);
cin>>q;
for(int i=1;i<=q;i++)
{
ll tmp=ans;
ll pos,xx;
cin>>pos>>xx;
// writeln("ssssssbbbb",pos,xx);
if(must.count(pos))
{
tmp+=(xx-a[pos]);
}
else
{
auto nowpos=prev(must.upper_bound(pos));
ll x=*nowpos,y=*next(nowpos);
ll sb=cacl(x,y);
tmp-=sb;
// writeln("sb1",x,sb);
ll lst=a[pos];
a[pos]=xx;
// writeln("apos",a[pos]);
sb=cacl(x,y);
tmp+=sb;
// writeln("sb2",sb);
a[pos]=lst;
}
writeln(tmp);
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(15);
mul_t
solve();
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3472kb
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: 4ms
memory: 3552kb
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:
-1901941366 -2075715831 -1578772352 -1724625649 -1957553831 -1866133236 -2089348284 -1853258237 -1853258237 -2133920107 -1797542839 -1853258237 -1608127602 -1863020453 -1853258237 -1936392811 -1705750582 -1692715473 146144035 146144035 -112885523 239917879 390951726 146144035 146144035 -13 -12 -12 -...
result:
wrong answer 1st numbers differ - expected: '2472886431', found: '-1901941366'