#include <stdio.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ld long double
#define bug cout << "bug\n";
const ll maxn = 1e6 + 5, maxm = 2e2 + 1;
const ll mod = 1e9 + 7, inf = 1e9, block = 550, hb = 126067, base = 1000050017,
biginf = 5e18;
const ld eps = 1e-15;
using namespace std;
int n;
ll a, b;
ll l[maxn], r[maxn];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> a >> b;
a = a / gcd(a, b + 1);
ll p;
if (a > (ll)1e18 / b){
p = (ll)1e18;
}
else{
p = a * b;
}
vector<pair<ll, ll>> v;
for (int i = 1; i <= n; ++i){
cin >> l[i] >> r[i];
ll x = l[i] % p;
ll y = r[i] % p;
if (x <= y){
v.pb(mp(x, y));
}
else{
v.pb(mp(x, p - 1));
v.pb(mp(0, y));
}
}
sort(v.begin(), v.end());
ll ans = 0, nxt = -1;
for (auto it : v){
ll lf = it.f, rg = it.s;
if (nxt < lf){
ans += rg - lf + 1;
nxt = rg;
}
else if (nxt <= rg){
ans += rg - nxt;
nxt = rg;
}
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
1156 KB |
Output is correct |
3 |
Correct |
5 ms |
1224 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
1220 KB |
Output is correct |
17 |
Correct |
43 ms |
4432 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
380 KB |
Output is correct |
5 |
Correct |
294 ms |
33196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
407 ms |
32684 KB |
Output is correct |
3 |
Correct |
396 ms |
32820 KB |
Output is correct |
4 |
Correct |
376 ms |
32820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
407 ms |
32684 KB |
Output is correct |
3 |
Correct |
396 ms |
32820 KB |
Output is correct |
4 |
Correct |
376 ms |
32820 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
389 ms |
32712 KB |
Output is correct |
7 |
Correct |
400 ms |
32740 KB |
Output is correct |
8 |
Correct |
395 ms |
32712 KB |
Output is correct |
9 |
Correct |
434 ms |
32728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
407 ms |
32684 KB |
Output is correct |
3 |
Correct |
396 ms |
32820 KB |
Output is correct |
4 |
Correct |
376 ms |
32820 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
40 ms |
4452 KB |
Output is correct |
7 |
Correct |
43 ms |
4464 KB |
Output is correct |
8 |
Correct |
38 ms |
4440 KB |
Output is correct |
9 |
Correct |
39 ms |
4424 KB |
Output is correct |
10 |
Correct |
38 ms |
4412 KB |
Output is correct |
11 |
Correct |
40 ms |
4388 KB |
Output is correct |
12 |
Correct |
42 ms |
4540 KB |
Output is correct |
13 |
Correct |
46 ms |
4548 KB |
Output is correct |
14 |
Correct |
41 ms |
4424 KB |
Output is correct |
15 |
Correct |
43 ms |
4420 KB |
Output is correct |
16 |
Correct |
45 ms |
4428 KB |
Output is correct |
17 |
Correct |
42 ms |
4332 KB |
Output is correct |
18 |
Correct |
415 ms |
32452 KB |
Output is correct |
19 |
Correct |
414 ms |
32152 KB |
Output is correct |
20 |
Correct |
424 ms |
32220 KB |
Output is correct |
21 |
Correct |
47 ms |
3892 KB |
Output is correct |
22 |
Correct |
36 ms |
3916 KB |
Output is correct |
23 |
Correct |
129 ms |
13696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
45 ms |
4440 KB |
Output is correct |
3 |
Correct |
50 ms |
4404 KB |
Output is correct |
4 |
Correct |
464 ms |
32648 KB |
Output is correct |
5 |
Correct |
43 ms |
3948 KB |
Output is correct |
6 |
Correct |
41 ms |
3928 KB |
Output is correct |
7 |
Correct |
40 ms |
3980 KB |
Output is correct |
8 |
Correct |
46 ms |
3972 KB |
Output is correct |
9 |
Correct |
45 ms |
3992 KB |
Output is correct |
10 |
Correct |
40 ms |
3656 KB |
Output is correct |
11 |
Correct |
42 ms |
3676 KB |
Output is correct |
12 |
Correct |
35 ms |
3628 KB |
Output is correct |
13 |
Correct |
41 ms |
3720 KB |
Output is correct |
14 |
Correct |
432 ms |
31960 KB |
Output is correct |
15 |
Correct |
42 ms |
3660 KB |
Output is correct |
16 |
Correct |
389 ms |
31964 KB |
Output is correct |
17 |
Correct |
388 ms |
31956 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
1156 KB |
Output is correct |
3 |
Correct |
5 ms |
1224 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
1220 KB |
Output is correct |
17 |
Correct |
43 ms |
4432 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |