#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(max(a,b+1),min(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++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
600 KB |
Output is correct |
3 |
Correct |
4 ms |
600 KB |
Output is correct |
4 |
Correct |
0 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 |
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 |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 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 |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
600 KB |
Output is correct |
17 |
Correct |
52 ms |
2480 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 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 |
340 KB |
Output is correct |
5 |
Correct |
323 ms |
16748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
382 ms |
16772 KB |
Output is correct |
3 |
Correct |
380 ms |
16788 KB |
Output is correct |
4 |
Correct |
397 ms |
16772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
382 ms |
16772 KB |
Output is correct |
3 |
Correct |
380 ms |
16788 KB |
Output is correct |
4 |
Correct |
397 ms |
16772 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
383 ms |
16860 KB |
Output is correct |
7 |
Correct |
383 ms |
16780 KB |
Output is correct |
8 |
Correct |
394 ms |
16952 KB |
Output is correct |
9 |
Correct |
425 ms |
16744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
382 ms |
16772 KB |
Output is correct |
3 |
Correct |
380 ms |
16788 KB |
Output is correct |
4 |
Correct |
397 ms |
16772 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
37 ms |
2512 KB |
Output is correct |
7 |
Correct |
40 ms |
2488 KB |
Output is correct |
8 |
Correct |
40 ms |
2484 KB |
Output is correct |
9 |
Correct |
40 ms |
2460 KB |
Output is correct |
10 |
Correct |
39 ms |
2376 KB |
Output is correct |
11 |
Correct |
42 ms |
2404 KB |
Output is correct |
12 |
Correct |
37 ms |
2516 KB |
Output is correct |
13 |
Correct |
41 ms |
2428 KB |
Output is correct |
14 |
Correct |
41 ms |
2504 KB |
Output is correct |
15 |
Correct |
43 ms |
2416 KB |
Output is correct |
16 |
Correct |
39 ms |
2452 KB |
Output is correct |
17 |
Correct |
38 ms |
2512 KB |
Output is correct |
18 |
Correct |
386 ms |
16828 KB |
Output is correct |
19 |
Correct |
388 ms |
16776 KB |
Output is correct |
20 |
Correct |
483 ms |
16796 KB |
Output is correct |
21 |
Correct |
43 ms |
2488 KB |
Output is correct |
22 |
Correct |
36 ms |
2440 KB |
Output is correct |
23 |
Correct |
120 ms |
8584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
41 ms |
2484 KB |
Output is correct |
3 |
Correct |
40 ms |
2504 KB |
Output is correct |
4 |
Correct |
458 ms |
16808 KB |
Output is correct |
5 |
Correct |
39 ms |
2512 KB |
Output is correct |
6 |
Correct |
40 ms |
2492 KB |
Output is correct |
7 |
Correct |
39 ms |
2528 KB |
Output is correct |
8 |
Correct |
42 ms |
2424 KB |
Output is correct |
9 |
Correct |
52 ms |
2452 KB |
Output is correct |
10 |
Correct |
47 ms |
2504 KB |
Output is correct |
11 |
Correct |
42 ms |
2380 KB |
Output is correct |
12 |
Correct |
37 ms |
2552 KB |
Output is correct |
13 |
Correct |
40 ms |
2488 KB |
Output is correct |
14 |
Correct |
467 ms |
16820 KB |
Output is correct |
15 |
Correct |
40 ms |
2420 KB |
Output is correct |
16 |
Correct |
396 ms |
16856 KB |
Output is correct |
17 |
Correct |
380 ms |
16748 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 |
Correct |
4 ms |
600 KB |
Output is correct |
3 |
Correct |
4 ms |
600 KB |
Output is correct |
4 |
Correct |
0 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 |
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 |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 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 |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
600 KB |
Output is correct |
17 |
Correct |
52 ms |
2480 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |