#include <bits/stdc++.h>
using namespace std;
#define v vector
#define int long long
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define ff first
#define ss second
#define inp_v(vec) for (auto &i : vec) cin >> i;
#define prt_v(vec) for (auto i : vec) cout << i << endl;
#define MS(x) memset(x, 0, sizeof(x))
#define gcd(a,b) __gcd(a, b);
#define lcm(a,b) (a*(b/gcd(a,b)))
#define lb lower_bound
#define ub upper_bound
bool chmin(int &a, int b){return b<a?a=b, true:false;}
bool chmax(int &a, int b){return b>a?a=b, true:false;}
// bool comp(const pair<int, int>&a, const pair<int int>&b){
// return a.second<b.second;
// }
signed main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int N, a, b;cin>>N>>a>>b;
double cycles=a/(__gcd(a, b+1))*b;
int cycle=(int)cycles;
vector<pair<int, int>>segment;
vector<pair<int, int>>seg;
bool flag=false;
for(int i=0;i<N;i++){
int x, y;cin>>x>>y;
if(y-x+1>=cycle){
flag=true;
}
if(y>=cycle){
// cout<<i<<" "<<x<<" "<<cycle<<" "<<y%cycle<<endl;
if(x>=cycle){
if(y/cycle>x/cycle){
segment.push_back({x%cycle, cycle-1});
segment.push_back({0, y%cycle});
}
else segment.push_back({x%cycle, y%cycle});
// segment.push_back({0, y%cycle});
}
else{
segment.push_back({x, cycle-1});
segment.push_back({0, y%cycle});
}
}
else{
segment.push_back({x, y});
}
}
sort(segment.begin(), segment.end());
int curl=-1, curr=-1;
int ans=0;
// cout<<cycle<<endl;
for(int i=0;i<segment.size();i++){
// cout<<segment[i].first<<" "<<segment[i].second<<endl;
if(curr>segment[i].second){
continue;
}
else{
curl=max(curr+1, segment[i].first);
curr=segment[i].second;
ans+=curr-curl+1;
}
}
if(flag)cout<<cycle<<endl;
else cout<<ans<<endl;
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:60:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for(int i=0;i<segment.size();i++){
| ~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
600 KB |
Output is correct |
3 |
Correct |
5 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 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 |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
600 KB |
Output is correct |
17 |
Correct |
32 ms |
2444 KB |
Output is correct |
18 |
Incorrect |
0 ms |
224 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
340 KB |
Output is correct |
5 |
Correct |
208 ms |
16856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
310 ms |
16788 KB |
Output is correct |
3 |
Correct |
297 ms |
17248 KB |
Output is correct |
4 |
Correct |
309 ms |
17224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
310 ms |
16788 KB |
Output is correct |
3 |
Correct |
297 ms |
17248 KB |
Output is correct |
4 |
Correct |
309 ms |
17224 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
296 ms |
17228 KB |
Output is correct |
7 |
Correct |
300 ms |
17204 KB |
Output is correct |
8 |
Correct |
314 ms |
17244 KB |
Output is correct |
9 |
Correct |
322 ms |
17280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
310 ms |
16788 KB |
Output is correct |
3 |
Correct |
297 ms |
17248 KB |
Output is correct |
4 |
Correct |
309 ms |
17224 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
29 ms |
2792 KB |
Output is correct |
7 |
Correct |
33 ms |
2700 KB |
Output is correct |
8 |
Correct |
30 ms |
2688 KB |
Output is correct |
9 |
Correct |
31 ms |
2640 KB |
Output is correct |
10 |
Correct |
29 ms |
2744 KB |
Output is correct |
11 |
Correct |
32 ms |
2664 KB |
Output is correct |
12 |
Correct |
30 ms |
2628 KB |
Output is correct |
13 |
Correct |
31 ms |
2644 KB |
Output is correct |
14 |
Correct |
29 ms |
2612 KB |
Output is correct |
15 |
Correct |
34 ms |
2716 KB |
Output is correct |
16 |
Correct |
34 ms |
2744 KB |
Output is correct |
17 |
Correct |
31 ms |
2760 KB |
Output is correct |
18 |
Correct |
302 ms |
17180 KB |
Output is correct |
19 |
Correct |
291 ms |
17088 KB |
Output is correct |
20 |
Correct |
330 ms |
17168 KB |
Output is correct |
21 |
Correct |
32 ms |
2736 KB |
Output is correct |
22 |
Correct |
29 ms |
2764 KB |
Output is correct |
23 |
Correct |
93 ms |
8956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
39 ms |
3088 KB |
Output is correct |
3 |
Correct |
35 ms |
2860 KB |
Output is correct |
4 |
Correct |
369 ms |
17164 KB |
Output is correct |
5 |
Correct |
32 ms |
2612 KB |
Output is correct |
6 |
Correct |
33 ms |
2708 KB |
Output is correct |
7 |
Correct |
32 ms |
2772 KB |
Output is correct |
8 |
Correct |
38 ms |
2692 KB |
Output is correct |
9 |
Correct |
32 ms |
2740 KB |
Output is correct |
10 |
Correct |
32 ms |
2760 KB |
Output is correct |
11 |
Correct |
35 ms |
2808 KB |
Output is correct |
12 |
Correct |
34 ms |
2756 KB |
Output is correct |
13 |
Correct |
37 ms |
2724 KB |
Output is correct |
14 |
Correct |
329 ms |
17068 KB |
Output is correct |
15 |
Correct |
34 ms |
2888 KB |
Output is correct |
16 |
Correct |
303 ms |
17076 KB |
Output is correct |
17 |
Correct |
316 ms |
17236 KB |
Output is correct |
18 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
600 KB |
Output is correct |
3 |
Correct |
5 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 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 |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
600 KB |
Output is correct |
17 |
Correct |
32 ms |
2444 KB |
Output is correct |
18 |
Incorrect |
0 ms |
224 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |