#include <bits/stdc++.h>
#define DIMN 5000010
using namespace std;
pair <long long,int> v[DIMN];
map <pair <long long , long long> , long long> mp;
long long cmmdc (long long x , long long y){
long long r;
while (y){
r = x % y;
x = y;
y = r;
}
return x;
}
int main()
{
FILE *fin = stdin;
FILE *fout = stdout;
int n , over , elem , i , into;
long long a , b, l , r , sol;
fscanf (fin,"%d%lld%lld",&n,&a,&b);
a /= cmmdc (a , b + 1);
over = 0;
if ( a > 1000000000000000000LL / b )
over = 1;
elem = 0;
for (i=1;i<=n;i++){
fscanf (fin,"%lld%lld",&l,&r);
if (over){
/// dau resturile l si r
v[++elem] = make_pair( l , 1 ); /// begin
v[++elem] = make_pair( r + 1 , 0 ); /// end
}
else {
if (r - l + 1 >= a * b){ /// sunt toate resturile
v[++elem] = make_pair( 0 , 1 ); /// begin
v[++elem] = make_pair( a * b , 0 ); /// end
}
else {
l = l % (a * b);
r = r % (a * b);
if (l <= r){
v[++elem] = make_pair( l , 1 ); /// begin
v[++elem] = make_pair( r + 1 , 0 ); /// end
}
else { /// se duce l .. ab - 1 0 ... r
v[++elem] = make_pair( l , 1 ); /// begin
v[++elem] = make_pair( a * b , 0 ); /// end
v[++elem] = make_pair( 0 , 1 ); /// begin
v[++elem] = make_pair( r + 1 , 0 ); /// end
}
}
}
}
/*for (long long j = 0; j < a * b ; j++){
if( mp[make_pair((j + j / b) % a , j % b)]){
fprintf (fout,"%lld\n",mp[make_pair((j + j / b) % a , j % b)] - j);
break;
}
mp[make_pair((j + j / b) % a , j % b)] = j;
}*/
/// acum eu am un vector de evenimente , vr sa vad reunuiunea
sol = 0;
sort (v + 1 , v + elem + 1);
into = 0;
for ( i = 1 ; i <= elem ; i++ ){
while (i < elem && v[i].first == v[i+1].first){
if (v[i].second == 1)
into++;
else into--;
i++;
}
if (i == elem)
break;
if (v[i].second == 1)
into++;
else into--;
if (into > 0){
sol = sol + v[i+1].first - v[i].first;
}
}
fprintf (fout,"%lld",sol);
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:22:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
fscanf (fin,"%d%lld%lld",&n,&a,&b);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:29:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
fscanf (fin,"%lld%lld",&l,&r);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
8 ms |
1016 KB |
Output is correct |
3 |
Correct |
8 ms |
1016 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
380 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
8 ms |
1016 KB |
Output is correct |
17 |
Correct |
73 ms |
4708 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
408 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
478 ms |
32236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
631 ms |
32060 KB |
Output is correct |
3 |
Correct |
673 ms |
32248 KB |
Output is correct |
4 |
Correct |
641 ms |
32128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
631 ms |
32060 KB |
Output is correct |
3 |
Correct |
673 ms |
32248 KB |
Output is correct |
4 |
Correct |
641 ms |
32128 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
671 ms |
31972 KB |
Output is correct |
7 |
Correct |
631 ms |
40512 KB |
Output is correct |
8 |
Correct |
659 ms |
43868 KB |
Output is correct |
9 |
Correct |
755 ms |
40396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
631 ms |
32060 KB |
Output is correct |
3 |
Correct |
673 ms |
32248 KB |
Output is correct |
4 |
Correct |
641 ms |
32128 KB |
Output is correct |
5 |
Correct |
2 ms |
128 KB |
Output is correct |
6 |
Correct |
61 ms |
4728 KB |
Output is correct |
7 |
Correct |
65 ms |
4728 KB |
Output is correct |
8 |
Correct |
62 ms |
4728 KB |
Output is correct |
9 |
Correct |
65 ms |
4732 KB |
Output is correct |
10 |
Correct |
61 ms |
4728 KB |
Output is correct |
11 |
Correct |
66 ms |
4728 KB |
Output is correct |
12 |
Correct |
63 ms |
4728 KB |
Output is correct |
13 |
Correct |
72 ms |
4856 KB |
Output is correct |
14 |
Correct |
62 ms |
4728 KB |
Output is correct |
15 |
Correct |
74 ms |
4696 KB |
Output is correct |
16 |
Correct |
72 ms |
4728 KB |
Output is correct |
17 |
Correct |
66 ms |
4728 KB |
Output is correct |
18 |
Correct |
675 ms |
43732 KB |
Output is correct |
19 |
Correct |
630 ms |
40212 KB |
Output is correct |
20 |
Correct |
781 ms |
40196 KB |
Output is correct |
21 |
Correct |
82 ms |
7332 KB |
Output is correct |
22 |
Correct |
58 ms |
7160 KB |
Output is correct |
23 |
Correct |
209 ms |
14072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
252 KB |
Output is correct |
2 |
Correct |
70 ms |
4728 KB |
Output is correct |
3 |
Correct |
70 ms |
4796 KB |
Output is correct |
4 |
Correct |
843 ms |
32132 KB |
Output is correct |
5 |
Correct |
71 ms |
4728 KB |
Output is correct |
6 |
Correct |
72 ms |
4700 KB |
Output is correct |
7 |
Correct |
72 ms |
7160 KB |
Output is correct |
8 |
Correct |
76 ms |
7168 KB |
Output is correct |
9 |
Correct |
66 ms |
7260 KB |
Output is correct |
10 |
Correct |
74 ms |
7212 KB |
Output is correct |
11 |
Correct |
72 ms |
7260 KB |
Output is correct |
12 |
Correct |
64 ms |
7288 KB |
Output is correct |
13 |
Correct |
75 ms |
7160 KB |
Output is correct |
14 |
Correct |
738 ms |
40796 KB |
Output is correct |
15 |
Correct |
74 ms |
7160 KB |
Output is correct |
16 |
Correct |
615 ms |
39544 KB |
Output is correct |
17 |
Correct |
650 ms |
39272 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
8 ms |
1016 KB |
Output is correct |
3 |
Correct |
8 ms |
1016 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
380 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
8 ms |
1016 KB |
Output is correct |
17 |
Correct |
73 ms |
4708 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
380 KB |
Output is correct |
20 |
Correct |
2 ms |
408 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
256 KB |
Output is correct |
23 |
Correct |
2 ms |
256 KB |
Output is correct |
24 |
Correct |
2 ms |
256 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
27 |
Correct |
3 ms |
376 KB |
Output is correct |
28 |
Correct |
478 ms |
32236 KB |
Output is correct |
29 |
Correct |
1 ms |
256 KB |
Output is correct |
30 |
Correct |
631 ms |
32060 KB |
Output is correct |
31 |
Correct |
673 ms |
32248 KB |
Output is correct |
32 |
Correct |
641 ms |
32128 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
671 ms |
31972 KB |
Output is correct |
35 |
Correct |
631 ms |
40512 KB |
Output is correct |
36 |
Correct |
659 ms |
43868 KB |
Output is correct |
37 |
Correct |
755 ms |
40396 KB |
Output is correct |
38 |
Correct |
2 ms |
128 KB |
Output is correct |
39 |
Correct |
61 ms |
4728 KB |
Output is correct |
40 |
Correct |
65 ms |
4728 KB |
Output is correct |
41 |
Correct |
62 ms |
4728 KB |
Output is correct |
42 |
Correct |
65 ms |
4732 KB |
Output is correct |
43 |
Correct |
61 ms |
4728 KB |
Output is correct |
44 |
Correct |
66 ms |
4728 KB |
Output is correct |
45 |
Correct |
63 ms |
4728 KB |
Output is correct |
46 |
Correct |
72 ms |
4856 KB |
Output is correct |
47 |
Correct |
62 ms |
4728 KB |
Output is correct |
48 |
Correct |
74 ms |
4696 KB |
Output is correct |
49 |
Correct |
72 ms |
4728 KB |
Output is correct |
50 |
Correct |
66 ms |
4728 KB |
Output is correct |
51 |
Correct |
675 ms |
43732 KB |
Output is correct |
52 |
Correct |
630 ms |
40212 KB |
Output is correct |
53 |
Correct |
781 ms |
40196 KB |
Output is correct |
54 |
Correct |
82 ms |
7332 KB |
Output is correct |
55 |
Correct |
58 ms |
7160 KB |
Output is correct |
56 |
Correct |
209 ms |
14072 KB |
Output is correct |
57 |
Correct |
2 ms |
252 KB |
Output is correct |
58 |
Correct |
70 ms |
4728 KB |
Output is correct |
59 |
Correct |
70 ms |
4796 KB |
Output is correct |
60 |
Correct |
843 ms |
32132 KB |
Output is correct |
61 |
Correct |
71 ms |
4728 KB |
Output is correct |
62 |
Correct |
72 ms |
4700 KB |
Output is correct |
63 |
Correct |
72 ms |
7160 KB |
Output is correct |
64 |
Correct |
76 ms |
7168 KB |
Output is correct |
65 |
Correct |
66 ms |
7260 KB |
Output is correct |
66 |
Correct |
74 ms |
7212 KB |
Output is correct |
67 |
Correct |
72 ms |
7260 KB |
Output is correct |
68 |
Correct |
64 ms |
7288 KB |
Output is correct |
69 |
Correct |
75 ms |
7160 KB |
Output is correct |
70 |
Correct |
738 ms |
40796 KB |
Output is correct |
71 |
Correct |
74 ms |
7160 KB |
Output is correct |
72 |
Correct |
615 ms |
39544 KB |
Output is correct |
73 |
Correct |
650 ms |
39272 KB |
Output is correct |
74 |
Correct |
2 ms |
376 KB |
Output is correct |
75 |
Correct |
2 ms |
376 KB |
Output is correct |
76 |
Correct |
2 ms |
376 KB |
Output is correct |
77 |
Correct |
2 ms |
376 KB |
Output is correct |
78 |
Correct |
2 ms |
376 KB |
Output is correct |
79 |
Correct |
7 ms |
1016 KB |
Output is correct |
80 |
Correct |
840 ms |
38820 KB |
Output is correct |
81 |
Correct |
849 ms |
42896 KB |
Output is correct |
82 |
Correct |
740 ms |
38904 KB |
Output is correct |
83 |
Correct |
736 ms |
37844 KB |
Output is correct |
84 |
Correct |
750 ms |
41864 KB |
Output is correct |
85 |
Correct |
777 ms |
37976 KB |
Output is correct |
86 |
Correct |
211 ms |
13048 KB |
Output is correct |
87 |
Correct |
2 ms |
256 KB |
Output is correct |