Submission #726833

# Submission time Handle Problem Language Result Execution time Memory
726833 2023-04-19T12:08:46 Z penguin133 Strange Device (APIO19_strange_device) C++17
100 / 100
557 ms 53260 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve(){
	int n, a, b;
	cin >> n >> a >> b;
	int tmp = __gcd(a, b+1);
	__int128 x = a;
	x *= b;
	x /= tmp;
	vector <pi> v;
	int ans = 0;
	for(int i=1;i<=n;i++){
		int l, r; cin >> l >> r;
		if(l == r){
			v.push_back({l%x, l%x});
			continue;
		}
		__int128 l1 = l, r1 = r;
		if(r1 >= l1 + x){
			cout << (long long)x << '\n';
			return;
		}
		l %= x;
		r %= x;
		if(l > r)v.push_back({l, x-1}), v.push_back({0, r});
		else v.push_back({l, r});
	}
	sort(v.begin(), v.end());
	int prv = -1, st = -1;
	for(auto [i, j] : v){
		if(i > prv){
			if(prv != -1)ans += prv-st+1;
			st = i;
		}
		prv = max(prv, j);
	}
	if(prv != -1)ans += prv-st+1;
	cout << ans;
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	//cin >> tc;
	for(int tc1=1;tc1<=tc;tc1++){
		// cout << "Case #" << tc1 << ": ";
		solve();
	}
}

Compilation message

strange_device.cpp:52:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   52 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 5 ms 984 KB Output is correct
3 Correct 6 ms 984 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 4 ms 980 KB Output is correct
17 Correct 47 ms 3556 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 314 ms 16944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 431 ms 17128 KB Output is correct
3 Correct 439 ms 17244 KB Output is correct
4 Correct 391 ms 17256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 431 ms 17128 KB Output is correct
3 Correct 439 ms 17244 KB Output is correct
4 Correct 391 ms 17256 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 438 ms 17352 KB Output is correct
7 Correct 394 ms 17340 KB Output is correct
8 Correct 395 ms 17256 KB Output is correct
9 Correct 432 ms 17072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 431 ms 17128 KB Output is correct
3 Correct 439 ms 17244 KB Output is correct
4 Correct 391 ms 17256 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 55 ms 3108 KB Output is correct
7 Correct 50 ms 3264 KB Output is correct
8 Correct 40 ms 3172 KB Output is correct
9 Correct 44 ms 3260 KB Output is correct
10 Correct 40 ms 3272 KB Output is correct
11 Correct 47 ms 3272 KB Output is correct
12 Correct 45 ms 3272 KB Output is correct
13 Correct 47 ms 3196 KB Output is correct
14 Correct 40 ms 3220 KB Output is correct
15 Correct 43 ms 3272 KB Output is correct
16 Correct 44 ms 3192 KB Output is correct
17 Correct 45 ms 3228 KB Output is correct
18 Correct 394 ms 17328 KB Output is correct
19 Correct 406 ms 17504 KB Output is correct
20 Correct 467 ms 17392 KB Output is correct
21 Correct 43 ms 3180 KB Output is correct
22 Correct 39 ms 3260 KB Output is correct
23 Correct 123 ms 8924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 51 ms 3448 KB Output is correct
3 Correct 52 ms 3552 KB Output is correct
4 Correct 523 ms 17552 KB Output is correct
5 Correct 48 ms 3460 KB Output is correct
6 Correct 50 ms 3528 KB Output is correct
7 Correct 47 ms 3684 KB Output is correct
8 Correct 54 ms 3488 KB Output is correct
9 Correct 48 ms 3460 KB Output is correct
10 Correct 46 ms 3500 KB Output is correct
11 Correct 47 ms 3676 KB Output is correct
12 Correct 41 ms 3520 KB Output is correct
13 Correct 50 ms 3636 KB Output is correct
14 Correct 484 ms 16984 KB Output is correct
15 Correct 49 ms 3956 KB Output is correct
16 Correct 399 ms 17008 KB Output is correct
17 Correct 406 ms 17016 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 5 ms 984 KB Output is correct
3 Correct 6 ms 984 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 4 ms 980 KB Output is correct
17 Correct 47 ms 3556 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
20 Correct 0 ms 324 KB Output is correct
21 Correct 0 ms 320 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 316 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 314 ms 16944 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 431 ms 17128 KB Output is correct
31 Correct 439 ms 17244 KB Output is correct
32 Correct 391 ms 17256 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 438 ms 17352 KB Output is correct
35 Correct 394 ms 17340 KB Output is correct
36 Correct 395 ms 17256 KB Output is correct
37 Correct 432 ms 17072 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 55 ms 3108 KB Output is correct
40 Correct 50 ms 3264 KB Output is correct
41 Correct 40 ms 3172 KB Output is correct
42 Correct 44 ms 3260 KB Output is correct
43 Correct 40 ms 3272 KB Output is correct
44 Correct 47 ms 3272 KB Output is correct
45 Correct 45 ms 3272 KB Output is correct
46 Correct 47 ms 3196 KB Output is correct
47 Correct 40 ms 3220 KB Output is correct
48 Correct 43 ms 3272 KB Output is correct
49 Correct 44 ms 3192 KB Output is correct
50 Correct 45 ms 3228 KB Output is correct
51 Correct 394 ms 17328 KB Output is correct
52 Correct 406 ms 17504 KB Output is correct
53 Correct 467 ms 17392 KB Output is correct
54 Correct 43 ms 3180 KB Output is correct
55 Correct 39 ms 3260 KB Output is correct
56 Correct 123 ms 8924 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 51 ms 3448 KB Output is correct
59 Correct 52 ms 3552 KB Output is correct
60 Correct 523 ms 17552 KB Output is correct
61 Correct 48 ms 3460 KB Output is correct
62 Correct 50 ms 3528 KB Output is correct
63 Correct 47 ms 3684 KB Output is correct
64 Correct 54 ms 3488 KB Output is correct
65 Correct 48 ms 3460 KB Output is correct
66 Correct 46 ms 3500 KB Output is correct
67 Correct 47 ms 3676 KB Output is correct
68 Correct 41 ms 3520 KB Output is correct
69 Correct 50 ms 3636 KB Output is correct
70 Correct 484 ms 16984 KB Output is correct
71 Correct 49 ms 3956 KB Output is correct
72 Correct 399 ms 17008 KB Output is correct
73 Correct 406 ms 17016 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 5 ms 984 KB Output is correct
80 Correct 557 ms 53260 KB Output is correct
81 Correct 516 ms 53124 KB Output is correct
82 Correct 493 ms 53180 KB Output is correct
83 Correct 491 ms 53248 KB Output is correct
84 Correct 468 ms 53260 KB Output is correct
85 Correct 500 ms 53208 KB Output is correct
86 Correct 135 ms 18436 KB Output is correct
87 Correct 1 ms 212 KB Output is correct