QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#75602 | #4917. 中奖率 | 4182_543_731 | 0 | 1744ms | 4332kb | C++20 | 3.2kb | 2023-02-05 21:32:19 | 2023-02-05 21:32:22 |
Judging History
answer
#pragma GCC optimize(3)
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
//simple integer
#define ll long long
ll bs=1e18;
struct integer{
vector<ll> v;
explicit operator bool()const{return !v.empty();}
void add(ll a)
{
ll rs=a;
for(int i=0;rs;i++)
{
if(i>=v.size())v.push_back(0);
rs+=v[i];
v[i]=rs%bs;
rs/=bs;
}
}
void mul(ll a)
{
__int128 rs=0;
for(int i=0;i<v.size()||rs;i++)
{
if(i>=v.size())v.push_back(0);
rs+=(__int128)a*v[i];
v[i]=rs%bs;
rs/=bs;
}
}
void div(ll a)
{
int sz=v.size();
ll rs=0;
for(int i=sz-1;i>=0;i--)
{
__int128 ri=(__int128)bs*rs+v[i];
v[i]=ri/a;rs=ri%a;
}
while(v.size()&&v.back()==0)v.pop_back();
}
ll mod(ll a)
{
int sz=v.size();
ll rs=0;
for(int i=sz-1;i>=0;i--)
{
__int128 ri=(__int128)bs*rs+v[i];
rs=ri%a;
}
return rs;
}
};
#define N 105000
char s[N];
integer input()
{
integer si;
scanf("%s",s+1);
ll s1=1,s2=0;
int le=1;
while(s[le+1])le++;
while(le)
{
s2+=s1*(s[le]-'0');s1*=10;
if(s1==bs)si.v.push_back(s2),s1=1,s2=0;
le--;
}
if(s2)si.v.push_back(s2);
return si;
}
void output(integer s)
{
if(!s){printf("0\n");return;}
printf("%lld",s.v.back());
for(int i=(int)s.v.size()-2;i>=0;i--)printf("%018lld",s.v[i]);
printf("\n");
}
int n,q,a,su[N],fg;
ll la[N];
ll calc(ll a,ll b)
{
ll si=0;
//sum la*s/lx/n-i/n
for(int i=1;i<=n;i++)if(la[i]>0)
{
__int128 ri=(__int128)la[i]*a+b*n-i*b;
si+=ri/n/b;
}
return si;
}
void query1(integer s)
{
if(!fg)
{
int ci=0;
for(int i=1;i<=n;i++)if(la[i]==0)ci++;
int ri=s.mod(ci);
s.div(ci);s.mul(n);
for(int i=1;i<=n;i++)if(la[i]==0)
{
ri--;
if(!ri)s.add(i);
}
output(s);
return;
}
ll s1=0;
for(int i=1;i<=n;i++)if(la[i]>0)s1+=la[i];
ll re=s.mod(s1);s.div(s1);
if(s)s.add(-1),re+=s1;
ll lb=0,rb=2ll*n*n*n,fr=1ll*n*n,as=0;
while(lb<=rb)
{
ll mid=(lb+rb)>>1;
if(calc(mid,fr)<re)as=mid,lb=mid+1;
else rb=mid-1;
}
re-=calc(as,fr);
vector<pair<ll,int> > tp;
for(int i=1;i<=n;i++)if(la[i]>0)
{
__int128 ri=(__int128)la[i]*as+fr*n-i*fr;
if(ri/n/fr!=(ri+la[i])/n/fr)tp.push_back(make_pair(la[i],i));
}
sort(tp.begin(),tp.end());
int sx=tp[re-1].second;
ll ry=(__int128)(as+1)*la[sx]/fr;
s.mul(la[sx]);s.mul(n);s.add(ry);
output(s);
}
void query2(integer s)
{
int id=s.mod(n);
if(!id)id=n;
if(la[id]<0||(la[id]==0&&fg)){printf("inf\n");return;}
if(la[id]==0)
{
s.div(n);
int ci=0,c2=0;
for(int i=1;i<=n;i++)if(la[i]==0)ci++,c2+=id<n&&i<=id;
s.mul(ci);s.add(c2);
output(s);
return;
}
ll lx=la[id],rs=lx*n,ri=s.mod(rs);
s.div(rs);
if(s)s.add(-1),ri+=rs;
ll s1=0;
for(int i=1;i<=n;i++)if(la[i]>0)s1+=la[i];
s.mul(s1);
//sum la*s/lx/n-i/n
for(int i=1;i<=n;i++)if(la[i]>0)
{
__int128 r1=(__int128)la[i]*ri-i*lx-(la[i]>lx)+n*lx;
s.add(r1/n/lx);
}
output(s);
}
int main()
{
scanf("%d%d%s",&n,&q,s+1);
for(int i=1;i<=n;i++)su[i]=su[i-1]+s[i]-'0',la[i]=1ll*su[i]*n-1ll*su[n]*i;
for(int i=1;i<n;i++)if(la[i]>0)fg=1;
while(q--)
{
scanf("%d",&a);integer b=input();
if(a==1)query1(b);else query2(b);
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 12ms
memory: 4264kb
input:
93594 19 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
858593754828725132145234462121942193025054301678275601001678706334737220068846345177656532185917892637205093166941016596643007666817600635533391347328492307337615836505532468318313687612500169078197827941413629289826494947257522181438115720197272190384339981534693840498841363776001396278110552090217...
result:
wrong answer 1st words differ - expected: '803592238894397000180010742478...2448338547538237511748357029202', found: '858593754828725132145234462121...1541150590193255318049359449933'
Subtask #2:
score: 0
Wrong Answer
Test #6:
score: 9
Accepted
time: 2ms
memory: 3044kb
input:
10 19 0000000000 2 241 1 405 1 927 1 669 1 734 1 349 2 493 1 828 1 385 1 855 2 761 1 63 1 288 1 754 2 91 1 863 2 805 2 1000 1 1000
output:
241 405 927 669 734 349 493 828 385 855 761 63 288 754 91 863 805 1000 1000
result:
ok 19 tokens
Test #7:
score: -9
Wrong Answer
time: 2ms
memory: 3196kb
input:
10 20 1111111111 2 112 2 917 1 364 1 898 1 37 2 456 2 839 1 414 1 13 1 858 2 49 2 653 2 502 1 562 1 138 2 559 2 778 2 494 2 1000 1 1000
output:
251 592 324 1397 57 343 420 819 16 573 25 979 1127 998 93 280 438 556 inf 1999
result:
wrong answer 1st words differ - expected: '112', found: '251'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #26:
score: 13
Accepted
time: 10ms
memory: 4308kb
input:
91666 20 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
515706124162066910404299759270263525075572767596736003465355923316260588149010617187359188941516324390245173109156994742981144311903350592651694874773059936377465166504183446390352558958540404515986128670780159685531688747924073414308447680356209302719213735419339034163216206854876449919662582900737...
result:
ok 20 tokens
Test #27:
score: -13
Wrong Answer
time: 157ms
memory: 4288kb
input:
91047 20 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
677769831199645492521390020590692332429201263944235633972590576080546681679552954312908664420406031587155486166070477700686248722341514730746663105321710980016559314318527133224879940874615128024066110699285918293756754216298233013143167232357788785460182114455137052943972234672521647205571216875059...
result:
wrong answer 1st words differ - expected: '748490273573792980373170496345...1636342578936255492260687176968', found: '677769831199645492521390020590...4542820663595074071055701119034'
Subtask #5:
score: 0
Wrong Answer
Test #36:
score: 0
Wrong Answer
time: 1744ms
memory: 4332kb
input:
98506 19 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
809524063778643777014164460069247825197075915436567206660387670268498748291693063178997071069144581251856641736952047602502711509281187485307221825461279538885373352010966049458501239425001013979898667874247961135746514502006616328299223601147083652552180419043842691179285613607830964462596815382674...
result:
wrong answer 1st words differ - expected: '129925218195110981928395603118...4444988083658465926564772872533', found: '809524063778643777014164460069...4665068477582643958571199614047'
Subtask #6:
score: 0
Skipped
Dependency #2:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
0%