QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#212923#6824. Demonstrational Sequencesnameless_story#TL 1183ms237100kbC++232.0kb2023-10-13 22:58:552023-10-13 22:58:55

Judging History

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

  • [2023-10-13 22:58:55]
  • 评测
  • 测评结果:TL
  • 用时:1183ms
  • 内存:237100kb
  • [2023-10-13 22:58:55]
  • 提交

answer

#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ll;
template<class T1,class T2> bool cmax(T1 &x,const T2 &y) { if (x<y) { x=y; return 1; }return 0; }
#define all(x) (x).begin(),(x).end()
const ll N=1e7+2,M=1e4+5,NN=7e6+5,Q=1<<20|5;
bool ed[N];
ll c[NN+1];
mt19937 rnd(235);
vector<int> buc[Q];
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cout<<fixed<<setprecision(15);
	ll p,q,i,j;
	int T;
	cin>>p>>q>>T;
	p/=q;
	map<pair<ll,ll>,int> ans;
	for (i=0; i<N; i++) if (gcd(i,p)==1) ed[i]=1;
	p*=q;
	// assert(ed[2]);
	while (T--)
	{
		auto cal=[&]()
			{
				ll a,b,d,dmq;
				int tot=1e6,i,j;
				for (i=0; i<q; i++) buc[i].clear();
				cin>>a>>b;
				// a=2022; b=924;
				a%=p; b%=p;
				if (ans.count({a,b})) return ans[{a,b}];
				c[0]=a;
				for (i=1; i<=NN; i++) c[i]=(c[i-1]*c[i-1]+b)%p;
				// shuffle(c+5000,c+NN+1,rnd);
				// cerr<<c[0]<<' '<<c[3]<<' '<<q<<endl;
				vector<ll> occ;
				ll R=max<int>(q*5,100);
				for (i=0; i<=R; i++) occ.push_back(c[i]%q);
				sort(all(occ)); occ.resize(unique(all(occ))-occ.begin());
				for (ll x:occ) buc[x].clear();
				for (i=0; i<=R; i++) buc[c[i]%q].push_back(c[i]/q);
				// cerr<<occ.size()<<endl;
				for (ll x:occ)
				{
					auto &v=buc[x];
					// if (x==1) cerr<<v[0]<<' '<<v[1]<<endl;
					sort(all(v));
					// if (v.size()>1000)
					int m=unique(all(v))-v.begin();
					if (m!=v.size()&&ed[0]) return ans[{a,b}]=1;
					v.resize(m);
					// if (x==1) assert(count(all(v),0)&&count(all(v),2));
					// cerr<<x<<endl;
					// int m=v.size();
					for (i=0; i<m; i++)
					{
						// cerr<<i<<endl;
						for (j=i-1; j>=0; j--)
						{
							// if (x==1&&i==1&&j==0) cerr<<i<<' '<<j<<endl;
							if (v[i]-v[j]<N&&ed[v[i]-v[j]]) return ans[{a,b}]=1;
							// if (v[j]-v[i]<N&&ed[v[j]-v[i]]) return ans[{a,b}]=1;
							// if (v[i]+pq-v[j]<N&&ed[v[i]+pq-v[j]]) return ans[{a,b}]=1;
						}
						// tot-=min<int>(tot,i-1);
					}
				}
				return ans[{a,b}]=0;
			};
		cout<<cal();
	}
	cout<<endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 418ms
memory: 92580kb

input:

15 5 5
1 1
1 2
2 4
4 8
8 16

output:

11010

result:

ok "11010"

Test #2:

score: 0
Accepted
time: 1183ms
memory: 237100kb

input:

998244352 1048576 3
2022 924
12345678 1234567
23333333 6666666

output:

001

result:

ok "001"

Test #3:

score: 0
Accepted
time: 761ms
memory: 127500kb

input:

100237 100237 10
1244422970085542683 6256585832417115176
11178595626727644735 679276059713497324
5646838801370008540 6709514788466664568
9971158657914728691 8724448042786063799
9867649407902336110 2614925263502318093
1990105069810770727 8671216841234378816
7965667786524489724 6722337513023700570
246...

output:

1111111111

result:

ok "1111111111"

Test #4:

score: -100
Time Limit Exceeded

input:

1000000007 1 200
1244424352052424851 13102057264748565738
10964128241743967010 11238647915096906960
9602909082986968021 14247804011443894396
13231275623402659328 11122445945926639224
1819715673773979255 15011227386780949150
10389668459305004672 13595253579372877142
136927098471150438 141908708541553...

output:


result: