#include <bits/stdc++.h>
#define int long long
using namespace std;
set<int> s;
vector<pair<int,int>> v;
signed main()
{
ios::sync_with_stdio(0),cin.tie(0);
int n,a,b;
cin>>n>>a>>b;
int mod = (a*b)/__gcd<long long>(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:25: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]
25 | 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 |
4 ms |
984 KB |
Output is correct |
3 |
Correct |
5 ms |
976 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 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 |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
288 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 |
1056 KB |
Output is correct |
17 |
Correct |
47 ms |
2944 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 |
Incorrect |
1 ms |
320 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 |
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 |
286 ms |
17228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
403 ms |
17256 KB |
Output is correct |
3 |
Correct |
385 ms |
17324 KB |
Output is correct |
4 |
Correct |
374 ms |
17752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
403 ms |
17256 KB |
Output is correct |
3 |
Correct |
385 ms |
17324 KB |
Output is correct |
4 |
Correct |
374 ms |
17752 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
390 ms |
17576 KB |
Output is correct |
7 |
Correct |
408 ms |
17580 KB |
Output is correct |
8 |
Correct |
402 ms |
17396 KB |
Output is correct |
9 |
Correct |
404 ms |
17580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
403 ms |
17256 KB |
Output is correct |
3 |
Correct |
385 ms |
17324 KB |
Output is correct |
4 |
Correct |
374 ms |
17752 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
45 ms |
3000 KB |
Output is correct |
7 |
Correct |
44 ms |
3064 KB |
Output is correct |
8 |
Correct |
48 ms |
3008 KB |
Output is correct |
9 |
Correct |
43 ms |
2884 KB |
Output is correct |
10 |
Correct |
39 ms |
2884 KB |
Output is correct |
11 |
Correct |
40 ms |
3012 KB |
Output is correct |
12 |
Correct |
45 ms |
3020 KB |
Output is correct |
13 |
Correct |
43 ms |
2988 KB |
Output is correct |
14 |
Correct |
41 ms |
2868 KB |
Output is correct |
15 |
Correct |
43 ms |
2836 KB |
Output is correct |
16 |
Correct |
47 ms |
2868 KB |
Output is correct |
17 |
Correct |
44 ms |
2888 KB |
Output is correct |
18 |
Correct |
386 ms |
17384 KB |
Output is correct |
19 |
Correct |
375 ms |
17172 KB |
Output is correct |
20 |
Correct |
440 ms |
17692 KB |
Output is correct |
21 |
Correct |
41 ms |
2868 KB |
Output is correct |
22 |
Correct |
49 ms |
2992 KB |
Output is correct |
23 |
Correct |
135 ms |
9376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
47 ms |
2924 KB |
Output is correct |
3 |
Correct |
43 ms |
2844 KB |
Output is correct |
4 |
Correct |
446 ms |
17724 KB |
Output is correct |
5 |
Correct |
42 ms |
2956 KB |
Output is correct |
6 |
Correct |
57 ms |
3076 KB |
Output is correct |
7 |
Correct |
42 ms |
2916 KB |
Output is correct |
8 |
Correct |
45 ms |
3016 KB |
Output is correct |
9 |
Correct |
45 ms |
2988 KB |
Output is correct |
10 |
Correct |
45 ms |
2888 KB |
Output is correct |
11 |
Correct |
45 ms |
2992 KB |
Output is correct |
12 |
Correct |
37 ms |
2924 KB |
Output is correct |
13 |
Correct |
43 ms |
2776 KB |
Output is correct |
14 |
Correct |
431 ms |
17892 KB |
Output is correct |
15 |
Correct |
41 ms |
2904 KB |
Output is correct |
16 |
Correct |
383 ms |
17684 KB |
Output is correct |
17 |
Correct |
401 ms |
17904 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 |
4 ms |
984 KB |
Output is correct |
3 |
Correct |
5 ms |
976 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 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 |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
288 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 |
1056 KB |
Output is correct |
17 |
Correct |
47 ms |
2944 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |