#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
ll n, a, b;
ll mod;
cin >> n >> a >> b;
for(ll i = 1;;++i){
if((b*i+i)%a == 0 || b*i > 1e18){
mod = b*i;
break;
}
}
vector<pll> seg;
for(ll i = 0; i < n; ++i){
pll tmp;
cin >> tmp.ff >> tmp.ss;
if(tmp.ss - tmp.ff + 1 >= mod){
cout << mod << '\n';
return 0;
}
tmp.ff %= mod;
tmp.ss %= mod;
//cout << i << ' ' << tmp.ff << ' ' << tmp.ss << '\n';
if(tmp.ss >= tmp.ff)
seg.pb({tmp.ff, tmp.ss});
else{
seg.pb({tmp.ff, mod-1});
seg.pb({0, tmp.ss});
}
}
//for(auto u : seg)
// cout << u.ff << ' ' << u.ss << '\n';
sort(seg.begin(), seg.end());
vector<pll> v;
for(auto u : seg){
//cout << u.ff << ' ' << u.ss << '\n';
if(!v.empty() && v.back().ss >= u.ff)
v.back().ss = max(v.back().ss, u.ss);
else
v.pb(u);
}
ll ans = 0;
for(auto u : v){
ans += u.ss-u.ff+1;
//cout << u.ff << ' ' << u.ss << '\n';
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
10 ms |
1276 KB |
Output is correct |
3 |
Correct |
11 ms |
1272 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
10 ms |
1276 KB |
Output is correct |
17 |
Correct |
65 ms |
5480 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
556 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
391 ms |
22100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
552 ms |
41412 KB |
Output is correct |
3 |
Execution timed out |
5047 ms |
376 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
552 ms |
41412 KB |
Output is correct |
3 |
Execution timed out |
5047 ms |
376 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
552 ms |
41412 KB |
Output is correct |
3 |
Execution timed out |
5047 ms |
376 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
63 ms |
8752 KB |
Output is correct |
3 |
Correct |
71 ms |
8684 KB |
Output is correct |
4 |
Correct |
666 ms |
69776 KB |
Output is correct |
5 |
Correct |
87 ms |
8680 KB |
Output is correct |
6 |
Correct |
79 ms |
8676 KB |
Output is correct |
7 |
Correct |
80 ms |
8684 KB |
Output is correct |
8 |
Correct |
91 ms |
8684 KB |
Output is correct |
9 |
Correct |
78 ms |
8660 KB |
Output is correct |
10 |
Correct |
64 ms |
8684 KB |
Output is correct |
11 |
Correct |
79 ms |
8680 KB |
Output is correct |
12 |
Correct |
71 ms |
8680 KB |
Output is correct |
13 |
Correct |
106 ms |
8680 KB |
Output is correct |
14 |
Correct |
599 ms |
69840 KB |
Output is correct |
15 |
Correct |
80 ms |
8680 KB |
Output is correct |
16 |
Correct |
562 ms |
66112 KB |
Output is correct |
17 |
Correct |
559 ms |
68036 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
10 ms |
1276 KB |
Output is correct |
3 |
Correct |
11 ms |
1272 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
10 ms |
1276 KB |
Output is correct |
17 |
Correct |
65 ms |
5480 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
6 ms |
376 KB |
Output is correct |
24 |
Correct |
6 ms |
376 KB |
Output is correct |
25 |
Correct |
6 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
556 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
391 ms |
22100 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
552 ms |
41412 KB |
Output is correct |
31 |
Execution timed out |
5047 ms |
376 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |