#define LOCAL
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define db 0
#define EPS (1e-7) //0.0000001 the value
#define PI (acos((ld)-1.0))
#define MAXN (1000006)
#define ll long long int
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = (ss); ii < (ll)(ee); ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll((x))
#define MSB(bm) ((bm==0)?-1:(63-__builtin_clzll((bm))))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;}string to_string(bool b){return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void degug_out() { cerr << endl; }template <typename Head, typename... Tail>void degug_out(Head H, Tail... T) {cerr << " " << to_string(H);degug_out(T...);}inline ll gcd(ll a,ll b){if(a>b)swap(a,b);if(a==0)return b;return gcd(b%a,a);}
#ifdef LOCAL
// #define degug(...) cerr << "[" << #__VA_ARGS__ << "]:", degug_out(__VA_ARGS__)
#else
// #define degug(...) 663
#define cerr if(0)cout
#endif
ll n,A,B;
pi E[MAXN];
ll limit=1e18+5;
ll qmult(ll x,ll e) {
if(e==0)return 0;
ll half=qmult(x,e/2);
half+=half; half=min(half,limit);
if(e&1) half+=x; half=min(half,limit);
return half;
}
int main()
{
FAST
cin>>n>>A>>B;
ll p=qmult(A/gcd(A,B+1),B);
FOR(i,0,n) cin>>E[i].f>>E[i].s; FOR(i,0,n) if(E[i].s-E[i].f+1>=p) { cout<<p<<'\n'; return 0; }
vector<pi>pay;
FOR(i,0,n) { ll a=E[i].f%p,b=E[i].s%p;
if(a>b) pay.eb(a,p-1),pay.eb(0,b);
else pay.eb(a,b);
}
sort(all(pay));
ll px=-1; ll ans=0;
for(auto i:pay) {
if(px>=i.f) ans+=max(0ll,i.s-px);
else ans+=i.s-i.f+1;
px=max(px,i.s);
}
cout<<ans<<'\n';
}
Compilation message
strange_device.cpp: In function 'long long int qmult(long long int, long long int)':
strange_device.cpp:48:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(e&1) half+=x; half=min(half,limit);
^~
strange_device.cpp:48:19: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if(e&1) half+=x; half=min(half,limit);
^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
424 KB |
Output is correct |
2 |
Correct |
10 ms |
1272 KB |
Output is correct |
3 |
Correct |
9 ms |
1272 KB |
Output is correct |
4 |
Correct |
2 ms |
292 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
352 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
1 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
504 KB |
Output is correct |
16 |
Correct |
8 ms |
1276 KB |
Output is correct |
17 |
Correct |
70 ms |
5564 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
276 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
476 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
476 KB |
Output is correct |
5 |
Correct |
464 ms |
33476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
292 KB |
Output is correct |
2 |
Correct |
637 ms |
33628 KB |
Output is correct |
3 |
Correct |
628 ms |
33136 KB |
Output is correct |
4 |
Correct |
613 ms |
33020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
292 KB |
Output is correct |
2 |
Correct |
637 ms |
33628 KB |
Output is correct |
3 |
Correct |
628 ms |
33136 KB |
Output is correct |
4 |
Correct |
613 ms |
33020 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
617 ms |
33040 KB |
Output is correct |
7 |
Correct |
632 ms |
33360 KB |
Output is correct |
8 |
Correct |
613 ms |
33400 KB |
Output is correct |
9 |
Correct |
681 ms |
33668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
292 KB |
Output is correct |
2 |
Correct |
637 ms |
33628 KB |
Output is correct |
3 |
Correct |
628 ms |
33136 KB |
Output is correct |
4 |
Correct |
613 ms |
33020 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
62 ms |
5972 KB |
Output is correct |
7 |
Correct |
67 ms |
5788 KB |
Output is correct |
8 |
Correct |
65 ms |
5768 KB |
Output is correct |
9 |
Correct |
65 ms |
5692 KB |
Output is correct |
10 |
Correct |
62 ms |
5360 KB |
Output is correct |
11 |
Correct |
65 ms |
5360 KB |
Output is correct |
12 |
Correct |
62 ms |
5428 KB |
Output is correct |
13 |
Correct |
71 ms |
5356 KB |
Output is correct |
14 |
Correct |
62 ms |
5360 KB |
Output is correct |
15 |
Correct |
71 ms |
5736 KB |
Output is correct |
16 |
Correct |
69 ms |
5868 KB |
Output is correct |
17 |
Correct |
65 ms |
5716 KB |
Output is correct |
18 |
Correct |
630 ms |
33300 KB |
Output is correct |
19 |
Correct |
605 ms |
33236 KB |
Output is correct |
20 |
Correct |
696 ms |
33428 KB |
Output is correct |
21 |
Correct |
72 ms |
6388 KB |
Output is correct |
22 |
Correct |
63 ms |
5632 KB |
Output is correct |
23 |
Correct |
204 ms |
18600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
69 ms |
5600 KB |
Output is correct |
3 |
Correct |
67 ms |
5232 KB |
Output is correct |
4 |
Correct |
706 ms |
33312 KB |
Output is correct |
5 |
Correct |
69 ms |
5296 KB |
Output is correct |
6 |
Correct |
73 ms |
5256 KB |
Output is correct |
7 |
Correct |
70 ms |
5368 KB |
Output is correct |
8 |
Correct |
70 ms |
5308 KB |
Output is correct |
9 |
Correct |
66 ms |
5272 KB |
Output is correct |
10 |
Correct |
67 ms |
5232 KB |
Output is correct |
11 |
Correct |
68 ms |
5484 KB |
Output is correct |
12 |
Correct |
64 ms |
5456 KB |
Output is correct |
13 |
Correct |
72 ms |
5484 KB |
Output is correct |
14 |
Correct |
689 ms |
33392 KB |
Output is correct |
15 |
Correct |
67 ms |
5912 KB |
Output is correct |
16 |
Correct |
614 ms |
33268 KB |
Output is correct |
17 |
Correct |
605 ms |
33380 KB |
Output is correct |
18 |
Correct |
2 ms |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
424 KB |
Output is correct |
2 |
Correct |
10 ms |
1272 KB |
Output is correct |
3 |
Correct |
9 ms |
1272 KB |
Output is correct |
4 |
Correct |
2 ms |
292 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
352 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
1 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
504 KB |
Output is correct |
16 |
Correct |
8 ms |
1276 KB |
Output is correct |
17 |
Correct |
70 ms |
5564 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
276 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
476 KB |
Output is correct |
26 |
Correct |
3 ms |
504 KB |
Output is correct |
27 |
Correct |
3 ms |
476 KB |
Output is correct |
28 |
Correct |
464 ms |
33476 KB |
Output is correct |
29 |
Correct |
2 ms |
292 KB |
Output is correct |
30 |
Correct |
637 ms |
33628 KB |
Output is correct |
31 |
Correct |
628 ms |
33136 KB |
Output is correct |
32 |
Correct |
613 ms |
33020 KB |
Output is correct |
33 |
Correct |
2 ms |
348 KB |
Output is correct |
34 |
Correct |
617 ms |
33040 KB |
Output is correct |
35 |
Correct |
632 ms |
33360 KB |
Output is correct |
36 |
Correct |
613 ms |
33400 KB |
Output is correct |
37 |
Correct |
681 ms |
33668 KB |
Output is correct |
38 |
Correct |
3 ms |
376 KB |
Output is correct |
39 |
Correct |
62 ms |
5972 KB |
Output is correct |
40 |
Correct |
67 ms |
5788 KB |
Output is correct |
41 |
Correct |
65 ms |
5768 KB |
Output is correct |
42 |
Correct |
65 ms |
5692 KB |
Output is correct |
43 |
Correct |
62 ms |
5360 KB |
Output is correct |
44 |
Correct |
65 ms |
5360 KB |
Output is correct |
45 |
Correct |
62 ms |
5428 KB |
Output is correct |
46 |
Correct |
71 ms |
5356 KB |
Output is correct |
47 |
Correct |
62 ms |
5360 KB |
Output is correct |
48 |
Correct |
71 ms |
5736 KB |
Output is correct |
49 |
Correct |
69 ms |
5868 KB |
Output is correct |
50 |
Correct |
65 ms |
5716 KB |
Output is correct |
51 |
Correct |
630 ms |
33300 KB |
Output is correct |
52 |
Correct |
605 ms |
33236 KB |
Output is correct |
53 |
Correct |
696 ms |
33428 KB |
Output is correct |
54 |
Correct |
72 ms |
6388 KB |
Output is correct |
55 |
Correct |
63 ms |
5632 KB |
Output is correct |
56 |
Correct |
204 ms |
18600 KB |
Output is correct |
57 |
Correct |
2 ms |
376 KB |
Output is correct |
58 |
Correct |
69 ms |
5600 KB |
Output is correct |
59 |
Correct |
67 ms |
5232 KB |
Output is correct |
60 |
Correct |
706 ms |
33312 KB |
Output is correct |
61 |
Correct |
69 ms |
5296 KB |
Output is correct |
62 |
Correct |
73 ms |
5256 KB |
Output is correct |
63 |
Correct |
70 ms |
5368 KB |
Output is correct |
64 |
Correct |
70 ms |
5308 KB |
Output is correct |
65 |
Correct |
66 ms |
5272 KB |
Output is correct |
66 |
Correct |
67 ms |
5232 KB |
Output is correct |
67 |
Correct |
68 ms |
5484 KB |
Output is correct |
68 |
Correct |
64 ms |
5456 KB |
Output is correct |
69 |
Correct |
72 ms |
5484 KB |
Output is correct |
70 |
Correct |
689 ms |
33392 KB |
Output is correct |
71 |
Correct |
67 ms |
5912 KB |
Output is correct |
72 |
Correct |
614 ms |
33268 KB |
Output is correct |
73 |
Correct |
605 ms |
33380 KB |
Output is correct |
74 |
Correct |
2 ms |
380 KB |
Output is correct |
75 |
Correct |
2 ms |
376 KB |
Output is correct |
76 |
Correct |
0 ms |
376 KB |
Output is correct |
77 |
Correct |
2 ms |
376 KB |
Output is correct |
78 |
Correct |
2 ms |
376 KB |
Output is correct |
79 |
Correct |
9 ms |
1272 KB |
Output is correct |
80 |
Correct |
707 ms |
33976 KB |
Output is correct |
81 |
Correct |
706 ms |
34040 KB |
Output is correct |
82 |
Correct |
674 ms |
34156 KB |
Output is correct |
83 |
Correct |
669 ms |
33992 KB |
Output is correct |
84 |
Correct |
727 ms |
34256 KB |
Output is correct |
85 |
Correct |
688 ms |
34056 KB |
Output is correct |
86 |
Correct |
194 ms |
16488 KB |
Output is correct |
87 |
Correct |
2 ms |
376 KB |
Output is correct |