//Sylwia Sapkowska
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << "'" << x << "'";}
void __print(const char *x) {cerr << '"' << x << '"';}
void __print(const string &x) {cerr << '"' << x << '"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define int long long
typedef pair<int, int> T;
const int oo = 1e18, oo2 = 1e9+7, K = 30;
const int mod = 998244353;
#define ii __int128_t
void solve(){
int n, A, B; cin >> n >> A >> B;
//po obrzydliwych obliczeniach dostajemy ze co AB to sie powtarza + dziala na samplach
//jesli s \neq t mod AB, to daja rozne pary, nie wprost daja
//wiec musi s \equiv t mod B, ale wtedy s \neq t mod A (bo gdyby zachodzilo przystawanie, to mozna wymnozyc(?))
//czy to ze AB niekoniecznie wzglednie pierwsze przeszkadza w czyms?
//wiec wtedy pierwsza wartosc daje inna reszte
set<T>s;//przedzialy mod AB
ii CC = (ii)A*(ii)B/(ii)__gcd(A, B+1);
CC = min(CC, (ii)2*oo);
int C = CC;
for (int i = 0; i<n; i++){
int l, r; cin >> l >> r;
int L = l%C;
int R = r%C;
if (r-l+1 >= C) {
s.insert({0, C-1});
} else {
if (L <= R) s.insert({L, R});
else {
s.insert({L, C-1});
s.insert({0, R});
}
}
}
debug(s);
map<int, int>sweep;
for (auto [a, b]: s){
sweep[a]++;
sweep[b+1]--;
}
int prev = -1;
int open = 0, ans = 0;
for (auto [a, val]: sweep){
debug(a, val, open);
if (open) {
ans += a-prev;
}
open += val;
prev = a;
}
cout << ans << "\n";
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin >> t;
while (t--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
6 ms |
2004 KB |
Output is correct |
3 |
Correct |
6 ms |
1884 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
360 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
6 ms |
1884 KB |
Output is correct |
17 |
Correct |
66 ms |
16468 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
183 ms |
13140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
814 ms |
125692 KB |
Output is correct |
3 |
Correct |
863 ms |
125620 KB |
Output is correct |
4 |
Correct |
918 ms |
162892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
814 ms |
125692 KB |
Output is correct |
3 |
Correct |
863 ms |
125620 KB |
Output is correct |
4 |
Correct |
918 ms |
162892 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
985 ms |
162796 KB |
Output is correct |
7 |
Correct |
979 ms |
162796 KB |
Output is correct |
8 |
Correct |
924 ms |
162768 KB |
Output is correct |
9 |
Correct |
932 ms |
162904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
814 ms |
125692 KB |
Output is correct |
3 |
Correct |
863 ms |
125620 KB |
Output is correct |
4 |
Correct |
918 ms |
162892 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
70 ms |
16528 KB |
Output is correct |
7 |
Correct |
62 ms |
16588 KB |
Output is correct |
8 |
Correct |
68 ms |
16504 KB |
Output is correct |
9 |
Correct |
73 ms |
16464 KB |
Output is correct |
10 |
Correct |
63 ms |
16516 KB |
Output is correct |
11 |
Correct |
70 ms |
16468 KB |
Output is correct |
12 |
Correct |
62 ms |
16556 KB |
Output is correct |
13 |
Correct |
75 ms |
16620 KB |
Output is correct |
14 |
Correct |
73 ms |
16464 KB |
Output is correct |
15 |
Correct |
75 ms |
16464 KB |
Output is correct |
16 |
Correct |
70 ms |
16468 KB |
Output is correct |
17 |
Correct |
71 ms |
16724 KB |
Output is correct |
18 |
Correct |
952 ms |
162980 KB |
Output is correct |
19 |
Correct |
920 ms |
162908 KB |
Output is correct |
20 |
Correct |
934 ms |
162688 KB |
Output is correct |
21 |
Correct |
63 ms |
16440 KB |
Output is correct |
22 |
Correct |
62 ms |
16464 KB |
Output is correct |
23 |
Correct |
83 ms |
12828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
68 ms |
12800 KB |
Output is correct |
3 |
Correct |
65 ms |
12888 KB |
Output is correct |
4 |
Correct |
825 ms |
125716 KB |
Output is correct |
5 |
Correct |
69 ms |
12904 KB |
Output is correct |
6 |
Correct |
64 ms |
12880 KB |
Output is correct |
7 |
Correct |
65 ms |
12944 KB |
Output is correct |
8 |
Correct |
69 ms |
12884 KB |
Output is correct |
9 |
Correct |
66 ms |
12916 KB |
Output is correct |
10 |
Correct |
65 ms |
12884 KB |
Output is correct |
11 |
Correct |
72 ms |
12756 KB |
Output is correct |
12 |
Correct |
68 ms |
12880 KB |
Output is correct |
13 |
Correct |
66 ms |
12884 KB |
Output is correct |
14 |
Correct |
865 ms |
126152 KB |
Output is correct |
15 |
Correct |
59 ms |
12880 KB |
Output is correct |
16 |
Correct |
765 ms |
162940 KB |
Output is correct |
17 |
Correct |
894 ms |
162940 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
6 ms |
2004 KB |
Output is correct |
3 |
Correct |
6 ms |
1884 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
360 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
6 ms |
1884 KB |
Output is correct |
17 |
Correct |
66 ms |
16468 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
183 ms |
13140 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
814 ms |
125692 KB |
Output is correct |
31 |
Correct |
863 ms |
125620 KB |
Output is correct |
32 |
Correct |
918 ms |
162892 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
985 ms |
162796 KB |
Output is correct |
35 |
Correct |
979 ms |
162796 KB |
Output is correct |
36 |
Correct |
924 ms |
162768 KB |
Output is correct |
37 |
Correct |
932 ms |
162904 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
70 ms |
16528 KB |
Output is correct |
40 |
Correct |
62 ms |
16588 KB |
Output is correct |
41 |
Correct |
68 ms |
16504 KB |
Output is correct |
42 |
Correct |
73 ms |
16464 KB |
Output is correct |
43 |
Correct |
63 ms |
16516 KB |
Output is correct |
44 |
Correct |
70 ms |
16468 KB |
Output is correct |
45 |
Correct |
62 ms |
16556 KB |
Output is correct |
46 |
Correct |
75 ms |
16620 KB |
Output is correct |
47 |
Correct |
73 ms |
16464 KB |
Output is correct |
48 |
Correct |
75 ms |
16464 KB |
Output is correct |
49 |
Correct |
70 ms |
16468 KB |
Output is correct |
50 |
Correct |
71 ms |
16724 KB |
Output is correct |
51 |
Correct |
952 ms |
162980 KB |
Output is correct |
52 |
Correct |
920 ms |
162908 KB |
Output is correct |
53 |
Correct |
934 ms |
162688 KB |
Output is correct |
54 |
Correct |
63 ms |
16440 KB |
Output is correct |
55 |
Correct |
62 ms |
16464 KB |
Output is correct |
56 |
Correct |
83 ms |
12828 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
68 ms |
12800 KB |
Output is correct |
59 |
Correct |
65 ms |
12888 KB |
Output is correct |
60 |
Correct |
825 ms |
125716 KB |
Output is correct |
61 |
Correct |
69 ms |
12904 KB |
Output is correct |
62 |
Correct |
64 ms |
12880 KB |
Output is correct |
63 |
Correct |
65 ms |
12944 KB |
Output is correct |
64 |
Correct |
69 ms |
12884 KB |
Output is correct |
65 |
Correct |
66 ms |
12916 KB |
Output is correct |
66 |
Correct |
65 ms |
12884 KB |
Output is correct |
67 |
Correct |
72 ms |
12756 KB |
Output is correct |
68 |
Correct |
68 ms |
12880 KB |
Output is correct |
69 |
Correct |
66 ms |
12884 KB |
Output is correct |
70 |
Correct |
865 ms |
126152 KB |
Output is correct |
71 |
Correct |
59 ms |
12880 KB |
Output is correct |
72 |
Correct |
765 ms |
162940 KB |
Output is correct |
73 |
Correct |
894 ms |
162940 KB |
Output is correct |
74 |
Correct |
1 ms |
344 KB |
Output is correct |
75 |
Correct |
1 ms |
348 KB |
Output is correct |
76 |
Correct |
0 ms |
348 KB |
Output is correct |
77 |
Correct |
0 ms |
348 KB |
Output is correct |
78 |
Correct |
1 ms |
348 KB |
Output is correct |
79 |
Correct |
6 ms |
1880 KB |
Output is correct |
80 |
Correct |
983 ms |
162828 KB |
Output is correct |
81 |
Correct |
960 ms |
163008 KB |
Output is correct |
82 |
Correct |
946 ms |
162644 KB |
Output is correct |
83 |
Correct |
821 ms |
162984 KB |
Output is correct |
84 |
Correct |
794 ms |
162804 KB |
Output is correct |
85 |
Correct |
787 ms |
162932 KB |
Output is correct |
86 |
Correct |
83 ms |
13096 KB |
Output is correct |
87 |
Correct |
1 ms |
348 KB |
Output is correct |