QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#311728 | #6106. Making Number | linlexiao | WA | 86ms | 25640kb | C++20 | 4.6kb | 2024-01-22 18:00:12 | 2024-01-22 18:00:13 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
inline int read(){int f=1,x=0;char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}while(isdigit(c)){x=x*10+c-'0';c=getchar();}return x*f;}
inline ll readll(){ll f=1,x=0;char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}while(isdigit(c)){x=x*10+c-'0';c=getchar();}return x*f;}
#define all(x) x.begin(),x.end()
const int N = 1e5+5;
int cnt[10];
char X[N],Y[N];
int n;
struct Node{
int s[10];
int minv;
Node(){memset(s,0,sizeof(s));minv=1e9;}
}t[N*4];
Node operator+(const Node& l,const Node& r){
Node ret;
for(int i=0;i<10;i++)ret.s[i]=l.s[i]+r.s[i];
ret.minv=min(l.minv,r.minv);
return ret;
}
Node s[N];
void build(int o,int l,int r){
if(l==r){
if(1<=l&&l<=n)t[o].s[Y[l]]=1;
if(l<n)t[o].minv=Y[l+1];
else t[o].minv=1e9;
return;
}
int lch=o<<1,rch=o<<1|1,mid=(l+r)>>1;
build(lch,l,mid),build(rch,mid+1,r);
t[o]=t[lch]+t[rch];
}
void modify(int o,int l,int r,int qi){
if(l==r){
memset(t[o].s,0,sizeof(t[o].s));
t[o].s[Y[l]]++;
if(l<n)t[o].minv=Y[l+1];
else t[o].minv=1e9;
return;
}
int lch=o<<1,rch=o<<1|1,mid=(l+r)>>1;
if(qi<=mid)modify(lch,l,mid,qi);
else modify(rch,mid+1,r,qi);
t[o]=t[lch]+t[rch];
}
Node qsum(int o,int l,int r,int ql,int qr){
if(ql>qr)return Node();
if(ql<=l&&r<=qr)return t[o];
int lch=o<<1,rch=o<<1|1;
int mid=(l+r)>>1;
if(qr<=mid)return qsum(lch,l,mid,ql,qr);
if(ql>mid)return qsum(rch,mid+1,r,ql,qr);
return qsum(lch,l,mid,ql,qr)+qsum(rch,mid+1,r,ql,qr);
}
int query(int o,int l,int r){
if(l==r)return l;
int lch=o<<1,rch=o<<1|1,mid=(l+r)>>1;
bool ok = 1;
for(int i=0;i<10;i++){
if(cnt[i]<t[lch].s[i]){ok=0;break;}
}
if(!ok)return query(lch,l,mid);
for(int i=0;i<10;i++)cnt[i]-=t[lch].s[i];
int ans = query(rch,mid+1,r);
for(int i=0;i<10;i++)cnt[i]+=t[lch].s[i];
return ans;
}
bool check(const Node& d,int minval){
for(int i=minval+1;i<10;i++)if(d.s[i])return 1;
return 0;
}
int min_left(int o,int l,int r,int qr,Node& d){
if(l>qr)return 0;
if(qr>=r){
auto dd = d+t[o];
if(!check(dd,dd.minv)){
d=dd;
return 0;
}
if(l==r)return r;
}
int lch=o<<1,rch=o<<1|1,mid=(l+r)>>1;
int pos = min_left(rch,mid+1,r,qr,d);
if(pos)return pos;
return min_left(lch,l,mid,qr,d);
}
Node getf1r(int r){
Node n2;
auto minus = qsum(1,1,n,1,r);
for(int i=0;i<10;i++)n2.s[i]=s[n].s[i]-minus.s[i];
return n2;
}
int main(){
scanf("%s%s",X+1,Y+1);
n=strlen(X+1);
for(int i=1;i<=n;i++)X[i]-='0',Y[i]-='0';
for(int i=1;i<=n;i++){
cnt[X[i]]++;
s[i]=s[i-1];
s[i].s[X[i]]++;
}
build(1,1,n);
int q=read();
while(q--){
if(q%10000==0)build(1,1,n);
int o=read();
if(o==1){
int i=read(),x=read();
Y[i]=x;
modify(1,1,n,i);
if(i)modify(1,1,n,i-1);
}
else{
int pos = read();
bool same = 1;
for(int i=0;i<10;i++){
if(t[1].s[i]!=cnt[i]){
same=0;break;
}
}
if(same){
printf("%d\n",(int)Y[pos]);
continue;
}
int p = query(1,1,n);
auto nd = getf1r(p-1);
int p2 = min_left(1,1,n,p-1,nd);
auto n2 = getf1r(p2);
if(!check(n2,Y[p2+1])){
puts("-1");
continue;
}
if(pos<=p2){
printf("%d\n",(int)Y[pos]);
continue;
}
if(pos==p2+1){
for(int i=Y[p2+1]+1;i<10;i++){
if(n2.s[i]){
printf("%d\n",i);
break;
}
}
continue;
}
for(int i=Y[p2+1]+1;i<10;i++){
if(n2.s[i]){
n2.s[i]--;break;
}
}
int L = p2+2;
for(int i=0;i<10;i++){
int R = L+n2.s[i]-1;
if(L<=pos&&pos<=R){
printf("%d\n",i);
}
L += n2.s[i];
}
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 25392kb
input:
3304 1615 6 2 3 2 4 1 1 3 2 2 1 2 4 2 1
output:
3 4 0 3
result:
ok 4 number(s): "3 4 0 3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 25412kb
input:
838046 780357 10 2 1 2 2 1 2 4 2 3 2 4 1 4 5 2 5 2 6 1 1 9 2 2
output:
8 0 3 4 6 8 -1
result:
ok 7 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 25312kb
input:
2950 9052 4 2 1 2 2 2 3 2 4
output:
9 0 5 2
result:
ok 4 number(s): "9 0 5 2"
Test #4:
score: 0
Accepted
time: 86ms
memory: 25580kb
input:
677626993975892499704039030543272430899275243910257911804799779050091046516452988178013531014268918811173939650642586439566406179191340032290242471164620397693718115937469230865639050202204033086180013798392250945514997389392089836361472892923108709052296874567465127993121832785182254870655135620662...
output:
7 9 3 6 0 4 7 1 1 4 1 5 4 5 2 1 3 8 3 8 4 9 5 8 1 5 6 1 3 9 4 7 2 2 4 1 2 0 1 8 3 7 0 8 5 9 9 4 9 4 4 4 7 1 5 6 3 0 3 7 4 6 2 4 9 6 4 8 2 0 4 4 2 0 6 4 8 4 9 9 9 0 4 6 8 1 9 6 5 8 3 1 5 4 8 8 7 7 4 0 0 6 2 0 3 9 8 6 8 2 9 2 7 6 1 4 3 8 9 6 4 8 3 5 4 7 5 7 4 1 7 5 3 9 0 9 8 9 1 5 6 8 9 8 5 5 0 1 8 0 ...
result:
ok 49975 numbers
Test #5:
score: 0
Accepted
time: 72ms
memory: 25604kb
input:
511480086753564282821528855178563929745572703769018450686519315364994143491916967272893579288334926852555836951575502077626800161580974941822438484334857675128558893510619871726746734393334541554012208506864881136634075294480149999489082362631943342210952658415428622030685123950393010171647050758706...
output:
6 2 8 5 5 4 6 0 4 4 7 6 0 7 4 5 2 2 4 3 9 5 3 5 9 7 3 4 4 7 6 6 1 8 8 9 5 3 4 8 8 5 2 1 1 9 9 4 6 6 3 5 0 3 5 9 5 1 6 4 2 3 0 0 2 4 2 0 1 0 4 4 6 0 7 7 2 4 6 8 3 4 8 7 8 7 8 3 2 1 6 0 5 7 6 0 1 7 4 8 3 3 0 6 8 2 7 0 8 4 5 3 5 5 5 2 2 6 8 1 2 0 4 7 6 9 5 1 7 5 4 8 7 5 7 9 6 7 2 4 4 1 8 3 6 6 7 4 9 1 ...
result:
ok 49929 numbers
Test #6:
score: 0
Accepted
time: 84ms
memory: 25576kb
input:
472330038062685403802290048373688812241446646131931548371358882106958120983785742309604463056365028053384497842197902484437459388258909692021136121000437587309020081655554248416237604736980589208691771671180049141616984590478595217573559381574160795133081222146011610538801003982869672106413196666521...
output:
1 0 7 0 7 5 8 3 3 2 4 7 0 4 1 9 1 4 7 0 4 2 6 0 5 7 2 2 7 6 3 9 4 5 9 1 0 1 6 9 4 3 2 3 9 9 1 2 6 7 1 3 0 3 9 0 3 3 8 7 2 0 5 9 5 4 1 5 3 0 2 7 7 9 2 4 2 9 9 2 8 8 7 2 1 4 0 0 9 8 7 0 9 1 4 2 4 1 0 8 2 8 5 3 5 6 3 9 5 3 3 2 2 1 7 1 5 3 1 4 5 9 2 9 7 8 2 5 7 3 6 8 6 0 5 9 8 6 0 5 0 9 9 4 4 7 5 2 9 0 ...
result:
ok 50042 numbers
Test #7:
score: 0
Accepted
time: 73ms
memory: 25464kb
input:
386233463881717072875581827146070520751747126770517661713166628789189627724980782503822688280432695205513144141020509128499902342551505341291338189246300115206785134828666443367135785829882467172883975489827563563779932862926264780289693656829908932995843695380306139371737193136677430867087011811629...
output:
3 4 1 9 4 5 6 9 2 7 5 6 6 3 1 3 4 1 1 8 9 8 4 9 2 6 5 8 6 2 6 5 2 0 9 2 6 2 5 1 0 7 4 0 0 8 6 3 2 1 1 8 7 0 8 2 9 7 4 7 8 0 4 4 4 1 6 2 3 5 2 5 7 4 7 5 2 8 5 6 7 9 8 3 4 6 6 5 4 6 6 2 6 3 9 8 8 9 1 1 8 0 3 5 8 1 9 2 8 8 3 7 6 8 3 3 7 1 8 7 6 4 4 3 5 1 9 7 0 8 7 4 7 5 2 1 3 3 9 4 0 1 4 7 9 8 2 8 2 1 ...
result:
ok 49992 numbers
Test #8:
score: 0
Accepted
time: 77ms
memory: 25632kb
input:
745583415671483224856063268315723013208093546585338940411563348183242984213440969816633586058807593886948284456364509705729509729228715032842535706716746469625245322861513742352222229050932105542759840801595902514973411977932610802947368055541931365403552209659301957818972982202503192705179196359265...
output:
2 6 5 5 6 3 5 3 8 4 8 8 2 9 8 7 4 2 9 3 7 4 5 7 6 3 3 7 3 3 8 8 1 1 6 9 3 7 6 1 6 0 7 2 5 9 6 9 8 7 5 2 4 2 2 3 5 1 1 0 4 6 5 9 4 4 3 3 4 8 9 7 3 3 6 6 2 5 9 4 8 8 9 6 5 6 6 1 8 9 6 6 4 8 1 6 3 9 5 3 0 4 6 0 3 2 5 4 0 1 1 9 1 3 3 3 7 6 3 8 3 4 2 3 9 1 3 5 9 3 6 4 7 6 1 2 3 9 3 7 0 4 3 0 1 8 9 3 4 9 ...
result:
ok 49998 numbers
Test #9:
score: 0
Accepted
time: 75ms
memory: 25604kb
input:
687148149898590835128734096020818522700529479354111091949312960135002085101685319911019178222572129521797945953853905713726059302432395983082137469982521105165791059980657901801789909933674074000321433370751326550034923277070556265051872985662112168660614913449190413055498618459115952038181012606241...
output:
8 9 1 3 3 5 6 1 9 6 8 7 8 4 4 1 0 8 7 4 5 3 1 9 6 1 7 1 3 5 0 9 2 9 8 9 1 9 3 6 5 7 5 0 4 8 2 7 4 5 0 5 8 4 1 4 4 0 2 2 2 8 6 8 2 4 8 7 4 8 1 4 4 9 9 0 8 2 2 9 6 7 8 8 2 7 3 5 6 0 0 8 1 6 3 3 8 9 9 7 7 8 5 0 1 9 8 0 3 7 8 3 6 9 3 1 6 8 8 6 8 6 4 2 7 1 4 4 7 8 8 5 7 5 0 2 6 6 9 5 6 4 9 9 0 8 1 0 1 7 ...
result:
ok 49960 numbers
Test #10:
score: 0
Accepted
time: 82ms
memory: 25604kb
input:
511410590003206748743026837297269617156860999163734519503176440751003346982052198127800474000547281930526632644516345712652806992189907653673339456162173013088973643589761306561810879584560558973989908184836364781078674144968906782339481360394956565722773781126049434152414561245822910375917863114385...
output:
6 5 8 4 6 7 3 3 7 5 4 7 3 4 9 7 5 7 5 9 6 7 1 1 0 4 6 6 6 2 1 1 1 1 1 4 3 0 6 6 1 3 1 8 5 6 9 4 1 3 1 3 3 1 2 6 7 4 5 8 9 1 9 5 4 0 6 2 0 8 5 3 3 6 5 2 4 0 9 3 3 7 7 1 5 3 0 0 2 1 4 7 5 3 3 7 4 9 0 0 9 7 1 3 0 3 3 9 6 7 3 6 6 5 7 1 4 1 6 8 3 5 1 1 6 5 8 7 7 8 6 0 6 9 3 3 7 3 5 4 1 6 3 3 5 9 9 3 8 6 ...
result:
ok 50026 numbers
Test #11:
score: 0
Accepted
time: 76ms
memory: 25536kb
input:
412360324827978957176583694828310104622570454802673606075377276215378423471812273240200693215211478171394399847108642814672419979452510744863417210894498320009435941598606905856781313771012596687811178858150589131279746416550676044440596239657711594345549954832445910296588861477458018692941905242921...
output:
1 8 5 2 3 9 2 8 3 8 4 3 6 5 4 1 3 1 3 5 5 8 9 2 6 1 6 4 0 6 6 3 5 6 3 4 8 3 9 0 4 0 2 4 7 5 4 3 3 6 9 9 3 2 6 9 4 9 8 7 5 4 7 7 1 0 3 2 7 7 3 8 7 4 8 3 9 9 1 1 3 6 3 4 3 6 4 5 5 7 2 2 4 6 3 3 7 3 0 8 7 9 6 8 8 3 5 0 5 9 4 3 1 2 5 4 2 7 1 8 9 8 3 5 1 0 9 4 2 4 2 3 3 1 3 4 8 4 6 3 6 9 8 0 1 1 9 5 5 3 ...
result:
ok 49948 numbers
Test #12:
score: 0
Accepted
time: 76ms
memory: 25600kb
input:
856329357016035505153679499429017618522016754810690745637585353807331320998717013354091215483446306780029058518021052461209557195048736635002613733400864914984195578672150918541302093698958464131643763263426069118339541672648022567592260494469158830001260168605992533833064759869674003545017260491009...
output:
6 8 7 0 4 5 2 3 8 9 4 3 9 1 9 5 6 7 3 4 6 6 6 8 1 8 7 5 3 2 4 0 5 5 4 0 7 1 7 6 2 0 8 7 1 0 7 9 6 3 6 7 0 1 5 1 5 4 9 6 9 7 5 3 9 9 0 0 1 1 1 6 0 0 1 6 2 6 9 5 5 6 8 9 2 4 9 8 4 4 3 1 8 7 5 6 4 3 6 3 5 8 1 6 8 2 2 7 5 6 1 6 8 0 9 8 8 2 2 6 9 8 6 6 5 0 8 2 8 9 1 7 9 8 8 6 6 4 7 7 8 6 0 3 4 0 8 9 5 5 ...
result:
ok 50026 numbers
Test #13:
score: 0
Accepted
time: 79ms
memory: 25496kb
input:
207978770069539728817271045945248746241818636280006621963858065263619645208863709951955581650441063780888002768150890864716529529107478452273845099423444295437542775021972720210956321827972662761649312268042113348860266380256320778223985862679633592673273717863417100156085087721855894555348405500719...
output:
0 2 8 1 3 4 5 2 7 1 3 4 7 4 2 8 7 8 8 6 1 3 2 5 4 1 2 8 3 1 9 7 6 1 1 1 6 2 9 9 1 2 5 8 6 0 3 9 3 5 3 5 1 5 9 9 1 7 9 6 1 0 3 8 7 5 3 1 6 2 5 7 6 0 6 6 4 1 5 8 9 9 2 3 3 0 5 5 4 6 8 9 4 6 4 2 6 5 1 6 2 9 5 7 8 1 3 3 7 4 1 6 4 9 7 8 2 9 7 4 7 1 4 7 7 9 1 1 8 6 5 2 3 7 6 7 5 9 1 5 1 4 6 8 0 7 1 6 5 2 ...
result:
ok 50025 numbers
Test #14:
score: 0
Accepted
time: 76ms
memory: 25496kb
input:
164428742658650397298339420552443455101568119017687712665088396853574942791024688455356045424416501995017237219123098822376166101955464501466812812649086495459262962860410367705834209150622335631443903792735958848302687895202370035731150731351456335899336987100067685293569877313567752878310940738755...
output:
1 8 6 9 4 2 1 1 4 5 2 7 5 5 3 5 9 0 8 1 3 2 5 3 8 1 5 8 5 1 8 6 4 8 2 3 5 8 0 2 1 6 1 4 6 2 8 1 8 9 8 7 1 0 0 2 5 1 8 7 7 4 8 5 2 5 8 3 8 6 7 7 5 8 0 2 3 3 7 7 0 1 6 1 0 4 6 6 8 7 8 6 2 9 6 0 2 1 5 1 4 0 6 2 8 9 4 9 8 1 9 8 3 0 4 5 0 9 8 3 1 8 1 6 8 0 8 5 8 8 1 9 5 0 1 0 3 4 2 2 9 5 3 7 5 6 2 2 0 6 ...
result:
ok 50022 numbers
Test #15:
score: 0
Accepted
time: 80ms
memory: 25524kb
input:
998767354558322906625620015167794944657818251826400836199407978416545069691547034108346073612303533094806958918805437473506719658260875212008010754739853345390768650837328322896341589343550573089739136161331978235561797773390415153085804136062697178719078131890066607436125156355189718122782466286459...
output:
8 7 1 8 6 9 3 0 3 8 4 4 7 4 8 6 5 6 3 6 8 9 2 0 3 6 6 5 1 5 9 0 4 2 4 4 9 8 7 3 5 4 5 6 7 5 2 5 3 9 2 3 8 0 1 9 8 2 2 7 5 6 9 4 1 7 2 3 5 8 7 6 5 1 8 7 9 6 5 6 8 3 0 2 3 8 1 6 9 0 0 2 2 6 5 5 2 9 4 5 2 6 3 0 4 3 6 5 1 9 6 1 6 2 0 9 2 0 0 0 2 1 7 1 9 4 6 4 5 3 5 7 3 7 0 6 9 0 0 9 6 3 3 6 0 8 1 7 5 0 ...
result:
ok 49925 numbers
Test #16:
score: 0
Accepted
time: 76ms
memory: 25512kb
input:
496117747349030859242712439552847857173335411600183925191605438390308987026311211708747951426974071035231015263358833473203227234913873963653616567985338093815470280976485981645438455282050097953301422963637710015063600088898465670743373005589682945970747704429911563933261846140395176443170301349475...
output:
8 7 8 7 3 9 0 9 9 6 6 6 6 9 4 4 8 7 9 0 4 3 9 2 0 4 0 5 7 0 0 2 2 0 4 7 9 3 7 5 9 4 1 7 5 0 5 8 2 2 3 1 1 5 4 8 2 9 9 9 3 3 5 9 2 2 3 8 0 2 7 9 0 7 6 2 0 5 7 6 5 4 5 7 9 1 0 5 7 9 0 5 8 1 7 4 8 8 6 2 5 3 2 9 9 8 6 5 3 1 6 6 9 9 2 4 6 0 7 7 2 9 5 0 1 7 1 3 7 9 2 1 4 8 6 1 6 1 3 5 3 5 4 3 6 3 0 7 6 8 ...
result:
ok 49966 numbers
Test #17:
score: 0
Accepted
time: 73ms
memory: 25640kb
input:
879077611568305029524273214759692546023681920619909666645816914982402484913116250093137152695049206643460741460271833570279670253121465212427814124175174303836095991951317860795539333476942195636187095271368531406226910990880535137299873821691406148014509516363900520071195534330828232780282826477512...
output:
4 2 2 0 5 4 0 1 4 5 7 2 2 5 2 3 1 7 9 0 6 0 3 0 4 4 0 6 7 5 8 2 3 3 9 6 3 6 0 5 2 1 8 1 0 9 1 7 0 9 8 4 8 2 8 0 0 9 5 1 7 4 5 4 8 9 3 1 9 0 0 2 0 7 6 8 6 0 6 1 2 9 1 1 7 1 4 7 7 6 8 9 8 6 6 2 3 8 9 4 0 4 8 8 5 6 5 8 0 8 5 2 4 4 0 1 1 1 4 3 1 4 1 6 2 0 7 7 3 1 6 7 9 5 9 2 1 4 5 8 2 8 9 8 0 4 4 6 1 5 ...
result:
ok 49930 numbers
Test #18:
score: 0
Accepted
time: 73ms
memory: 25516kb
input:
203968624374417872599305057960984030372982060448780195288250350584273341499079030196956080469617724888838406395743230124996577835874461904028816041291105143917991579964524439244822473009488603180812160846042219893300437496918585071513942690378687371239260250594909446238312463866438654013074218583158...
output:
4 4 2 1 9 2 8 7 7 9 0 0 9 0 3 6 0 0 0 3 2 0 6 4 6 4 8 7 8 3 4 6 4 3 3 9 7 5 2 8 2 0 9 3 7 8 1 9 1 8 6 2 5 1 4 2 3 8 7 9 5 5 1 8 8 4 8 5 5 9 3 1 4 8 1 5 1 1 5 3 5 4 8 0 3 3 7 3 3 6 2 3 1 4 3 1 9 4 2 5 2 2 4 6 4 6 0 4 4 9 2 2 9 2 9 8 3 8 3 6 4 8 1 1 3 4 5 9 6 0 2 1 4 1 9 4 9 4 0 4 5 9 6 5 0 0 6 4 2 7 ...
result:
ok 50003 numbers
Test #19:
score: -100
Wrong Answer
time: 81ms
memory: 25512kb
input:
664828096591123841572296486591075547872856344115703231722069827322096608384090019204366008637182716083677163674626630101166122412141233257614793889487901853834607207647628854345933911980118782654448753250508439833562347861706645574261195579084500718799334623432092033351838757658540625351640733190174...
output:
9 3 8 3 6 7 6 2 3 9 2 5 7 1 9 2 1 3 2 1 9 1 2 2 7 7 2 1 3 4 7 9 4 6 3 2 9 5 1 0 2 6 7 5 0 0 3 4 3 2 6 4 9 0 2 0 6 1 0 0 5 8 7 2 6 6 2 7 2 8 6 0 8 1 9 9 4 0 9 9 9 3 9 1 6 0 1 9 7 1 3 1 7 8 5 4 3 1 2 7 0 3 5 1 7 9 9 3 0 7 6 4 2 3 5 4 4 6 4 0 3 8 5 0 0 0 6 6 8 9 0 1 9 3 7 9 7 4 7 6 6 9 2 2 6 6 4 8 8 7 ...
result:
wrong answer 46609th numbers differ - expected: '6', found: '-1'