QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#823426#434. 密码Kevin53070 579ms47736kbC++233.3kb2024-12-21 00:08:112024-12-21 00:08:11

Judging History

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

  • [2024-12-21 00:08:11]
  • 评测
  • 测评结果:0
  • 用时:579ms
  • 内存:47736kb
  • [2024-12-21 00:08:11]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define i128 __int128_t
void die(string S){puts(S.c_str());exit(0);}
using range=pair<i128,i128>;
i128 p;
struct equation
{
	i128 a,c,err;
	equation(){}
	equation(i128 _a,i128 _c,i128 _err):a(_a),c(_c),err(_err){}
	bool operator <(equation b){return a<b.a;}
	equation operator +(equation b){return equation((a+b.a)%p,(c+b.c)%p,err+b.err);}
	equation operator -(equation b){return equation((a+p-b.a)%p,(c+p-b.c)%p,err+b.err);}
};
inline bool check(vector<equation> ve)
{
	for(auto E:ve) if(E.a!=1) return 0;
	return 1;
}
inline int sp(range R)
{
	return R.first>R.second;
}
inline range merge(range a,range b)
{
	if(!a.first&&a.second==p-1) return b;
	if(!b.first&&b.second==p-1) return a;
	if(sp(a)&&!sp(b)) swap(a,b);
	if(sp(a)&&sp(b)) return range(max(a.first,b.first),min(a.second,b.second));
	if(!sp(a)&&!sp(b)) return range(max(a.first,b.first),min(a.second,b.second));
	if(a.second>=b.first)
		return range(max(b.first,a.first),a.second);
	return range(a.first,min(a.second,b.second));
}
vector<equation> evolve(vector<equation> ve)
{
	const int limit=50000;
	srt(ve);
	vector<equation> res;
	int p=-1;
	for(int i=0;i<sz(ve);i++)
	{
		while(p+1<sz(ve)&&ve[p+1].a<ve[i].a) p++;
		if(~p) res.pb(ve[i]-ve[p]);
	}
	for(auto E:ve) res.pb(E);
	srt(res);
	while(sz(res)>limit) res.pop_back();
	return res;
}
mt19937_64 rng(20210448);
void solve()
{
	vector<equation> ve;
	int n;
	cin>>n;
	ll _p;
	cin>>_p;
	p=_p;
	ll err;
	cin>>err;
	err=(err+1)/2;
	for(int i=0;i<n;i++)
	{
		ll a,b;
		cin>>a>>b;
		ve.pb(a,b,err);
	}
	vector<equation> history=ve;
	int round=0;
	while(!check(ve))
	{
		round++;
		ve=evolve(ve);
		for(auto E:ve) history.pb(E);
	}
	range R(0,p-1);
	for(auto E:ve) if(E.a==1) if(E.err*4<p)
	{
		range nR((E.c-E.err+p)%p,(E.c+E.err)%p);
		R=merge(R,nR);
	}
	for(int i=0;i<10;i++)
	{
		for(auto E:history)
		{
			i128 Lb=E.a*R.first;
			i128 Rb=E.a*(R.second<R.first?(R.second+p):R.second);
			if(Lb/p==Rb/p)
			{
				i128 dest=(Lb/p*p)+E.c;
				i128 Err=E.err;
				if(dest-Err>Rb) dest-=p;
				Lb=max(Lb,dest-Err);
				Rb=min(Rb,dest+Err);
				Lb=(Lb+E.a-1)/E.a;
				Rb=Rb/E.a;
				if(Lb>=p) Lb-=p;
				if(Rb>=p) Rb-=p;
				R=range(Lb,Rb);
			}
			else if(Lb/p+1==Rb/p)
			{
				i128 dest=(Lb/p*p)+E.c;
				i128 Err=E.err;
				if(dest+Err<Lb||dest+p-Err>Rb)
				{
					if(dest+Err<Lb) dest+=p;
					Lb=max(Lb,dest-Err);
					Rb=min(Rb,dest+Err);
					Lb=(Lb+E.a-1)/E.a;
					Rb=Rb/E.a;
					if(Lb>=p) Lb-=p;
					if(Rb>=p) Rb-=p;
					R=range(Lb,Rb);
				}
			}
		}
	}
	cout<<(ll)(R.first)<<" "<<(ll)(R.second)<<'\n';
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
		solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 0
Wrong Answer
time: 571ms
memory: 45824kb

input:

5
50 957125670377996927 1000000
585945225866084424 54589429123661916
573947126284093449 777559102750892238
153166610639441991 900505234633730119
829276546475860347 938947033720938303
667383545481941162 128214790654861522
642730062581689305 607900221293886873
386770285184824777 896008952335357488
399...

output:

557534539406344445 557534539406344445
48614680453513616 48614680453513616
171635259452156428 171635259452156428
510374952494623520 510374952494623520
577639061489488455 577639061489488455

result:

wrong answer 1st lines differ - expected: '557534539406344445', found: '557534539406344445 557534539406344445'

Test #2:

score: 0
Wrong Answer
time: 576ms
memory: 44980kb

input:

5
50 985780537212717349 100000000
930098920826707192 859185097554991862
114822564798967594 461663135509764494
290070133363935573 237203042621528977
876169993923548070 273892762234612214
946247278327197064 419030027202401205
613487802603166556 236215096880543712
249116322858554956 901707011293379960
...

output:

728806913399199677 728806913399199677
304868452402743224 304868452402743224
697338918497266871 697338918497266871
845921715720531367 845921715720531367
470978095570778021 470978095570778021

result:

wrong answer 1st lines differ - expected: '728806913399199677', found: '728806913399199677 728806913399199677'

Test #3:

score: 0
Wrong Answer
time: 555ms
memory: 43972kb

input:

5
50 912737338345705547 100000000000
560012542306640281 862559101259689768
518735103494826790 725717349992961571
733957671413353056 169708736886932691
847743526385447667 828696564841332397
107464092562234365 59619590616607389
12132877913647855 720538986960211892
612839049922974832 392264373061240257...

output:

667097255749051439 667097255749051439
24610618949224203 24610618949224203
416899801207925772 416899801207925772
297738252979447312 297738252979447312
23941143985346380 23941143985346380

result:

wrong answer 1st lines differ - expected: '667097255749051439', found: '667097255749051439 667097255749051439'

Test #4:

score: 0
Wrong Answer
time: 579ms
memory: 44152kb

input:

5
50 923097614961380909 1000000000000
97787754875250907 894771248217970266
776694885545580577 777083965073479575
75664239830708863 608716256879701985
237252054800496293 227374993084820963
863032115948152221 365706449805636266
24225822787011794 79303911682790301
773238132021550432 520965679721963390
...

output:

393439798021650097 393439798021650097
806593912421988792 806593912421988792
494092519607999744 494092519607999744
760635090566656810 760635090566656810
345872402107725664 345872402107725664

result:

wrong answer 1st lines differ - expected: '393439798021650097', found: '393439798021650097 393439798021650097'

Test #5:

score: 0
Wrong Answer
time: 337ms
memory: 46244kb

input:

5
2000 9342566358299507 93425663582995
6219101435016694 607891369107000
2117136321762304 2881084573543566
5176682988483854 9306200956208720
8253904804096661 3103523256778684
781386676390747 6601635146687045
6181577982870712 4562900022641750
771036361995174 8802607411541107
8287347227209040 478889400...

output:

8024221318129423 8024221317540052
2912294945034052 2912294941367486
923582019113741 923582017648788
5148136830870268 5148136533671116
5126098831248071 5126098828148685

result:

wrong answer 1st lines differ - expected: '8024221318134640', found: '8024221318129423 8024221317540052'

Test #6:

score: 0
Wrong Answer
time: 322ms
memory: 47736kb

input:

5
2000 9076941054068597 90769410540685
4164033048333799 6936964960910632
3199151620643150 6169865631753216
3651033776359505 2974612359357727
2437435894180490 7336869581147738
5545756515709013 7225793088900941
316850256662501 598866992420596
1931439899610976 2903969210506357
8802893275621192 51018944...

output:

1049242800759464 1049242800759455
8098010759854526 8098010671855915
6576281651243423 6576281648898891
8788103652940885 197444543566904
3573052280617493 3573052279768604

result:

wrong answer 1st lines differ - expected: '1049242800759464', found: '1049242800759464 1049242800759455'

Test #7:

score: 0
Wrong Answer
time: 398ms
memory: 44696kb

input:

5
50 986015706540181189 9860157065401811
472447084034094466 701096881178679368
789872459992477277 285017390663914121
139210847563896009 338277635649123845
434174656592580245 368068516438243771
537010852985895475 932180742287574181
420177119220393796 66137395305182219
278267742669272495 2098294852103...

output:

0 986015706540181188
0 908053926622227372
0 963711041952246486
0 986536584005342112
0 982155629982330210

result:

wrong answer 1st lines differ - expected: '247849421175747134', found: '0 986015706540181188'

Test #8:

score: 0
Wrong Answer
time: 421ms
memory: 45840kb

input:

5
50 937539041569299811 9375390415692998
243699599186989388 703817656494514633
490867383683796688 57336497141264681
700995121811059804 884266519548391255
881486531050497524 858417683373541541
483378074519689731 77311461506286120
163799445567955662 630863894729944525
440743631644571023 63661909944717...

output:

0 937539041569299810
0 919602186277915416
0 912539107279244398
0 960721608282788968
0 995085665182519480

result:

wrong answer 1st lines differ - expected: '480527239412739446', found: '0 937539041569299810'

Test #9:

score: 0
Wrong Answer
time: 415ms
memory: 45136kb

input:

5
50 956768533438862867 9567685334388628
159562951002452715 368735031805266874
168203674133135151 519955057721789995
47311303546279427 578468091719224380
488003044752475047 477936813372989614
937035830526454154 585363966735703129
36829830576452586 103584638478504234
938044828907421065 95216503175921...

output:

0 956768533438862866
0 985859438678396058
0 908188882885545010
0 990748329000924258
0 901518253067988922

result:

wrong answer 1st lines differ - expected: '872783696595005529', found: '0 956768533438862866'

Test #10:

score: 0
Wrong Answer
time: 429ms
memory: 45932kb

input:

5
50 954878053655579819 9548780536555798
547909457155842874 765505419310330784
582173103744680117 218053461605844877
290855470787761778 22535982680457566
488260659830503816 201490530306797340
811716163899850400 660850073720225447
662289272267072258 744062472352240699
397407312047625799 2689240086486...

output:

0 954878053655579818
0 991650555211305862
0 925484978640946078
0 952910425484403498
0 966042849951417760

result:

wrong answer 1st lines differ - expected: '300091718525150102', found: '0 954878053655579818'