QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#31759#21643. 多测不给大样例问题zmwang70 394ms8092kbC++202.8kb2022-05-12 12:31:342022-05-12 12:31:37

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-12 12:31:37]
  • 评测
  • 测评结果:70
  • 用时:394ms
  • 内存:8092kb
  • [2022-05-12 12:31:34]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<sstream>
#include<cctype>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
#include<set>
#include<functional>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#define in(x) x=read()
#define qr read()
#define int ll
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
namespace fastIO
{
    #define BUF_SIZE 100000
    bool IOerror=0;
    inline char nc()
	{
        static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
        if (p1==pend){
            p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin);
            if (pend==p1){IOerror=1;return -1;}
        }
        return *p1++;
    }
    inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';}
    inline ll read()
	{
        bool sign=0; char ch=nc();ll x=0;
        for (;blank(ch);ch=nc());
        if (IOerror)return 0;
        if (ch=='-')sign=1,ch=nc();
        for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';
        if (sign)x=-x;
        return x;
    }
    #undef BUF_SIZE
};
using namespace fastIO;
int pos[100][100],vv[1000010],a[100],b[100],res[100],MX[100][100];
vector<pii>lis,V[100];
unordered_map<int,int>w;
inline int gcd(int x,int y){return y==0?x:gcd(y,x%y);}
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int T=qr,mx=0;
	for(int i=1;i<=T;i++)
	{
		in(a[i]),in(b[i]);
		mx=max(mx,b[i]);
		V[b[i]].push_back(mp(a[i],i));
		for(int j=1;j<=b[i];j++)
		{
			pos[i][j]=j*a[i]/b[i];
			MX[b[i]][j]=max(MX[b[i]][j],pos[i][j]);
		}
	}
	for(int k=1;k<=mx;k++)
	{
		if(!V[k].size())continue;
		// int n=1e12,k=59;
		for(int i=1;i<=k;i++)
		{
			// pos[i]=i*n/k;
			vv[i]=i/__gcd(i,k);
		}
		lis.clear();
		int sum=0;
		for(int i=k-1;i>=1;i--)
		{
			if(k%i==0)
			{
				for(auto id:V[k])res[id.se]+=pos[id.se][i];
				break;
			}
			int v=vv[i];
			w.clear();
			for(auto j:lis)
			{
				if(j.fi<=MX[k][i])w[j.fi]+=j.se;
				int nxt=j.fi*v/gcd(j.fi,v); 
				if(nxt<=MX[k][i])w[nxt]-=j.se;
			}
			sum+=lis.size();
			w[v]++;
			// cout<<pos[i]<<"~"<<pos[i-1]<<":\n";
			lis.clear();
			for(auto j:w)
			{
				// cout<<j.fi<<','<<j.se<<'\n';
				if(j.se)lis.push_back(mp(j.fi,j.se));
			}
			sum+=w.size();
			for(auto id:V[k])
			{
				for(auto j:lis)
				{
					res[id.se]+=(pos[id.se][i]/j.fi)*j.se-(pos[id.se][i-1]/j.fi)*j.se;
				}
			}
			sum+=lis.size();
			// cout<<i<<":"<<sum<<'\n';
		}
		// cout<<res<<'\n';
	}
	for(int i=1;i<=T;i++)cout<<res[i]<<'\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 4ms
memory: 3672kb

input:

10
5489 36
7152 51
6028 52
5449 51
4237 38
6459 24
4376 18
8918 4
9637 17
3835 29

output:

4172
4603
4244
3497
2756
4805
3080
5202
4188
1594

result:

ok 10 numbers

Test #2:

score: 10
Accepted
time: 1ms
memory: 3688kb

input:

10
5489 36
7152 51
6028 52
5449 51
4237 38
6459 24
4376 18
8918 4
9637 17
3835 29

output:

4172
4603
4244
3497
2756
4805
3080
5202
4188
1594

result:

ok 10 numbers

Test #3:

score: 10
Accepted
time: 7ms
memory: 3692kb

input:

10
548814 36
715190 51
602764 52
544884 51
423655 38
645895 24
437588 18
891774 4
963663 17
383442 29

output:

417037
459640
424323
350180
275682
480155
307555
520201
419692
160086

result:

ok 10 numbers

Test #4:

score: 10
Accepted
time: 7ms
memory: 3664kb

input:

10
548814 36
715190 51
602764 52
544884 51
423655 38
645895 24
437588 18
891774 4
963663 17
383442 29

output:

417037
459640
424323
350180
275682
480155
307555
520201
419692
160086

result:

ok 10 numbers

Test #5:

score: 0
Time Limit Exceeded

input:

40
108949032315 48
479687679697 46
171144669185 44
619301422333 11
115275514360 51
357658863077 18
435025021428 10
532397231890 46
831463813173 29
751774983526 13
331915882382 27
305069804446 45
781149541018 46
245297399117 45
716700187940 27
61309249885 20
546481966522 28
435548933326 47
4719749101...

output:


result:


Test #6:

score: 10
Accepted
time: 394ms
memory: 6812kb

input:

40
175313422703 41
668554077197 28
46515670365 3
742128007881 3
597769331487 57
473156474346 51
555734731567 13
536262552944 12
280927598505 7
733572833714 57
384137261807 56
691329695834 13
771944255405 24
618237624522 34
392255598870 52
834174408779 38
249378938395 42
561969968921 23
140146815381 ...

output:

71445950881
466723327217
23257835183
371064003941
384182581034
304095064438
248242368023
376660602663
132437296440
471462635902
284703316365
308811580464
573848019370
402323110836
276166592512
542896160975
184241259561
240497645986
88731648380
83257008250
54615012469
694913482890
3464121834
50464269...

result:

ok 40 numbers

Test #7:

score: 10
Accepted
time: 346ms
memory: 6692kb

input:

40
137305220295 31
193845497145 7
962497300504 25
368785043518 8
953644561658 48
193025461331 36
840734481501 1
533572751059 33
196834696419 29
891413522825 26
962271824032 16
202601114680 16
694337374117 22
943323275350 47
569573675124 56
904629880258 8
370400863271 23
173999416545 3
391756029208 2...

output:

57334471252
91384305794
552994311358
235759009964
733997410475
146678214605
0
342759372486
82197039852
580116025754
646765708038
136173012774
451398070762
383377056255
422139506789
578316959165
158514761670
86999708273
273630480974
484299439324
290120090522
401410944445
311159803754
450154371449
218...

result:

ok 40 numbers

Test #8:

score: 10
Accepted
time: 336ms
memory: 8092kb

input:

40
881016335236 48
638231672168 23
103399835277 60
614433314132 14
997269035780 55
223271883948 7
729216955531 7
835214784347 19
33057449007 60
638568044682 13
395718905847 51
433782552943 54
183782204284 8
305922876055 4
758641313049 13
88279097335 27
516887865419 57
755360065025 20
41306349942 15
...

output:

678097201596
273134194474
81977861134
400108007251
625566921205
105256745291
343773707607
363340806170
26208735772
285243362610
254326364947
321762152717
117489337739
178455011031
338879154623
56318186676
332200572684
527597592616
26152435282
318610621433
623156115542
485215863847
445221752474
22406...

result:

ok 40 numbers

Test #9:

score: 0
Time Limit Exceeded

input:

40
607133757272 46
838009504113 6
590986326994 22
855393603878 44
740162516232 53
217094184817 16
8492610764 7
42208309410 15
695394531401 39
609973215777 53
829974076649 59
375655472415 48
645002905745 29
417491209528 46
216159998106 56
600168186288 44
532747090211 10
709089965281 18
845106680415 5...

output:


result:


Test #10:

score: 0
Time Limit Exceeded

input:

40
731099174499 6
324727098669 18
845451652180 55
439615161896 35
400277785279 26
908689852003 8
263580613375 26
406650175007 24
705201256490 47
820334553144 29
825664216676 37
645202552816 34
948907755479 30
764621811758 24
849595370745 25
124514947739 53
47927748232 9
669177674276 59
263998454524 ...

output:


result: