QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#770519#9597. Grade 2AlucardWA 455ms100504kbC++142.5kb2024-11-21 22:11:332024-11-21 22:11:33

Judging History

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

  • [2024-11-21 22:11:33]
  • 评测
  • 测评结果:WA
  • 用时:455ms
  • 内存:100504kb
  • [2024-11-21 22:11:33]
  • 提交

answer

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define i128 _int128
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define int long long

const ll INF = 0x3f3f3f3f;
const int N = 4e6 + 9, M = 1e9 + 9;
const ll mod = 998244353;

int read(){
    int s = 0, w = 1;
    char c = getchar();
    while (!isdigit(c))
        (c == '-') ? w = -1 : w = 1, c = getchar();
    while (isdigit(c))
        s = (s << 1) + (s << 3) + (c ^ 48), c = getchar();
    return s * w;
}

int qpow(int a, int b){
    a %= mod;
    int res = 1;
    while (b)
    {
        if (b & 1)
        {
            res = (res * a) % mod;
        }
        a = (a * a) % mod;
        b >>= 1;
    }
    return res % mod;
}

int gcd(int a, int b){
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}

// int inverse(int a){
//     a%=mod;
// 	return qpow(fac[a%mod],mod-2)%mod;
// }

// int C(int n,int r){
//     n%=mod,r%=mod;
//     if(r>n)return 0;
//     return ((fac[n%mod]*inverse(r))%mod*inverse(n-r))%mod;
// }

// int Lucas(int n,int r){
//     if(r==0)return 1;
//     return C(n%mod,r%mod)%mod*Lucas(n/mod,r/mod)%mod;
// }

int x, n, mini_sum, l, r, ans;
map<int, int> res;
int prefix[N];

void solve(){
    cin>>x>>n;
    int p=1;
    ans=0;
    memset(prefix,0,sizeof(prefix));
    while(p<x)p*=2;
    int fid=0,lid=0;
    for(int i=1;i<=p;++i){
        if(gcd(((i*x)^x),x)==1){
            // cout<<i<<endl;
            res[i]=1;
            mini_sum++;
            if(fid==0)fid=i;
            lid=i;
        }
        prefix[i]=prefix[i-1]+res[i];
    }
    // for(int i=1;i<=p;++i){
    //     cout<<i<<'-'<<prefix[i]<<endl;
    // }
    // cout<<fid<<' '<<lid<<endl;
    while(n--){
        cin>>l>>r;
        if(!x&1)ans=0;
        else{
            ans=0;
            int cl=ceil((double)l/p),cr=r/p;
            if(p*cl<=p*cr){
                ans=mini_sum*(cr-cl);
                ans+=prefix[r%p];
            }
            ans+=prefix[min(r,cl*p-1)%p]-prefix[(l-1)%p];
            cout<<ans<<endl;
        }
    }
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int _ = 1;
    // fac[0]=1;
    // for(int i=1;i<=N-9;++i)fac[i]=(fac[i-1]*i)%mod;
    // cin>>_;

    while(_--)solve();

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 34988kb

input:

15 2
1 4
11 4514

output:

2
2252

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 154ms
memory: 67796kb

input:

500696 100000
110442401300 646889080214
337192 670162015551
508011001649 508011014425
94418501628 94418501634
824168677375 824168677376
732815842309 795402573302
353241304050 846773277757
622033633276 622033633284
760381702139 760381702143
207714 795408271057
382792 952061527685
686173 331215904334
...

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 100000 lines

Test #3:

score: 0
Accepted
time: 159ms
memory: 67724kb

input:

465262 100000
119442423888 249533375982
528365238401 528365275157
654839906300 654839906303
135820863700 135820967840
336231 918143221477
568175915485 568176067832
993015103483 993015103488
951474 444595379179
298623434750 298623434751
257961 410491919396
996297715292 996297994388
17765498878 177654...

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 100000 lines

Test #4:

score: 0
Accepted
time: 294ms
memory: 100504kb

input:

599394 100000
683408 868635908987
347999512025 347999739145
740945 377178907084
399211757563 399211757568
766968 548821086083
630762 702128377806
756554924031 756554924036
904713771313 904714518208
17026878789 17027129255
11601638470 206412869961
253365321722 253365321730
785476956554 785477402085
2...

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 100000 lines

Test #5:

score: 0
Accepted
time: 89ms
memory: 51440kb

input:

255255 100000
693776785134 693776920782
174578728959 174578728960
109045569231 631173362385
470661333171 470661439492
401883 183360880923
436203696728 436203931780
165055 339075075373
640081 299360395352
864237441330 864237509663
730335563579 730335652091
194265481215 194265481219
40664920117 406649...

output:

48406
1
186110004314
37959
65357983202
83815
120861662355
106705381500
24327
31556
2
13697
28081
260202193146
52511483770
4
46174459075
3
175347987986
2
47909
258154440479
327427357801
2
22468
54932
46381156133
45666301683
94552873123
55243
2
152254920558
2
109713294365
91231052949
144890963440
1
19...

result:

ok 100000 lines

Test #6:

score: 0
Accepted
time: 186ms
memory: 67824kb

input:

504735 100000
890566082557 890566082559
106681282682 350150954751
14542620333 14542688528
962703917051 962703917057
100450168807 730499846454
90869911943 879001649039
367411155928 367411237841
162790964603 162791319243
843464048636 843464048641
50183553762 50183754394
536413208571 536413208579
76470...

output:

3
91776653818
25745
4
237499194819
297088721196
30767
133683
4
75618
5
14803350036
102273946312
294367282076
90067
26374064222
218863908151
5920
116441
80585705578
78122672310
26247
4
2
362715381968
5
118998177006
1
46573605766
3
294440148616
16240766556
148286820503
170413778829
308538368031
80990
...

result:

ok 100000 lines

Test #7:

score: 0
Accepted
time: 157ms
memory: 67732kb

input:

510510 100000
636202516477 636202516483
766250113730 766250554933
783526 196225463076
79706372523 706598274579
942892 658373730973
467824279548 467824279556
21452896555 313469857150
378837 377299671727
240905 332480727153
498636101528 498636124308
976243856348 976243893391
292392 796495578924
544557...

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 100000 lines

Test #8:

score: 0
Accepted
time: 22ms
memory: 35060kb

input:

5 100000
577002044614 577002044615
927612729821 927612729823
458108524625 458108524631
280764605824 668589153220
952951869418 952951869419
529611 683061174939
139562629162 943958766161
682886119356 682886119359
809277569284 809277569288
273256 823615062996
553997 845861944424
810372 355828187260
560...

output:

2
3
4
193912273697
0
341530322664
402198068500
4
4
411807394869
422930695215
177913688445
0
0
4
3
384044390963
2
225492836247
123433323681
163157461936
325461532446
1
143731759371
302892329368
432434490591
3
4
380078319798
2
475791735460
2
0
175885810334
1
106930234833
0
248426664239
3
3
2
142058695...

result:

ok 100000 lines

Test #9:

score: 0
Accepted
time: 22ms
memory: 34980kb

input:

67 100000
554948711586 554948711636
107216748533 551267140383
563444278266 563444278271
296834528251 296834528257
945075901986 945075902057
820833 418403638528
42398724782 775548809425
136440466958 136440467007
137424666397 245095767595
293841341489 293841341519
389980376654 389980376662
65049866518...

output:

41
333037793887
6
5
52
313802113274
549862563484
36
80753325903
24
9
204510681731
473854242629
97253383657
475906911704
2
410453985059
65
592074124647
58
116232829554
3
26550484176
9
8
608544154442
4
596001232498
7
7
295977286700
37
206073186915
280442942335
42
4
546702626742
7689840672
25
206159337...

result:

ok 100000 lines

Test #10:

score: 0
Accepted
time: 19ms
memory: 35004kb

input:

647 100000
463906998888 479659267251
268847 751155874289
651417786367 651417786370
497555 155709224392
622915482618 622915482628
777631 838255026695
243048678285 883954678899
772196356537 967103315725
82204086763 82204087076
66104 324475714342
991803 866563791381
463633987995 958099429201
383184 307...

output:

14767751592
704208380099
2
145976931409
9
785863358495
600849375577
182725274236
296
304195920221
812402624603
463561351131
288610355562
129966561457
283627883934
147229474948
7
912956605545
1
4
571081297966
248
359551529842
583
6
743201235071
7
3
189759269108
432607129516
6
5
434423260186
275
25074...

result:

ok 100000 lines

Test #11:

score: 0
Accepted
time: 20ms
memory: 35484kb

input:

4889 100000
767055827601 767055829288
490893 294465817432
199109591038 199109591039
399822153968 880358292711
825864 747773295851
118874 331319816798
928131530748 928131530753
533475 556937288088
417423462211 417423463757
285188 108197134613
199505599366 261970387618
533517149327 533517151742
848403...

output:

1636
285263285082
2
465519384412
724404580300
320965957363
4
539532481036
1499
104815697882
60512763621
2338
366584431777
3
761707061319
835258241886
2
238377636719
1469
2
45526221069
8
7
4
7
782134351716
902323964729
4
4
265399465733
1
5214
6
3271
2823
789992986908
355206949764
1151
65083701660
112...

result:

ok 100000 lines

Test #12:

score: 0
Accepted
time: 63ms
memory: 43288kb

input:

71473 100000
656103964666 656103964671
498648624075 498648637229
390504315038 647137082392
570202 924129361870
280087103369 431002142325
298239920694 774852456682
706167805477 706167829997
18668 138509788321
253794 654841194475
552838823872 552838883299
593165270991 891051126522
792248 278481571911
...

output:

6
13051
254627823863
916909035485
149736015217
472889000553
24331
137427662078
649724995836
58966
295558622282
276305148576
58150260531
8727462519
65958
34832
32273
1
374742818985
974579726797
703332411703
6
112493
2313
16964
280078382150
493585564078
5
876393142339
67113
51312803819
277929355688
5
...

result:

ok 100000 lines

Test #13:

score: 0
Accepted
time: 449ms
memory: 100448kb

input:

947137 100000
939374 755248253137
224227105223 472382869959
92509901532 701330847277
221867943268 946309636964
736631 404594275091
520041 340554160109
970446602238 970446602242
160354561278 751516102516
64990740479 64990740479
188023308283 188023308288
981243156946 981243222322
223384960026 44150610...

output:

754509767562
247913425109
608226394050
723734231081
404198427581
340221068165
3
590584235039
1
5
65313
217908137513
162936
8
149195
475632034863
3
292614
125979
3309
523598
336729889389
3
718959183140
1
701322266556
648513042428
6
157001
6
4
891628987081
839203
245040
137154282443
199050435598
25288...

result:

ok 100000 lines

Test #14:

score: 0
Accepted
time: 455ms
memory: 100452kb

input:

999763 100000
871469416445 871469416451
66152 791908961867
777345764209 777346045153
269291 297435009460
669356 360116089360
421377007492 783648031951
636957491199 636957491202
786893578508 786894249495
492327403515 492327403523
679508 654247174373
555190 965731300993
726894 279530730056
39378256871...

output:

5
790362198664
280395
296853812946
359412069573
361563463880
2
669686
7
652968669672
963844552936
278984046121
391256570836
978790360056
373170
4
679003
232633722051
448204751658
289995000591
3
939539712284
122172522837
385970821243
52443
575552777171
54043795511
525802
217025558619
446523
778017
72...

result:

ok 100000 lines

Test #15:

score: -100
Wrong Answer
time: 22ms
memory: 34968kb

input:

1 100000
391128977208 391128977208
596942630965 596942630969
208018 606593799103
629194896599 629194896599
349835863178 349835863178
531106536425 776212608295
736525416802 736525416802
81923833591 317949656478
536473402655 552509399268
125131 497916267917
403831493758 403831493758
696952420329 69695...

output:

0
4
606593591085
0
0
245106071870
0
236025822887
16035996613
497916142786
0
9
4
220224934733
2
623653273711
8
648891320825
0
412548830080
412088340786
6
564864603388
0
0
257968996148
0
7
7
4
2
5
0
0
272014261928
151772775391
0
80372883000
0
0
1
299815189371
9
5
0
298043332433
0
0
854736150527
0
0
0
...

result:

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