QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#770504#9597. Grade 2AlucardWA 313ms100460kbC++142.6kb2024-11-21 22:07:462024-11-21 22:07:47

Judging History

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

  • [2024-11-21 22:07:47]
  • 评测
  • 测评结果:WA
  • 用时:313ms
  • 内存:100460kb
  • [2024-11-21 22:07:46]
  • 提交

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
        {   
            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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

15 2
1 4
11 4514

output:

2
2252

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 146ms
memory: 67648kb

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: 157ms
memory: 67696kb

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: 313ms
memory: 100460kb

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: -100
Wrong Answer
time: 93ms
memory: 51300kb

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
186110042273
65357983202
65358067017
120861662355
106705381500
106705405827
106705437383
2
13699
41780
260202193146
52511483770
4
46174459075
3
175347987986
2
47911
258154440479
327427357801
2
22470
77402
46381156133
45666301683
94552873123
94552928366
2
152254920558
2
109713294...

result:

wrong answer 4th lines differ - expected: '37959', found: '186110042273'