//# pragma GCC optimize("Ofast,no-stack-protector")
//# pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
# pragma GCC optimize("Ofast")
# pragma GCC optimization ("unroll-loops")
# include "bits/stdc++.h"
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
# define int ll
using namespace std;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# define LOCAL
# define sim template < class c
# define ris return * this
# define dor > debug & operator <<
# define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define show(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int gcd(int a, int b)
{
if(b) return gcd(b,a%b);
return a;
}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bool B = 1;
int n,a,b,l[1 << 20],r[1 << 20],cnt,ans;
map<int,int>m;
int32_t main(){_
//freopen("input","r",stdin);
cin >> n >> a >> b;
a /= gcd(a,b + 1);
int BIGSHAQ = 1e18;
if(BIGSHAQ / a < b) B = 0;
else a *= b;
for(int i = 1;i <= n;i++)
{
cin >> l[i] >> r[i];
cnt += r[i] - l[i] + 1;
}
if(!B) rc(cnt);
for(int i = 1;i <= n;i++)
{
if(r[i] - l[i] + 1 >= a) rc(a);
r[i] %= a;
l[i] %= a;
if(r[i] < l[i])
{
m[l[i]]++;
m[a]--;
m[0]++;
m[r[i] + 1]--;
}
else
{
m[l[i]]++;
m[r[i] + 1]--;
}
}
int lstr = 0;
int x = 0;
ans = a;
for(auto it : m)
{
if(x == 0) ans -= it.first - lstr;
x += it.second;
if(x == 0) lstr = it.first;
}
if(x == 0) ans -= a - lstr;
rc(ans);
return 0;
}
Compilation message
strange_device.cpp:4:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
# pragma GCC optimization ("unroll-loops")
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
10 ms |
1144 KB |
Output is correct |
3 |
Correct |
11 ms |
1144 KB |
Output is correct |
4 |
Correct |
2 ms |
348 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 |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
10 ms |
1144 KB |
Output is correct |
17 |
Correct |
102 ms |
8228 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 |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 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 |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
418 ms |
17224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
1063 ms |
79508 KB |
Output is correct |
3 |
Correct |
1131 ms |
79304 KB |
Output is correct |
4 |
Correct |
1204 ms |
79468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
1063 ms |
79508 KB |
Output is correct |
3 |
Correct |
1131 ms |
79304 KB |
Output is correct |
4 |
Correct |
1204 ms |
79468 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
1124 ms |
79392 KB |
Output is correct |
7 |
Correct |
1143 ms |
79432 KB |
Output is correct |
8 |
Correct |
1126 ms |
79484 KB |
Output is correct |
9 |
Correct |
1229 ms |
79384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
1063 ms |
79508 KB |
Output is correct |
3 |
Correct |
1131 ms |
79304 KB |
Output is correct |
4 |
Correct |
1204 ms |
79468 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
87 ms |
10284 KB |
Output is correct |
7 |
Correct |
88 ms |
9860 KB |
Output is correct |
8 |
Correct |
94 ms |
9824 KB |
Output is correct |
9 |
Correct |
113 ms |
9788 KB |
Output is correct |
10 |
Correct |
92 ms |
9776 KB |
Output is correct |
11 |
Correct |
90 ms |
9432 KB |
Output is correct |
12 |
Correct |
97 ms |
9600 KB |
Output is correct |
13 |
Correct |
114 ms |
9464 KB |
Output is correct |
14 |
Correct |
88 ms |
9476 KB |
Output is correct |
15 |
Correct |
111 ms |
9452 KB |
Output is correct |
16 |
Correct |
111 ms |
9464 KB |
Output is correct |
17 |
Correct |
106 ms |
9792 KB |
Output is correct |
18 |
Correct |
1072 ms |
79272 KB |
Output is correct |
19 |
Correct |
1165 ms |
79396 KB |
Output is correct |
20 |
Correct |
1207 ms |
79372 KB |
Output is correct |
21 |
Correct |
96 ms |
10104 KB |
Output is correct |
22 |
Correct |
99 ms |
10232 KB |
Output is correct |
23 |
Correct |
183 ms |
7916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
111 ms |
9788 KB |
Output is correct |
3 |
Correct |
115 ms |
10160 KB |
Output is correct |
4 |
Correct |
1171 ms |
79400 KB |
Output is correct |
5 |
Correct |
110 ms |
9880 KB |
Output is correct |
6 |
Correct |
111 ms |
9836 KB |
Output is correct |
7 |
Correct |
109 ms |
9848 KB |
Output is correct |
8 |
Correct |
110 ms |
10160 KB |
Output is correct |
9 |
Correct |
107 ms |
10076 KB |
Output is correct |
10 |
Correct |
98 ms |
10072 KB |
Output is correct |
11 |
Correct |
103 ms |
10104 KB |
Output is correct |
12 |
Correct |
102 ms |
10076 KB |
Output is correct |
13 |
Correct |
112 ms |
10076 KB |
Output is correct |
14 |
Correct |
1260 ms |
79364 KB |
Output is correct |
15 |
Correct |
92 ms |
10180 KB |
Output is correct |
16 |
Correct |
1078 ms |
79432 KB |
Output is correct |
17 |
Correct |
1074 ms |
79440 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 |
10 ms |
1144 KB |
Output is correct |
3 |
Correct |
11 ms |
1144 KB |
Output is correct |
4 |
Correct |
2 ms |
348 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 |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
10 ms |
1144 KB |
Output is correct |
17 |
Correct |
102 ms |
8228 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 |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
376 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 |
504 KB |
Output is correct |
26 |
Correct |
3 ms |
504 KB |
Output is correct |
27 |
Correct |
3 ms |
504 KB |
Output is correct |
28 |
Correct |
418 ms |
17224 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
1063 ms |
79508 KB |
Output is correct |
31 |
Correct |
1131 ms |
79304 KB |
Output is correct |
32 |
Correct |
1204 ms |
79468 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
1124 ms |
79392 KB |
Output is correct |
35 |
Correct |
1143 ms |
79432 KB |
Output is correct |
36 |
Correct |
1126 ms |
79484 KB |
Output is correct |
37 |
Correct |
1229 ms |
79384 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
87 ms |
10284 KB |
Output is correct |
40 |
Correct |
88 ms |
9860 KB |
Output is correct |
41 |
Correct |
94 ms |
9824 KB |
Output is correct |
42 |
Correct |
113 ms |
9788 KB |
Output is correct |
43 |
Correct |
92 ms |
9776 KB |
Output is correct |
44 |
Correct |
90 ms |
9432 KB |
Output is correct |
45 |
Correct |
97 ms |
9600 KB |
Output is correct |
46 |
Correct |
114 ms |
9464 KB |
Output is correct |
47 |
Correct |
88 ms |
9476 KB |
Output is correct |
48 |
Correct |
111 ms |
9452 KB |
Output is correct |
49 |
Correct |
111 ms |
9464 KB |
Output is correct |
50 |
Correct |
106 ms |
9792 KB |
Output is correct |
51 |
Correct |
1072 ms |
79272 KB |
Output is correct |
52 |
Correct |
1165 ms |
79396 KB |
Output is correct |
53 |
Correct |
1207 ms |
79372 KB |
Output is correct |
54 |
Correct |
96 ms |
10104 KB |
Output is correct |
55 |
Correct |
99 ms |
10232 KB |
Output is correct |
56 |
Correct |
183 ms |
7916 KB |
Output is correct |
57 |
Correct |
2 ms |
376 KB |
Output is correct |
58 |
Correct |
111 ms |
9788 KB |
Output is correct |
59 |
Correct |
115 ms |
10160 KB |
Output is correct |
60 |
Correct |
1171 ms |
79400 KB |
Output is correct |
61 |
Correct |
110 ms |
9880 KB |
Output is correct |
62 |
Correct |
111 ms |
9836 KB |
Output is correct |
63 |
Correct |
109 ms |
9848 KB |
Output is correct |
64 |
Correct |
110 ms |
10160 KB |
Output is correct |
65 |
Correct |
107 ms |
10076 KB |
Output is correct |
66 |
Correct |
98 ms |
10072 KB |
Output is correct |
67 |
Correct |
103 ms |
10104 KB |
Output is correct |
68 |
Correct |
102 ms |
10076 KB |
Output is correct |
69 |
Correct |
112 ms |
10076 KB |
Output is correct |
70 |
Correct |
1260 ms |
79364 KB |
Output is correct |
71 |
Correct |
92 ms |
10180 KB |
Output is correct |
72 |
Correct |
1078 ms |
79432 KB |
Output is correct |
73 |
Correct |
1074 ms |
79440 KB |
Output is correct |
74 |
Correct |
2 ms |
376 KB |
Output is correct |
75 |
Correct |
2 ms |
376 KB |
Output is correct |
76 |
Correct |
2 ms |
376 KB |
Output is correct |
77 |
Correct |
3 ms |
376 KB |
Output is correct |
78 |
Correct |
2 ms |
380 KB |
Output is correct |
79 |
Correct |
11 ms |
1496 KB |
Output is correct |
80 |
Correct |
1213 ms |
79496 KB |
Output is correct |
81 |
Correct |
1166 ms |
79412 KB |
Output is correct |
82 |
Correct |
1239 ms |
79468 KB |
Output is correct |
83 |
Correct |
1222 ms |
79440 KB |
Output is correct |
84 |
Correct |
1276 ms |
79424 KB |
Output is correct |
85 |
Correct |
1205 ms |
79456 KB |
Output is correct |
86 |
Correct |
183 ms |
9352 KB |
Output is correct |
87 |
Correct |
2 ms |
376 KB |
Output is correct |