#include <bits/stdc++.h>
#define int long long
using namespace std;
set<int> s;
vector<pair<int,int>> v;
int g(int a,int b){
if(b==0) return a;
return g(b,a%b);
}
signed main()
{
ios::sync_with_stdio(0),cin.tie(0);
int n,a,b;
cin>>n>>a>>b;
int mod = (a*b)/g(a,b+1);
for(int i=1;i<=n;i++){
int x,y;
cin>>x>>y;
x%=mod;
y%=mod;
if(y>=x){
v.push_back({x,y});
}
else v.push_back({x,mod-1}),v.push_back({0,y});
}
sort(v.begin(),v.end());
int rr=-1,ans=0;
for(int i=0;i<v.size();i++){
int l=v[i].first;
int r=v[i].second;
if(l>rr){
ans+=(r-l+1);
rr=r;
}
else if(l<=rr&&r>rr){
ans+=(r-rr);
rr=r;
}
}
cout<<ans;
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:29: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]
29 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
728 KB |
Output is correct |
3 |
Correct |
5 ms |
728 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
320 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
728 KB |
Output is correct |
17 |
Correct |
45 ms |
2680 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
368 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
303 ms |
17104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
401 ms |
17072 KB |
Output is correct |
3 |
Correct |
455 ms |
17044 KB |
Output is correct |
4 |
Correct |
375 ms |
17392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
401 ms |
17072 KB |
Output is correct |
3 |
Correct |
455 ms |
17044 KB |
Output is correct |
4 |
Correct |
375 ms |
17392 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
376 ms |
17136 KB |
Output is correct |
7 |
Correct |
427 ms |
17196 KB |
Output is correct |
8 |
Correct |
384 ms |
17148 KB |
Output is correct |
9 |
Correct |
434 ms |
17164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
401 ms |
17072 KB |
Output is correct |
3 |
Correct |
455 ms |
17044 KB |
Output is correct |
4 |
Correct |
375 ms |
17392 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
41 ms |
2684 KB |
Output is correct |
7 |
Correct |
43 ms |
2688 KB |
Output is correct |
8 |
Correct |
42 ms |
2764 KB |
Output is correct |
9 |
Correct |
40 ms |
2772 KB |
Output is correct |
10 |
Correct |
48 ms |
2732 KB |
Output is correct |
11 |
Correct |
44 ms |
2876 KB |
Output is correct |
12 |
Correct |
49 ms |
2696 KB |
Output is correct |
13 |
Correct |
49 ms |
2864 KB |
Output is correct |
14 |
Correct |
39 ms |
2788 KB |
Output is correct |
15 |
Correct |
43 ms |
2760 KB |
Output is correct |
16 |
Correct |
54 ms |
2656 KB |
Output is correct |
17 |
Correct |
47 ms |
2756 KB |
Output is correct |
18 |
Correct |
412 ms |
17220 KB |
Output is correct |
19 |
Correct |
387 ms |
16992 KB |
Output is correct |
20 |
Correct |
429 ms |
17196 KB |
Output is correct |
21 |
Correct |
42 ms |
2696 KB |
Output is correct |
22 |
Correct |
46 ms |
2768 KB |
Output is correct |
23 |
Correct |
126 ms |
8984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
42 ms |
2668 KB |
Output is correct |
3 |
Correct |
42 ms |
2760 KB |
Output is correct |
4 |
Correct |
443 ms |
17376 KB |
Output is correct |
5 |
Correct |
53 ms |
2764 KB |
Output is correct |
6 |
Correct |
54 ms |
2708 KB |
Output is correct |
7 |
Correct |
49 ms |
2772 KB |
Output is correct |
8 |
Correct |
41 ms |
2768 KB |
Output is correct |
9 |
Correct |
44 ms |
2752 KB |
Output is correct |
10 |
Correct |
54 ms |
2740 KB |
Output is correct |
11 |
Correct |
48 ms |
2720 KB |
Output is correct |
12 |
Correct |
52 ms |
2772 KB |
Output is correct |
13 |
Correct |
45 ms |
2708 KB |
Output is correct |
14 |
Correct |
460 ms |
17148 KB |
Output is correct |
15 |
Correct |
51 ms |
2760 KB |
Output is correct |
16 |
Correct |
505 ms |
17192 KB |
Output is correct |
17 |
Correct |
449 ms |
17116 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
728 KB |
Output is correct |
3 |
Correct |
5 ms |
728 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
320 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
728 KB |
Output is correct |
17 |
Correct |
45 ms |
2680 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |