QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#103674#2574. Fancy ArraysSortingTL 97ms3580kbC++205.3kb2023-05-07 07:29:142023-05-07 07:29:18

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-07 07:29:18]
  • 评测
  • 测评结果:TL
  • 用时:97ms
  • 内存:3580kb
  • [2023-05-07 07:29:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair < int , int > pii ;
typedef vector < int > vi ;
#define fi first
#define se second
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

const int MOD = 1e9 + 7 ;

ull modmul(ull a, ull b, ull M) {
	ll ret = a * b - M * ull(1.L / M * a * b);
	return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull modpow(ull b, ull e, ull mod) {
	ull ans = 1;
	for (; e; b = modmul(b, b, mod), e /= 2)
		if (e & 1) ans = modmul(ans, b, mod);
	return ans;
}


bool isPrime(ull n) {
	if (n < 2 || n % 6 % 4 != 1) return (n | 1) == 3;
	ull A[] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022},
	    s = __builtin_ctzll(n-1), d = n >> s;
	for (ull a : A) {   // ^ count trailing zeroes
		ull p = modpow(a%n, d, n), i = s;
		while (p != 1 && p != n - 1 && a % n && i--)
			p = modmul(p, p, n);
		if (p != n-1 && i != s) return 0;
	}
	return 1;
}


ull pollard(ull n) {
	auto f = [n](ull x) { return modmul(x, x, n) + 1; };
	ull x = 0, y = 0, t = 30, prd = 2, i = 1, q;
	while (t++ % 40 || __gcd(prd, n) == 1) {
		if (x == y) x = ++i, y = f(x);
		if ((q = modmul(prd, max(x,y) - min(x,y), n))) prd = q;
		x = f(x), y = f(f(y));
	}
	return __gcd(prd, n);
}
vector<ull> factor(ull n) {
	if (n == 1) return {};
	if (isPrime(n)) return {n};
	ull x = pollard(n);
	auto l = factor(x), r = factor(n / x);
	l.insert(l.end(), r.begin ( ) , r.end ( ) );
	return l;
}

ull n ;
int q ;
map < ull , int > w ;
int cnt[ 60 ] ;
int tp = 0 ;
vector < int > v[ 500 ] ;
vector < int > aux ;
vector < int > ex ;

void rec ( int pos ) {
    if ( pos == 60 ) {
        v[ tp ++ ] = aux ;
        return ;
    }
    if ( cnt[ pos ] == 0 ) {
        rec ( pos + 1 ) ;
        return ;
    }
    for ( int i = 0 ; i <= cnt[ pos ] ; ++ i ) {
        aux.push_back ( i ) ;
        rec ( pos + 1 ) ;
        aux.pop_back ( ) ;
    }
}

vector < vector < int > > ori ;
vector < vector < int > > pw[ 61 ] ;
vector < vector < int > > ret , ans ;

void mul ( vector < vector < int > > &hh1 , vector < vector < int > > &hh2 ) {
    for ( int i = 0 ; i < tp ; ++ i ) {
        for ( int j = 0 ; j < tp ; ++ j ) {
            ret[ i ][ j ] = 0 ;
            for ( int t = 0 ; t < tp ; ++ t ) {
                ret[ i ][ j ] += ( 1LL * hh1[ i ][ t ] * hh2[ t ][ j ] ) % MOD ;
                if ( ret[ i ][ j ] >= MOD ) { ret[ i ][ j ] -= MOD ; }
            }
        }
    }
}

ll qlen[ 152 ] , qret[ 152 ] ;

pair < ll , int > srt[ 152 ] ;

void solve ( ) {
    cin >> n >> q ;
    vector < ull > divs = factor ( n ) ;
    for ( auto x : divs ) {
        ++ w[ x ] ;
    }
    for ( auto e : w ) {
        ++ cnt[ e.se ] ;
    }
    for ( int i = 0 ; i <= 60 ; ++ i ) {
        if ( cnt[ i ] > 0 ) { ex.push_back ( i ) ; }
    }
    rec ( 1 ) ;
    int sz = v[ 0 ].size ( ) ;
    ori.resize ( tp ) ;

    for ( int i = 0 ; i < tp ; ++ i ) {
        ori[ i ].resize ( tp , 0 ) ;
        for ( int j = 0 ; j < tp ; ++ j ) {
            ll bad = 1 , tot = 1 ;
            for ( int k = 0 ; k < sz ; ++ k ) {
                ll rem = cnt[ ex[ k ] ] - v[ i ][ k ] , foo = cnt[ ex[ k ] ] ;
                for ( int ctr = 0 ; ctr < v[ j ][ k ] ; ++ ctr ) {
                    bad = ( bad * ( rem -- ) ) ;
                    tot = ( tot * ( foo -- ) ) ;
                    bad = bad * ( ex[ k ] ) ;
                    tot = tot * ( ex[ k ] ) ;
                }
                for ( int ctr = 0 ; ctr < v[ j ][ k ] ; ++ ctr ) {
                    bad = ( bad / ( ctr + 1 ) ) ;
                    tot = ( tot / ( ctr + 1 ) ) ;
                }
            }
            ori[ i ][ j ] = ( tot - bad ) % MOD ;
            if ( i == 0 || j == 0 ) { ori[ i ][ j ] = 0 ; }
        }
    }
    ans.resize ( tp ) ;
    ret.resize ( tp ) ;
    for ( int i = 0 ; i < tp ; ++ i ) {
        ans[ i ].resize ( tp , 0 ) ;
        ret[ i ].resize ( tp , 0 ) ;
    }
    pw[ 0 ].assign ( ori.begin ( ) , ori.end ( ) ) ;
    for ( int i = 1 ; i <= 60 ; ++ i ) {
        mul ( pw[ i - 1 ] , pw[ i - 1 ] ) ;
        pw[ i ].assign ( ret.begin ( ) , ret.end ( ) ) ;
    }
    for ( int i = 0 ; i < tp ; ++ i ) {
        for ( int j = 0 ; j < tp ; ++ j ) {
            assert ( ori[ i ][ j ] == pw[ 0 ][ i ][ j ] ) ;
        }
    }
    for ( int i = 1 ; i <= q ; ++ i ) {
        cin >> qlen[ i ] ;
        srt[ i ] = { qlen[ i ] , i } ;
    }
    sort ( srt + 1 , srt + q + 1 ) ;
    for ( int i = 0 ; i < tp ; ++ i ) {
        for ( int j = 0 ; j < tp ; ++ j ) {
            if ( i == j ) { ans[ i ][ j ] = 1 ; }
            else { ans[ i ][ j ] = 0 ; }
        }
    }
    ll lvl = 0 ;
    for ( int i = 1 ; i <= q ; ++ i ) {
        ll diff = srt[ i ].fi - lvl ;
        for ( int j = 60 ; j >= 0 ; -- j ) {
            if ( diff >= ( 1LL << j ) ) {
                mul ( ans , pw[ j ] ) ;
                ans = ret ;
                diff -= ( 1LL << j ) ;
            }
        }
        for ( int j = 0 ; j < tp ; ++ j ) {
            qret[ srt[ i ].se ] = ( qret[ srt[ i ].se ] + ans[ tp - 1 ][ j ] ) % MOD ;
        }
        if ( srt[ i ].fi == 1 ) { ++ qret[ srt[ i ].se ] ; }
        lvl = srt[ i ].fi ;
    }
    for ( int i = 1 ; i <= q ; ++ i ) {
        cout << qret[ i ] << "\n" ;
    }
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    int t = 1 ; // cin >> t ; 
    while ( t -- ) { solve ( ) ; }
    return 0 ;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3496kb

input:

12 3
1
2
3

output:

6
21
91

result:

ok 3 number(s): "6 21 91"

Test #2:

score: 0
Accepted
time: 2ms
memory: 3408kb

input:

1 150
471816347971198367
934144370769132530
85747619384378846
928941512582005725
154937870030720168
947932149793416512
27783441557851811
522085897018258944
254251197759739965
280173028039582607
323577718378116194
390211126917894813
349211961997885462
482844442408522462
582732208453073301
94800734555...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 150 numbers

Test #3:

score: 0
Accepted
time: 0ms
memory: 3472kb

input:

2 150
879653409269605014
957081824205994700
92943925332284309
70508831927780168
72367833784810922
57052500883916366
260855517197770739
493364569696106472
261906268272035425
712282959082227662
35005533487670014
740269757357303611
472541044721679500
231355986572948422
563516773952248704
38987628675191...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

result:

ok 150 numbers

Test #4:

score: 0
Accepted
time: 2ms
memory: 3488kb

input:

4 150
833174642454220423
721913650877167279
111257970647375842
922819627392160450
408011919008881312
938552585499192014
401181394137854787
154596954164557809
43303362814617574
450360165684736834
713407776281798115
265067947883317301
820681723927726574
17493726254665319
431343457571478167
51814600647...

output:

468840309
547289647
533838877
966360705
857529002
153274687
262629852
52838138
491303862
824933368
322126614
254980983
479226482
849822478
733697869
39083554
972201092
931290745
94464717
488665996
671570906
328618580
560220503
648667666
629662517
387210606
508021018
647625623
446432016
725472621
181...

result:

ok 150 numbers

Test #5:

score: 0
Accepted
time: 3ms
memory: 3444kb

input:

12 150
866520608211357891
826644240983841587
604468068635680936
683891212731586479
729458231854829796
199304421232371994
115565992620864149
582246847462487026
45026322404633290
991496269676336501
828552610616377158
777876324164467943
21599638116777490
828672919384884473
156000006365142361
1075758095...

output:

779414664
514445561
232707217
332166208
129233036
140771797
795601301
985364453
520952055
724746825
753012961
330741891
856478920
617535185
769187104
694821591
377746976
624170068
604988921
681705434
307373491
860391243
993177813
401466218
638396860
81657365
567590547
536248402
218207546
850043246
7...

result:

ok 150 numbers

Test #6:

score: 0
Accepted
time: 6ms
memory: 3432kb

input:

60 150
942384627889050160
632722531683900587
323010899964408037
768156669746553097
910441269274010456
574994561230251602
991998693470233584
946559918384472428
688850429932902531
546016664495112655
911292584182165502
544392675853675112
286896336919591702
26067995914490533
342959982557875555
652184567...

output:

932200580
903893996
357154050
968506185
742674333
892926972
955069213
359920050
662550206
709081432
789644301
156063250
217976189
960971758
150053868
654190187
4302337
143734760
134807911
682516411
414799732
641288662
760159256
358958740
258320312
382386241
181861029
980283133
85490921
826348474
915...

result:

ok 150 numbers

Test #7:

score: 0
Accepted
time: 12ms
memory: 3440kb

input:

420 150
652643102578585626
815592668110344564
80182963922677648
329298533050661052
888030230126602620
366600500217079827
410187526382051676
102382793137115355
274746471179172353
296927801740189908
315100659826195468
117705908453673624
768586284103816365
68311227918233771
180984322159013983
934861174...

output:

134106992
679303625
834034299
991574091
800679260
187365176
338079081
632426140
889580947
359580371
291928987
167306560
879609773
6190610
230006744
690370376
32999033
279019618
258258432
470436938
155317311
403241661
56033583
77078814
968951238
37546219
154714275
643164852
354497133
450000862
491335...

result:

ok 150 numbers

Test #8:

score: 0
Accepted
time: 24ms
memory: 3464kb

input:

4620 150
297322315854726773
280471159266106599
699801246349452330
65496083279950550
871398581662271626
856073774431287314
261685312184467620
794118362921655401
559675718578383421
852245166791982043
206354949512966676
74912770463068510
763582430583263339
682350125491835657
902249948237866072
34545707...

output:

986044811
103091966
935113777
583542759
22612061
321972881
54295640
624452113
567960641
103460045
69195739
318209967
920265424
943514529
699397996
726777723
966124283
112846048
521332082
451189762
618299099
289852269
781213823
983239700
562263268
288749357
822981064
614412918
688340550
849355405
193...

result:

ok 150 numbers

Test #9:

score: 0
Accepted
time: 37ms
memory: 3432kb

input:

60060 150
321042833671319069
814779641977482535
206907881258140242
767656477507514350
965658116010881153
888046414032773423
752829149707163137
37075116613065442
825910891680936350
565535799506538902
42554938199054555
8281169553665359
762279657524288035
721144630802920750
317996750034298205
925077279...

output:

74005897
258648189
740728514
951722800
984957343
681780261
798706732
228390199
206326177
200055927
952166057
303251351
111205729
988934736
386979870
98349805
70618759
601550202
318699486
271487431
26515923
34666519
949278619
788840050
6330372
598336830
924291965
505223310
870746431
867707461
8648310...

result:

ok 150 numbers

Test #10:

score: 0
Accepted
time: 66ms
memory: 3508kb

input:

1021020 150
150546375236259464
956402079575897507
968744791372351937
13463566892651571
692798889396376374
916586573012377121
924472563871303333
240428216767012645
201769115986535644
434378618828710810
128004453899931139
206891611964666356
645377478508905195
815021290558325956
719028170873713564
1930...

output:

262996144
987798410
14820748
289072324
963824210
979941239
585955578
518300473
129823444
534729569
25449906
226686496
186371714
410946085
594251433
271314073
738280663
196494119
903815636
879387765
824397505
708849774
389012220
686309715
258859407
35876421
991782680
75766926
93598945
35416944
774534...

result:

ok 150 numbers

Test #11:

score: 0
Accepted
time: 97ms
memory: 3580kb

input:

19399380 150
236744048803792416
885780066050607118
828951197292810646
284651790382979731
606532017420458180
560079481459864793
539163183635352360
482802457708205662
228992116223889573
913777324385054202
906030569026659864
377107783185934542
483336437389083834
321631993535981481
724639864832760572
90...

output:

12331829
642558635
824299074
413423313
999070667
197490327
97388134
22927131
388819376
114986062
187368983
954105673
443408571
53711161
796465194
241085176
578817122
130283588
553303116
777107049
199876531
26416438
518944833
431524394
261407022
744927174
929895387
750357617
538155073
131439019
71960...

result:

ok 150 numbers

Test #12:

score: 0
Accepted
time: 13ms
memory: 3484kb

input:

69657034752000 150
403776100446711204
876994814256699519
358809067106070890
412670168821855830
205995758175869757
572442827386738585
923826004198949890
339609305869204070
520518044744048844
294563501488160749
400224049857958833
591478758481285289
494376786934891788
656940592622961750
649287802846795...

output:

503414314
635744710
692661894
728926999
52090322
412610766
863876734
832848120
218233091
626436736
960714899
252407342
641482308
576955912
787908231
539061074
961790198
322709898
875187824
81605008
176872142
510266542
915296599
716039366
480916810
50673040
901814730
50935546
19662315
394302225
21210...

result:

ok 150 numbers

Test #13:

score: -100
Time Limit Exceeded

input:

6257464012800 150
314719601137586866
70900274752717238
211126593622501975
861725907911381796
567133665411030378
284058563770137851
804925287843405996
585441965108843256
855862024117061122
601973598224965807
108390577626243554
575443097322310047
753119410812825352
946809189769995963
76770059502845287...

output:


result: