QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#693342 | #5415. Ropeway | MLK | WA | 3ms | 11816kb | C++14 | 3.0kb | 2024-10-31 15:59:45 | 2024-10-31 15:59:52 |
Judging History
answer
#include <bits/stdc++.h>
#define N (1000000 + 10) /*------------------ #define ------------------*/
#define M (400000 + 10)
#define MOD (1000000000 + 7)
//#define MOD (998244353)
#define INF (0x3f3f3f3f)
#define LNF (3e18)
#define mod(a,b) (((a)%(b)+(b))%(b))
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL,LL> PII;
typedef pair<LL,LL> PLL;
typedef pair<LL,LL> PIL;
typedef pair<LL,LL> PLI;
typedef pair<double,double> PDD;
LL n,k;
LL a[N],f[N],g[N],tmp[N];
string st;
LL q[N];
auto solve(){
cin >> n >> k;
for(LL i = 0;i <= n + 10;i ++ ) f[i] = g[i] = tmp[i] = q[i] = 0;
for(LL i = 1;i <= n;i ++ ) cin >> a[i];
cin >> st;
st = '1' + st + '1';
LL hh = 0,tt = -1;
q[++ tt] = 0;
for(LL i = 1;i <= n + 1;i ++ ){
while(hh <= tt && q[hh] < i - k) hh ++ ;
f[i] = f[q[hh]] + a[i];
if(st[i] == '0'){
while(hh <= tt && f[q[tt]] >= f[i]) tt -- ;
}else{
while(hh <= tt) tt -- ;
}
q[++ tt] = i;
}
hh = 0,tt = -1;
q[++ tt] = n + 1;
for(LL i = n;i >= 0;i -- ){
while(hh <= tt && q[hh] > i + k) hh ++ ;
g[i] = g[q[hh]] + a[i];
if(st[i] == '0'){
while(hh <= tt && g[q[tt]] >= g[i]) tt -- ;
}else{
while(hh <= tt) tt -- ;
}
q[++ tt] = i;
}
// for(LL i = 0;i <= n + 1;i ++ ) cout << f[i] << ' ';
// cout << '\n';
//
// for(LL i = 0;i <= n + 1;i ++ ) cout << g[i] << ' ';
// cout << '\n';
//
// cout << "==========\n";
LL Q;
cin >> Q;
while(Q -- ){
LL p,v,tv;
cin >> p >> v;
tv = a[p];
for(LL i = max(p - k + 1,0ll);i <= min(p + k,n + 1);i ++ )
tmp[i] = f[i];
f[p] = f[p] - a[p] + v;
a[p] = v;
hh = 0,tt = -1;
for(LL i = max(p - k + 1,0ll);i <= p;i ++ ){
while(hh <= tt && q[hh] > i + k) hh ++ ;
if(st[i] == '0'){
while(hh <= tt && f[q[tt]] >= f[i]) tt -- ;
}else{
while(hh <= tt) tt -- ;
}
q[++ tt] = i;
}
for(LL i = p + 1;i <= min(p + k,n + 1);i ++ ){
while(hh <= tt && q[hh] < i - k) hh ++ ;
// if(i == 4){
// cout << '\n';
// for(LL j = hh;j <= tt;j ++ ) cout << q[j] << ' ';
// cout << '\n';
// }
f[i] = f[q[hh]] + a[i];
//if(i == 4) cout << i << ' ' << f[i] << '\n';
if(st[i] == '0'){
while(hh <= tt && f[q[tt]] >= f[i]) tt -- ;
}else{
while(hh <= tt) tt -- ;
}
q[++ tt] = i;
}
// for(LL i = 0;i <= n + 1;i ++ ) cout << f[i] << ' ';
// cout << '\n';
//
// for(LL i = 0;i <= n + 1;i ++ ) cout << g[i] << ' ';
// cout << '\n';
LL ans = 2e9;
for(LL i = p + 1;i <= min(p + k,n + 1);i ++ )
ans = min(ans,f[i] + g[i] - a[i]);
cout << ans << '\n';
a[p] = tv;
for(LL i = max(p - k + 1,0ll);i <= min(p + k,n + 1);i ++ )
f[i] = tmp[i];
}
}
signed main(){
IOS
LL T = 1;
//
cin >> T;
while(T -- ) solve();
//while(T -- ) cout << (solve() ? "YES" : "NO") << '\n';
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 11800kb
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: 11816kb
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:
2000000000 2000000000 2000000000 2000000000 2000000000 2000000000 2000000000 2000000000 2000000000 2000000000 2000000000 2000000000 2000000000 2000000000 2000000000 2000000000 2000000000 2000000000 470735446 470735446 211705888 564509290 715543137 470735446 470735446 18 19 19 19 20 19 54 849950346 8...
result:
wrong answer 1st numbers differ - expected: '2472886431', found: '2000000000'