QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#328560 | #7881. Computational Complexity | ExplodingKonjac | WA | 58ms | 7760kb | C++20 | 5.8kb | 2024-02-15 21:11:38 | 2024-02-15 21:11:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define OPENIOBUF
namespace FastIO
{
class FastIOBase
{
protected:
#ifdef OPENIOBUF
static const int BUFSIZE=1<<16;
char buf[BUFSIZE+1];
int buf_p=0;
#endif
FILE *target;
FastIOBase(FILE *f): target(f){}
~FastIOBase()=default;
public:
#ifdef OPENIOBUF
virtual void flush()=0;
#endif
};
class FastOutput final: public FastIOBase
{
public:
FastOutput(FILE *f=stdout): FastIOBase(f) {}
#ifdef OPENIOBUF
~FastOutput() { flush(); }
void flush() { fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
void put(char x)
{
#ifdef OPENIOBUF
if(buf[buf_p++]=x,buf_p==BUFSIZE) flush();
#else
putc(x,target);
#endif
}
FastOutput &operator <<(char x)
{ return put(x),*this; }
FastOutput &operator <<(const char *s)
{ for(;*s;put(*(s++)));return *this; }
FastOutput &operator <<(const std::string &s)
{ return (*this)<<s.c_str(); }
template<typename T>
std::enable_if_t<std::is_integral<T>::value,FastOutput&> operator <<(T x)
{
if(x<0) return put('-'),(*this)<<(-x);
char stk[std::numeric_limits<T>::digits10+1],*top=stk;
do *(top++)=x%10+'0',x/=10; while(x);
while(top!=stk) put(*(--top));
return *this;
}
template<typename ...T>
void writesp(T &&...x)
{ std::initializer_list<int>{((*this)<<(x),put(' '),0)...}; }
template<typename ...T>
void writeln(T &&...x)
{ std::initializer_list<int>{((*this)<<(x),put('\n'),0)...}; }
template<typename Iter>
std::enable_if_t<std::is_base_of<
std::forward_iterator_tag,
typename std::iterator_traits<Iter>::iterator_category>
::value> writesp(Iter begin,Iter end)
{ while(begin!=end) (*this)<<*(begin++)<<' '; }
template<typename Iter>
std::enable_if_t<std::is_base_of<
std::forward_iterator_tag,
typename std::iterator_traits<Iter>::iterator_category>
::value> writeln(Iter begin,Iter end)
{ while(begin!=end) (*this)<<*(begin++)<<'\n'; }
}qout;
class FastInput final: public FastIOBase
{
private:
bool __eof;
public:
FastInput(FILE *f=stdin): FastIOBase(f),__eof(false)
#ifdef OPENIOBUF
{ buf_p=BUFSIZE; }
void flush() { buf[fread(buf,1,BUFSIZE,target)]=EOF,buf_p=0; }
bool eof()const { return buf[buf_p]==EOF; }
#else
{}
bool eof()const { return feof(target); }
#endif
char get()
{
if(__eof) return EOF;
#ifdef OPENIOBUF
if(buf_p==BUFSIZE) flush();
char ch=buf[buf_p++];
#else
char ch=getc(target);
#endif
return ~ch?ch:(__eof=true,EOF);
}
void unget(char c)
{
__eof=false;
#ifdef OPENIOBUF
buf[--buf_p]=c;
#else
ungetc(c,target);
#endif
}
explicit operator bool()const { return !__eof; }
FastInput &operator >>(char &x)
{ while(isspace(x=get()));return *this; }
template<typename T>
std::enable_if_t<std::is_integral<T>::value,FastInput&> operator >>(T &x)
{
char ch,sym=0;x=0;
while(isspace(ch=get()));
if(__eof) return *this;
if(ch=='-') sym=1,ch=get();
for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=get());
return unget(ch),sym?x=-x:x,*this;
}
FastInput &operator >>(char *s)
{
while(isspace(*s=get()));
if(__eof) return *this;
for(;!isspace(*s) && !__eof;*(++s)=get());
return unget(*s),*s='\0',*this;
}
FastInput &operator >>(std::string &s)
{
char str_buf[(1<<8)+1]={0},*p=str_buf;
char *const buf_end=str_buf+(1<<8);
while(isspace(*p=get()));
if(__eof) return *this;
for(s.clear(),p++;;p=str_buf)
{
for(;p!=buf_end && !isspace(*p=get()) && !__eof;p++);
if(p!=buf_end) break;
s.append(str_buf);
}
unget(*p),*p='\0',s.append(str_buf);
return *this;
}
template<typename ...T>
void read(T &&...x)
{ std::initializer_list<int>{((*this)>>(x),0)...}; }
template<typename Iter>
std::enable_if_t<std::is_base_of<
std::forward_iterator_tag,
typename std::iterator_traits<Iter>::iterator_category>
::value> read(Iter begin,Iter end)
{ while(begin!=end) (*this)>>*(begin++); }
}qin;
} // namespace FastIO
using FastIO::qin,FastIO::qout;
using LL=long long;
using LD=long double;
using UI=unsigned int;
using ULL=unsigned long long;
#ifndef DADALZY
#define FILEIO(file) freopen(file".in","r",stdin),freopen(file".out","w",stdout)
#define LOG(...) [](auto...){}(__VA_ARGS__)
#else
#define FILEIO(file)
#define LOG(...) fprintf(stderr,__VA_ARGS__)
#endif
constexpr LL MAXN=1e15;
LL T,MOD,f[20],g[20];
vector<tuple<LL,LL,LL>> d;
int main()
{
qin>>f[0]>>g[0]>>T>>MOD;
d.emplace_back(0,f[0],g[0]);
for(int i=1;i<=13;i++)
{
f[i]=max((LL)i,g[i/2]+g[i/3]+g[i/5]+g[i/7]);
g[i]=max((LL)i,f[i/2]+f[i/3]+f[i/4]+f[i/5]);
d.emplace_back(i,0,0);
}
for(int i=1;i<=13;i++)
{
if(gcd(i,2*3*5*7)!=1) continue;
for(LL x1=i;x1<=MAXN;x1*=2)
for(LL x2=x1;x2<=MAXN;x2*=3)
for(LL x3=x2;x3<=MAXN;x3*=5)
for(LL x4=x3;x4<=MAXN;x4*=7)
d.emplace_back(x4,0,0);
}
sort(d.begin(),d.end());
d.erase(unique(d.begin(),d.end()),d.end());
auto getdf=[&](LL x) {
auto it=lower_bound(d.begin(),d.end(),tuple(x,0,0));
if(get<0>(*it)==x)
return get<1>(*it);
return 0ll;
};
auto getdg=[&](LL x) {
auto it=lower_bound(d.begin(),d.end(),tuple(x,0,0));
if(get<0>(*it)==x)
return get<2>(*it);
return 0ll;
};
for(auto &[i,df,dg]: d)
{
if(!i) continue;
if(i<=13) df=(f[i]-f[i-1])%MOD,dg=(g[i]-g[i-1])%MOD;
else
{
df= (i%2==0?getdg(i/2):0)
+(i%3==0?getdg(i/3):0)
+(i%5==0?getdg(i/5):0)
+(i%7==0?getdg(i/7):0);
dg= (i%2==0?getdf(i/2):0)
+(i%3==0?getdf(i/3):0)
+(i%4==0?getdf(i/4):0)
+(i%5==0?getdf(i/5):0);
df%=MOD,dg%=MOD;
}
}
LL curf=0,curg=0;
for(auto &[i,df,dg]: d)
{
curf=df=(df+curf)%MOD;
curg=dg=(dg+curg)%MOD;
}
while(T--)
{
LL n;
qin>>n;
auto it=lower_bound(d.begin(),d.end(),tuple(n+1,0,0))-1;
qout<<get<1>(*it)<<' '<<get<2>(*it)<<'\n';
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 48ms
memory: 7760kb
input:
1958 920 10 100000000000 0 1 2 3 10 100 200 1000 19580920 20232023
output:
1958 920 3680 7832 10592 9554 17504 11276 50294 64826 784112 893714 1894550 1905470 12057866 12979424 71481494756 48626708512 28127864908 7251681354
result:
ok 20 numbers
Test #2:
score: 0
Accepted
time: 43ms
memory: 6956kb
input:
0 0 10 100000000000 0 1 2 3 4 10 20 30 40 100
output:
0 0 1 1 2 2 3 3 4 4 11 12 25 26 41 41 55 58 162 172
result:
ok 20 numbers
Test #3:
score: 0
Accepted
time: 45ms
memory: 6268kb
input:
2023 2023 10 2023 0 1 2 3 4 5 6 7 8 9
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 20 numbers
Test #4:
score: 0
Accepted
time: 48ms
memory: 6252kb
input:
36092 30559 2149 729566623185 909730017626 961811467628 978809456383 494310140318 760462959632 726343527430 220697276132 366336227300 456813204361 569783542145 13854148170 51526515764 564416233246 876430686824 862897449267 956440673661 512777546436 728860125927 799238602356 978766770799 47962348351 ...
output:
192287632545 510282654057 513694515018 658644741565 90751152870 6088748556 138070013247 301112114677 224113421002 105290451187 630454127249 196841848259 546918129568 526274849982 226761501362 157889210040 135623074930 620463814922 78467045157 602244472172 51639549042 411354142414 329188915935 306494...
result:
ok 4298 numbers
Test #5:
score: 0
Accepted
time: 46ms
memory: 6216kb
input:
46012 72474 6895 931299293479 635558333906 151352929427 186830308154 201652909474 130684521091 862625793178 335372663856 565394770762 609752364488 636658378167 568072145317 23602174799 74849827839 567735061723 964475612065 721588322843 526921882143 141483206690 794896616456 923141155683 443983986019...
output:
737640936783 269480550026 785950579990 586907405473 274405996613 356240054012 164145774405 803378519477 613956922400 426121843045 509646717167 788278629379 95131481441 672600899832 720839818877 52329269906 131977527669 257593035330 737640936783 269480550026 202443098753 171133839273 188615102144 605...
result:
ok 13790 numbers
Test #6:
score: -100
Wrong Answer
time: 58ms
memory: 6352kb
input:
4625 65696 87448 104757899185 324541097749 340894391228 353710640194 913290645927 500906082550 994613091630 486893604015 755863379632 795242109754 670982629049 89739557323 995677833835 622128974870 291590021762 74643709454 491030939322 504220665415 590951839890 749414110824 908656060298 831415689095...
output:
98303795767 103142174372 65443117278 73960832858 98210843493 77767478433 103310305130 64404731905 49497274980 77784699551 6023629698 98019249623 20876999933 74613973523 90026940744 16420118093 4144294227 59372787549 104296937781 47484456492 26305574968 86459688252 19092009846 73496634219 87546745649...
result:
wrong answer 1st numbers differ - expected: '24017028596', found: '98303795767'