QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#425686 | #7279. Tricks of the Trade | Lynkcat# | 0 | 3ms | 14096kb | C++20 | 3.7kb | 2024-05-30 15:48:25 | 2024-05-30 15:48:28 |
Judging History
answer
#include<bits/stdc++.h>
#define poly vector<int>
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define mt make_tuple
#define pa pair < int,int >
#define fi first
#define se second
#define inf 1e18
#define mod 998244353
#define sz(x) ((int)((x).size()))
#define int ll
// #define N
using namespace std;
const int N=250005;
int cnt;
struct node
{
int x,y,ls,rs;
}tr[N*64];
int n,K;
int m;
int a[N],b[N],v[N][3];
int pos[N];
int rt[N];
poly g;
poly I[N],E[N];
int vis[N];
int update(int u,int l,int r,int L,int x,int y)
{
int k=++cnt;
tr[k]=tr[u];
tr[k].x+=x;
tr[k].y+=y;
if (l==r) return k;
int mid=l+(r-l)/2;
if (L<=mid) tr[k].ls=update(tr[u].ls,l,mid,L,x,y);
else tr[k].rs=update(tr[u].rs,mid+1,r,L,x,y);
return k;
}
int Mn,Sum;
void qry(int kr,int kl,int l,int r,int k)
{
if (l==r)
{
Mn=l;
Sum+=k*g[l-1];
return;
}
int mid=l+(r-l)/2;
int rt=tr[tr[kr].rs].x-tr[tr[kl].rs].x;
if (k>rt)
{
Sum+=tr[tr[kr].rs].y-tr[tr[kl].rs].y;
qry(tr[kr].ls,tr[kl].ls,l,mid,k-rt);
} else
{
qry(tr[kr].rs,tr[kl].rs,mid+1,r,k);
}
}
void BellaKira()
{
cin>>n>>K;
for (int i=1;i<=n;i++)
cin>>a[i],a[i]+=a[i-1];
for (int i=1;i<=n;i++)
cin>>b[i];
for (int i=1;i<=n;i++)
{
v[i][0]=b[i]+a[i-1];
v[i][1]=b[i];
v[i][2]=b[i]-a[i];
}
if (K==1)
{
int mn=inf;
for (int i=1;i<=n;i++) mn=min(mn,b[i]-a[i]+a[i-1]);
cout<<mn<<'\n';
for (int i=1;i<=n;i++)
if (b[i]-a[i]+a[i-1]==mn) cout<<1;
else cout<<0;
cout<<'\n';
return;
}
for (int i=1;i<=n;i++)
{
g.push_back(v[i][1]);
}
sort(g.begin(),g.end());
g.erase(unique(g.begin(),g.end()),g.end());
for (int i=1;i<=n;i++)
{
pos[i]=lower_bound(g.begin(),g.end(),v[i][1])-g.begin()+1;
}
m=sz(g);
for (int i=1;i<=n;i++)
{
rt[i]=rt[i-1];
rt[i]=update(rt[i],1,m,pos[i],1,v[i][1]);
}
int ans=-inf;
int lst=1;
for (int j=2;j<=n;j++)
{
int mx=-inf,nxt=0;
for (int i=lst;i<j;i++)
{
if (j-i-1>=K-2)
{
Mn=sz(g)+1,Sum=0;
if (K-2)
qry(rt[j-1],rt[i],1,m,K-2);
Mn--;
if (Mn<sz(g)) Mn=g[Mn]; else Mn=inf;
if (Sum+v[j][2]+v[i][0]>mx)
{
mx=Sum+v[j][2]+v[i][0];
nxt=i;
}
ans=max(ans,Sum+v[j][2]+v[i][0]);
}
}
lst=nxt;
}
for (int i=1;i<=n;i++)
{
for (int j=i+1;j<=n;j++)
{
Mn=inf,Sum=0;
if (j-i-1>=K-2)
{
Mn=sz(g)+1,Sum=0;
if (K-2)
qry(rt[j-1],rt[i],1,m,K-2);
Mn--;
if (Mn<sz(g)) Mn=g[Mn]; else Mn=inf;
if (Sum+v[j][2]+v[i][0]==ans) I[i].push_back(Mn),E[j].push_back(Mn),vis[i]=vis[j]=1;
}
}
}
multiset<int>S;
for (int i=1;i<=n;i++)
{
for (auto u:I[i]) S.insert(u);
for (auto u:E[i]) S.erase(S.find(u));
if (S.size()&&v[i][1]>=(*S.begin())) vis[i]=1;
}
cout<<ans<<'\n';
for (int i=1;i<=n;i++) cout<<vis[i];
cout<<'\n';
}
signed main()
{
IOS;
cin.tie(0);
int T=1;
while (T--)
{
BellaKira();
}
}
/*list:
1.mod 998244353 or 1e9+7 or ???
2.N
3.duipai shuju xingtai duoyidian
...
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 0ms
memory: 14032kb
input:
5 3 3 5 2 3 6 2 1 5 2 3
output:
-1 00111
result:
ok all correct
Test #2:
score: 10
Accepted
time: 3ms
memory: 13880kb
input:
200 40 81 50 87 91 54 1 77 68 19 84 28 81 45 64 4 13 25 89 12808135 86 40 73 47 18 82 79 11 96 16 34 80 36 8 5 60 76 86 84 36 37 96 55 68 12807879 51 89 57 30 100 11 44 19 96 32 9 68 41 12808009 5 58 12807939 92 68 67 78 32 57 49 71 92 64 35 89 76 81 36 6 6 53 31 85 79 5 85 1 91 17 37 25 91 54 29 47...
output:
12807909 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111111111111111111111111111000000000000000000000000000000000000
result:
ok all correct
Test #3:
score: 10
Accepted
time: 3ms
memory: 13932kb
input:
200 41 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
81 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111000000
result:
ok all correct
Test #4:
score: 10
Accepted
time: 0ms
memory: 14096kb
input:
5 2 1 6 1 5 2 4 1 6 2 4
output:
2 10111
result:
ok all correct
Test #5:
score: 10
Accepted
time: 0ms
memory: 13752kb
input:
7 3 5 1 1 1 1 1 5 1 1 1 1 1 1 1
output:
0 0111110
result:
ok all correct
Test #6:
score: 0
Wrong Answer
time: 2ms
memory: 13872kb
input:
200 100 142654162 64490063 513345044 219974445 84112685 711899650 33120992 176027514 802361343 2414916 941549932 786288853 94273368 829024564 352947721 355629698 903479794 326383768 720620114 271371691 786997028 138881060 711795174 536092340 290169962 938690480 710723910 231424065 468554799 44519400...
output:
-2420357501 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
result:
wrong answer wrong answer on the first question
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Time Limit Exceeded
Test #30:
score: 10
Accepted
time: 2ms
memory: 13808kb
input:
5 2 1 6 1 5 2 4 1 6 2 4
output:
2 10111
result:
ok all correct
Test #31:
score: 0
Time Limit Exceeded
input:
250000 2 18 35 29 35 18 610084694 18 35 29 35 18 448867144 18 35 29 35 18 971272498 18 35 29 35 18 890430190 18 35 29 35 18 655685684 18 35 29 35 18 234608237 18 35 29 35 18 894586749 18 35 29 35 18 442195168 18 35 29 35 18 341564617 18 35 29 35 18 985069087 18 35 29 35 18 967546483 18 35 29 35 18 5...
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%