QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#743475#9597. Grade 2lonelywolf#WA 2341ms239128kbC++172.6kb2024-11-13 19:18:252024-11-13 19:18:26

Judging History

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

  • [2024-11-13 19:18:26]
  • 评测
  • 测评结果:WA
  • 用时:2341ms
  • 内存:239128kb
  • [2024-11-13 19:18:25]
  • 提交

answer

#include <bits/stdc++.h>  
using namespace std;  

#define int long long  

#define uint unsigned long long

constexpr uint mod = (1ull << 61) - 1;

mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<uint> dist(mod / 2, mod - 1);
const uint base = dist(rnd);

static inline uint add(uint a, uint b) {
    a += b;
    if (a >= mod) {
        a -= mod;
    }
    return a;
}
static inline uint mul(uint a, uint b) {
    __uint128_t c = __uint128_t(a) * b;
    return add(c >> 61, c & mod);
}

vector<int> power;
void init(int n) {
    power.resize(n);
    power[0] = 1;
    for (int i = 1; i < n; i++) {
        power[i] = mul(power[i - 1], base);
    }
}
vector<uint> build(const vector<int> &s) {
    int n = s.size() - 1;
    vector<uint> hashed(n + 1);
    for (int i = 1; i <= n; i++) {
        hashed[i] = add(mul(hashed[i - 1], base), s[i]);
    }
    return hashed;
}

uint query(const vector<uint> &s, int l, int r) {
    return add(s[r], mod - mul(s[l - 1], power[r - l + 1]));
}

uint merge(uint h1, uint h2, int len2) {
    return add(mul(h1, power[len2]), h2);
}

signed main() {  
    ios::sync_with_stdio(false);
    cin.tie(nullptr);  

    int x, n;
    cin >> x >> n;

    if (x % 2 == 0) {
    	while (n--) {
    		int l, r;
    		cin >> l >> r;
    		cout << 0 << "\n";
    	}
    	return 0;
    }

    if (x == 1) {
    	while (n--) {
    		int l, r;
    		cin >> l >> r;
    		cout << r - l + 1 << "\n";
    	}
    	return 0;
    }

   
    vector<int> t;
    int f = 1;
    int b = 0;
    int lst = 0;
    while (t.size() < (int)1e7 + 10) {
    	if (gcd((f * x) ^ x, x) == 1) {
    		if (b == 0) {
    			b = f;
    		} else {
    			t.push_back(f - lst);
    		}
    		lst = f;
    	}
    	f++;
    }

    init(1e7 + 10);
    auto hash = build(t);

    int len = 0;
    for (int i = 5000000; i >= 2; i -= 2) {
    	if (query(hash, 1, i) == query(hash, i + 1, 2 * i)) {
    		len = i;
    		break;
    	}
    }
    for (int i = 1; i < len; i++) {
    	t[i] += t[i - 1];
    }
    int T = t[len - 1];

    auto calc = [&](int a) {
    	if (a < b) {
    		return 0LL;
    	}

    	a -= b;
    	int ret = 1 + a / T * t.size();
    	a %= T;

    	int l = -1, r = len;
    	while (l + 1 != r) {
    		int m = (l + r) / 2;
    		if (t[m] <= a) {
    			l = m;
    		} else {
    			r = m;
    		}
    	}
		ret += l + 1;	
    	return ret;
    };

    while (n--) {
    	int l, r;
    	cin >> l >> r;
    	cout << calc(r) - calc(l - 1) << "\n";
    }

    return 0;
}  


  

详细

Test #1:

score: 100
Accepted
time: 672ms
memory: 239128kb

input:

15 2
1 4
11 4514

output:

2
2252

result:

ok 2 lines

Test #2:

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

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: 19ms
memory: 3816kb

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: 13ms
memory: 3620kb

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: 2341ms
memory: 238368kb

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
375802194514
37959
131972348132
83815
244050536805
215462910240
24327
31556
2
13697
28081
525412873436
106032140840
4
93234072945
3
354071547816
2
47909
521275377109
661160429841
2
22468
54932
93652772983
92211051173
190928418293
55243
2
307441101918
2
221534770935
184214550439
292571229770
...

result:

wrong answer 3rd lines differ - expected: '186110004314', found: '375802194514'