QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#109828 | #5415. Ropeway | zhuibao | WA | 5ms | 11640kb | C++20 | 2.8kb | 2023-05-30 18:38:05 | 2023-05-30 18:38:08 |
Judging History
answer
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll>pi;
#define int ll
#define X first
#define Y second
#define fer(i,a,n) for(int i=a;i<=n;i++)
#define ref(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,x) memset(a,x,sizeof a)
#define ac IO;int t;cin>>t;while(t--)solve()
#define AC signed main(){IO;solve();}
#define NO {cout<<"No"<<endl;return;}
#define YES {cout<<"Yes"<<endl;return;}
#define re(a) {cout<<a<<endl;return;}
#define all(v) v.begin(),v.end()
//ofstream fout("out.txt", ios::out);
//ifstream fin("in.txt", ios::in);
//#define cout fout
//#define cin fin
//--------------------瑞神神中神--------------------
//--------------------刘魔魔中魔--------------------
const int N=5e5+10;
int a[N],f[N],g[N],dp[N];
vector<int>vec;
pi q[N];
int n,m;
string str;
void init()
{
for(int i=0;i<=n+1;i++)
{
f[i]=g[i]=dp[i]=0;
q[i]={0,0};
}
vec.clear();
}
void solve()
{
cin>>n>>m;
init();
fer(i,1,n)
{
cin>>a[i];
}
a[n+1]=0;a[0]=0;
cin>>str;str=" "+str;
int tt=-1,hh=0;
q[++tt]={0,0};
vec.push_back(0);
for(int i=1;i<=n+1;i++)
{
while(hh<=tt&&(i-q[hh].Y)>m)hh++;
f[i]=q[hh].X+a[i];
while(hh<=tt&&q[tt].X>=f[i])tt--;
if(str[i]=='1')
{
while(hh<=tt)tt--;
vec.push_back(i);
}
q[++tt]={f[i],i};
}
vec.push_back(n+1);
tt=-1,hh=0;
q[++tt]={0,n+1};
for(int i=n;i>=0;i--)
{
while(hh<=tt&&(q[hh].Y-i)>m)hh++;
g[i]=q[hh].X+a[i];
while(hh<=tt&&q[tt].X>=g[i])tt--;
if(str[i]=='1')
{
while(hh<=tt)tt--;
}
q[++tt]={g[i],i};
}
tt=-1;hh=0;
q[++tt]={0,0};
for(int i=1;i<=n;i++)
{
while(hh<=tt&&i-q[hh].Y>m)hh++;
dp[i]=q[hh].X+g[i];
while(hh<=tt&&q[tt].X>=f[i])tt--;
if(str[i]=='1')
{
while(hh<=tt)tt--;
}
q[++tt]={f[i],i};
}
int op;
cin>>op;
while(op--)
{
int id,x;
cin>>id>>x;
int res=dp[id]-a[id]+x;
if(str[id]=='1')
{
cout<<res<<endl;
continue;
}
int mi=1e17;
auto it= lower_bound(all(vec),id);
int l=*(it-1);l=max(id-m+1,l);
if(*it==id)it++;
int r=*it;
for(int i=l;i<id;i++)
{
if(i+m<=r)
mi=min(mi,g[i+m]);
res=min(res,f[i]+mi);
}
cout<<res<<endl;
}
}
signed main()
{
ac;
}
詳細信息
Test #1:
score: 100
Accepted
time: 5ms
memory: 11624kb
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: 1ms
memory: 11640kb
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 2584701013 2712540666 2240907690 2577284958 2826535456 2766700195 2511807344 2814193324 2438434986 2669077215 2682112324 498292963 729032050 211705888 564509290 715543137 492281467 639116182 18 19 19 19 20 21 54 1685424960 ...
result:
wrong answer 8th numbers differ - expected: '2521569560', found: '2584701013'