#include <bits/stdc++.h>
#define stop system("pause")
#define INP freopen("promote.in","r",stdin)
#define OUTP freopen("promote.out","w",stdout)
#pragma GCC optimize ("O3")
#define int long long
using namespace std;
bool check(int x){
return x != -1;
}
map<int,int> qwe;
main()
{
ios_base::sync_with_stdio(0);
int n,a,b; cin >> n >> a >> b;
int lcm;
double kek = a*b;
if(kek >= 1e18)lcm = 1e18;
else lcm = a*b;
vector<pair<int,int> > v;
int res = 0;
for(int i(0); i < n;i++){
int l,r; cin >> l >> r;
l%=lcm;
r%=lcm;
if(l <= r)v.push_back({l,r});
else{
if(check(lcm-1))v.push_back({l,lcm-1});
v.push_back({0,r});
}
}
sort(v.begin(),v.end());
int ans = 0;
int lastx,lasty; lastx = lasty = -1;
for(int i(0); i < v.size();i++){
//cout << "q " << v[i].first << ' ' << v[i].second << endl;
int nx,ny;
nx = max(lasty+1,v[i].first);
ny = max(lasty,v[i].second);
if(nx >= lcm)continue;
ans+=ny-nx+1;
lastx = nx;
lasty = ny;
}
cout << ans;
return 0;
}
/*
15 500 13 18
*/
Compilation message
strange_device.cpp:16:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main()
^
strange_device.cpp: In function 'int main()':
strange_device.cpp:39:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i(0); i < v.size();i++){
~~^~~~~~~~~~
strange_device.cpp:25:9: warning: unused variable 'res' [-Wunused-variable]
int res = 0;
^~~
strange_device.cpp:38:9: warning: variable 'lastx' set but not used [-Wunused-but-set-variable]
int lastx,lasty; lastx = lasty = -1;
^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
348 KB |
Output is correct |
2 |
Correct |
8 ms |
1120 KB |
Output is correct |
3 |
Correct |
9 ms |
1052 KB |
Output is correct |
4 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
380 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
471 ms |
17684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
627 ms |
18052 KB |
Output is correct |
3 |
Incorrect |
631 ms |
17492 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
627 ms |
18052 KB |
Output is correct |
3 |
Incorrect |
631 ms |
17492 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
627 ms |
18052 KB |
Output is correct |
3 |
Incorrect |
631 ms |
17492 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
70 ms |
3076 KB |
Output is correct |
3 |
Correct |
66 ms |
3056 KB |
Output is correct |
4 |
Correct |
709 ms |
17288 KB |
Output is correct |
5 |
Correct |
69 ms |
2932 KB |
Output is correct |
6 |
Correct |
69 ms |
2928 KB |
Output is correct |
7 |
Correct |
68 ms |
2800 KB |
Output is correct |
8 |
Correct |
70 ms |
2764 KB |
Output is correct |
9 |
Correct |
68 ms |
2876 KB |
Output is correct |
10 |
Correct |
68 ms |
2800 KB |
Output is correct |
11 |
Correct |
68 ms |
3180 KB |
Output is correct |
12 |
Correct |
62 ms |
3056 KB |
Output is correct |
13 |
Correct |
70 ms |
3176 KB |
Output is correct |
14 |
Correct |
688 ms |
17240 KB |
Output is correct |
15 |
Incorrect |
70 ms |
3312 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
348 KB |
Output is correct |
2 |
Correct |
8 ms |
1120 KB |
Output is correct |
3 |
Correct |
9 ms |
1052 KB |
Output is correct |
4 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |