QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#74118 | #2122. Wystawa [A] | wind_cross | 0 | 1219ms | 13944kb | C++20 | 4.3kb | 2023-01-30 20:25:14 | 2023-01-30 20:25:15 |
Judging History
answer
#pragma GCC optimize(2)
#pragma GCC optimize("Ofast", "inline", "-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<bits/stdc++.h>
using namespace std;
inline char nc()
{
static char buf[1000005],*l,*r;
return l==r&&(r=(l=buf)+fread(buf,1,1000005,stdin),l==r)?EOF:*l++;
}
template <class code>inline code read(const code &a)
{
code x=0;short w=0;char ch=0;
while(!isdigit(ch)) {w|=ch=='-';ch=nc();}
while(isdigit(ch)) {x=(x<<3)+(x<<1)+(ch^48);ch=nc();}
return w?-x:x;
}
void print(__int128 x){
if(x<0)putchar('-'),x=-x;
if(x>=10)print(x/10);
putchar(x%10+48);
}
int a[100005],b[100005],n,k,xz[100005],c[100005];
long long xd[400005],tag[400005];
int xd1[400005];
void push_down(int root){
if(!tag[root])return;
int lc=root<<1,rc=root<<1|1;
tag[lc]+=tag[root];tag[rc]+=tag[root];
xd[lc]+=tag[root];xd[rc]+=tag[root];
tag[root]=0;
}
void upd1(int root,int x,int zl,int zr,int v){
if(zl==zr){
xd1[root]=v;
return;
}
int mid=(zl+zr)>>1;
if(x<=mid)upd1(root<<1,x,zl,mid,v);
else upd1(root<<1|1,x,mid+1,zr,v);
xd1[root]=max(xd1[root<<1],xd1[root<<1|1]);
}
int cx1(int root,int l,int r,int zl,int zr){
if(zl>r||zr<l)return -2e9;
if(zl>=l&&zr<=r)return xd1[root];
int mid=(zl+zr)>>1;
return max(cx1(root<<1,l,r,zl,mid),cx1(root<<1|1,l,r,mid+1,zr));
}
void upd(int root,int l,int r,int zl,int zr,int v){
if(zl>r||zr<l)return;
if(zl>=l&&zr<=r){
xd[root]+=v;
tag[root]+=v;
return;
}
push_down(root);
int mid=(zl+zr)>>1;
upd(root<<1,l,r,zl,mid,v);upd(root<<1|1,l,r,mid+1,zr,v);
xd[root]=max(xd[root<<1],xd[root<<1|1]);
}
long long cx(int root,int l,int r,int zl,int zr){
if(zl>r||zr<l)return -1e18;
if(zl>=l&&zr<=r)return xd[root];
push_down(root);
int mid=(zl+zr)>>1;
return max(cx(root<<1,l,r,zl,mid),cx(root<<1|1,l,r,mid+1,zr));
}
int ef(int root,int zl,int zr,long long v1,long long v2,int v3){
if(zl==zr){
// if(zl==15)printf("%lld\n",cx(1,1,zl,1,n)-cx1(1,zl,n,1,n)-cx(1,zl+1,n,1,n));
if(max(v1,xd[root])-max(v3,xd1[root])<=v2){
return zl;
}
return 0;
}
push_down(root);
int mid=(zl+zr)>>1,lc=root<<1,rc=root<<1|1;
long long n1=max(v1,xd[lc]),n2=max(v2,xd[rc]),n3=max(v3,max(xd1[rc],b[mid]));
if(n1-n3<=n2){
int fx=ef(root<<1|1,mid+1,zr,n1,v2,v3);
if(fx==0)return mid;
return fx;
}else return ef(root<<1,zl,mid,v1,n2,max(v3,xd1[rc]));
}
long long getz(int x){
if(x==0)return 1e18;
// printf("%lld %lld %lld ",cx(1,1,x,1,n),cx1(1,x,n,1,n),cx(1,x+1,n,1,n));
return max(cx(1,1,x,1,n)-cx1(1,x,n,1,n),cx(1,x+1,n,1,n));
}
int check(long long x){
memset(xd,0,sizeof(xd));
memset(xd1,0,sizeof(xd1));
memset(tag,0,sizeof(tag));
int sc=0;
for(int i=1;i<=n;i++)c[i]=max(b[i]-a[i],0),xz[i]=0;
for(int i=1;i<=n;i++){
upd(1,1,i,1,n,b[i]);
upd1(1,i,1,n,c[i]);
while(xd[1]>x&&sc<i){
int wz=ef(1,1,n,-1e18,-1e18,-2e9);
// if(wz<i)while(cx1(1,wz,n,1,n)!=c[wz])++wz;
--wz;
while(c[wz]<0&&wz<i)++wz;if(wz<i&&getz(wz)>=getz(wz+1)&&c[wz+1]>0)++wz;
// printf("%d %d %d %d %lld %lld\n",wz,i,c[wz+1],cx1(1,wz,n,1,n),xd[1],getz(wz+1),getz(wz));
upd(1,1,wz,1,n,-c[wz]);c[wz]=-2e9;upd1(1,wz,1,n,c[wz]);xz[wz]=1;
++sc;
}
if(xd[1]>x||sc>k)return -1;
}
return sc;
}
signed main()
{
// freopen("text.in","r",stdin);
// freopen("text.out","w",stdout);
n=read(n),k=read(k);
int fg=0;
for(int i=1;i<=n;i++)a[i]=read(a[i]);
for(int i=1;i<=n;i++){
b[i]=read(b[i]);
fg+=(a[i]<=b[i]);
}
int op=0;
if(fg<k){
op=1;
k=n-k;
for(int i=1;i<=n;i++)swap(a[i],b[i]);
}
long long l=0,r=1e14,kx=1e14;
while(l<=r){
long long mid=(l+r)>>1;
if(check(mid)!=-1)kx=mid,r=mid-1;
else l=mid+1;
}
printf("%lld\n",kx);
int sy=k-check(kx);
for(int i=1;i<=n;i++){
if(xz[i]^op)putchar('A');
else if(a[i]<=b[i]&&sy){
putchar('A');
--sy;
}else putchar('B');
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 18ms
memory: 11928kb
input:
6 2 -1 7 0 2 -5 0 3 1 4 -3 -3 12
output:
12 ABBBAB
result:
wrong answer read 12 but the jury's answer is 4
Subtask #2:
score: 0
Wrong Answer
Test #28:
score: 0
Wrong Answer
time: 16ms
memory: 12456kb
input:
80 15 -806772 -117802 266998 190197 -579000 615552 862955 -727153 870975 433653 583521 996193 563471 -615416 -924633 -296705 258551 -962057 -516030 -639148 -196720 656594 -667491 179513 98453 732582 -656179 525953 -955189 -711999 -708631 -6539 198681 -390094 611214 473002 -685751 787723 -511023 -183...
output:
1000383 ABABBBBBBBABABABBBABBBBBBBBBBABBBBBBBBBBBBBBBABABBBBBABBBBBBBBBBBBBBBBBAAAAABBBB
result:
FAIL WTF you have a better plan???
Subtask #3:
score: 0
Wrong Answer
Test #49:
score: 0
Wrong Answer
time: 16ms
memory: 12372kb
input:
400 35 282603 437907 189144 -306523 875091 -129096 135690 959139 919604 -510810 18016 -898443 -410507 -528852 -639057 503910 461833 267527 244577 -103136 -909424 -892963 -870210 -89935 509282 -930568 808009 773531 257190 -828648 -861529 -970580 -539999 260846 -620133 -979364 640196 388456 491785 -81...
output:
2191972 BABBBBBBBBBBBBBBBBBBBABBBBBBBBBABBBBBBBBBBBBBABABBABABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBABBBBABABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBABBBBBBAAAABABBBBBBBBBBBBBBBBBABBBBBBBBAABBABABBBBBBBBBABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBAA...
result:
wrong answer read 2191972 but the jury's answer is 1451726
Subtask #4:
score: 0
Wrong Answer
Test #70:
score: 0
Wrong Answer
time: 36ms
memory: 11704kb
input:
2000 196 53359475 -389458277 27443906 213187393 525501489 -563370396 -780381693 990456678 -966127727 -926000233 -208464373 99915107 429573188 471624215 -533030054 790604637 -643361957 -590004012 412092763 -856885908 -857464588 176819165 -218862254 802719311 794718647 525976558 341493086 692047249 14...
output:
3522046104 BBBBBBBBBABAABBBBBBBBBBBBBBBBBBBBBBBBBBABABBBBBBBBBBBBBBBBBBBBBBBBABABBBBBBBBBABBAAABABBBBBBBBBBBBBBBBBBBBBBBBBBABBAAABAABABABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBAABABBBBBBBBBBABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
result:
wrong answer read 3522046104 but the jury's answer is 2939757937
Subtask #5:
score: 0
Wrong Answer
Test #91:
score: 0
Wrong Answer
time: 88ms
memory: 12300kb
input:
8000 819 -80520 58858 -66529 -89399 -29326 -30844 -11574 101653 -19630 11590 -82857 -41398 47160 -103616 -72194 58679 39849 -58831 -74715 -21618 -42309 -108923 -62472 88514 82625 -38663 17205 -19790 -88376 -108625 67220 -93508 72195 72062 55863 118603 -58888 75786 -113297 -53630 -24366 119300 19571 ...
output:
323537 ABBAAAABABAABBABBBBBBAAAAABBAABABAABABBBBBBBBBBBBABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBABABBBBBBBBBBBABABBBBBBBBBBBBBBBBBAAAABBBBBABABBBBBBBBBBBBBABABBBABBBBBBABABBBBBBBBBBBBBBBABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBABBBAABABBBBBBBBBBBBBBBBBBBBBBBBBBB...
result:
FAIL WTF you have a better plan???
Subtask #6:
score: 0
Wrong Answer
Test #113:
score: 0
Wrong Answer
time: 309ms
memory: 13288kb
input:
25000 2601 684640294 598432913 -623227598 -736881259 -283494811 310898894 999454243 606030163 480256573 -699956166 388593535 -71688332 824098087 -969996868 53222581 730834964 -294074303 -949074306 -245586236 -170646877 -543582352 -466099725 -422182532 218666222 -822502298 -448284895 465111319 550729...
output:
2987102435 BBAAABBBBABABABBBAAAAABBAAABAAABAAAABAABBBAABBABAABBABBBBAABBABBAAAABABABABBABABAAABABBBAABBBBAABAAABAAABAABAAAABAABABBAABBBBABAABBAABBBAAABBBAABBBBAAAAAABAAAAAAABAABBBBBABBABABAAAABBAABABAAAABAABAAAAAAABABAAABBBBBABABABBBABBBABBAABBABAABBBBABAABABAAABABBABABABABBAABAAAABBABAABAABAABAABBA...
result:
FAIL WTF you have a better plan???
Subtask #7:
score: 0
Wrong Answer
Test #134:
score: 0
Wrong Answer
time: 419ms
memory: 13520kb
input:
50000 5073 401620049 252597114 638998890 -773942367 -994194991 773972290 755430111 -523539687 -749222285 70295502 406924746 -866460865 -321006536 -20842814 -717101098 238603919 -973981419 -263358138 341137321 -595132691 346299278 -897934865 -155536848 753555039 -925676770 -262539063 -447140814 22418...
output:
4159789614 BABAABBAAABAABABAABAAABBAABBABBBBBBBBBABABBBBABAAABBBBBAABABBBBAAABBAAABAAAAAAAAAAAAAABBABBBAABAAAAAAABBBBABAAABABAABAABBBAAAABABAABBBAABBABBBAABABBABBAAAAAABBABBBBAAABBBABABABBAABBBAAABAABBBABBABBBBABBBBAAABAAAABBAABAABAABBAABABBAAAABAAABBAAAABBABBABBBAABABBBABAABABBBABABBBBAAAABABBABBBA...
result:
FAIL WTF you have a better plan???
Subtask #8:
score: 0
Wrong Answer
Test #156:
score: 0
Wrong Answer
time: 893ms
memory: 13944kb
input:
80000 7878 777864027 -240722331 387404961 -663519829 -216544675 -615470669 389523326 -655149376 147392262 -473912099 -138402122 -464043161 559358763 -559101596 -823274287 110669805 -604050872 544371755 -438475893 567469656 820006475 817713642 888317607 -538471506 971148759 -445976429 128957549 -1023...
output:
3920724211 BABAAABABAAABAABABBABBBABABBBBBABAABAAAAAAABBAAAABBAAABBABABBBBABBBABABBAABBBAABBAAABBABBABABBBABBBBBABABAAAAAABAAAAABABBBBBBBAAAAABBBAAAABBAABABBABBBABABAABBABBABBABBABABABAABABABBBBAAABAABBAAAAAAAAAAAAAAAAABBBABAABAAABABBAABAABABABBABABABABBAAAABBABBABBBABAAABBBBBAAABBABAAAAABBABABAABAB...
result:
wrong answer read 3920724211 but the jury's answer is 3874967607
Subtask #9:
score: 0
Wrong Answer
Test #178:
score: 0
Wrong Answer
time: 1219ms
memory: 13868kb
input:
100000 10047 -5502 -308 7976 6352 -3142 -4377 528 1970 944 2448 8449 -4615 2083 4754 4525 -679 9798 -441 3115 5770 9575 6992 90 6051 -5122 70 -7052 2254 8847 2273 9231 9556 -8342 7092 -8287 -5179 -7231 -5016 4408 -4634 -1591 -6752 2148 2256 -9048 7607 553 -2994 -3081 -1207 3352 -578 8193 9903 7113 -...
output:
39002 BBABBAABABBABBBABBABBABAAAAABABBABABAABAAABAABBAABABBBBBAAAAABAAABBBABBBBABBBABABABABBBBAABABAAAABABABBABAAABAABABBBBAABAAAABBBBBABBAAABAABBBABABABBABAAABAAAABBAAAABAAABBBBAAABAAABABBBBBAABABBBABABBABBBABBAAAAAABBAAAAABAAAABBABBAABAABAAAAAAAAABBABBBABAAAABAABBBBABBBABAAAAABABAABABABAAAABBAAAAB...
result:
FAIL WTF you have a better plan???
Subtask #10:
score: 0
Wrong Answer
Test #198:
score: 0
Wrong Answer
time: 1150ms
memory: 13800kb
input:
100000 10184 897364269 894652505 421467601 -125369057 974459026 -179714212 582271101 448643533 643614224 628078404 484256779 -635646600 -559936755 337166672 300228846 50900132 -792820304 -300878123 -67707471 -746291314 157318792 -311384832 -239695088 218211183 -159892602 67981542 252575782 580382287...
output:
3372235692 ABAABABBBBBABBBAABBAAAABBAABABBBABABBBBABAAAAABAAABBABBABBBABBAAABBBBBBBBAABBAABABBAABBABABAABABAAAAAAAABABAABBBBBBBBAAABABABABBAAABABBAABBBBBBBAAAABABABBAAABAAAABBAAABBAABBAABABAABBAABABABBBAAAABAABABBBABBABBABBBBBAAABBABBBBAAABABBBABABBBAAABAAAABAABBABBBBBAAAAAAABABAABABABBAAABBBABABBAB...
result:
FAIL WTF you have a better plan???