QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#328559#7881. Computational ComplexityExplodingKonjacWA 41ms7272kbC++205.8kb2024-02-15 21:10:512024-02-15 21:10:51

Judging History

你现在查看的是最新测评结果

  • [2024-02-15 21:10:51]
  • 评测
  • 测评结果:WA
  • 用时:41ms
  • 内存:7272kb
  • [2024-02-15 21:10:51]
  • 提交

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=[&](int 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=[&](int 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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 40ms
memory: 7004kb

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: 36ms
memory: 6328kb

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: 39ms
memory: 7272kb

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: -100
Wrong Answer
time: 41ms
memory: 6932kb

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:

232626274055 462398338298
29587069229 389741314810
238276237200 642133207216
540388510197 484089648812
419433771686 111012706085
607140314866 459978197627
433867221338 425868183096
225864883307 250694292399
689859278533 655297710524
418010163005 414360740239
100070739832 278586016742
370085872089 51...

result:

wrong answer 1st numbers differ - expected: '192287632545', found: '232626274055'