#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;
int cmmdc (int x , int y){
int 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);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
420 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 |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
372 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
404 KB |
Output is correct |
13 |
Correct |
2 ms |
348 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 |
76 ms |
7180 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
0 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
481 ms |
37576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
630 ms |
44152 KB |
Output is correct |
3 |
Correct |
685 ms |
44176 KB |
Output is correct |
4 |
Correct |
643 ms |
40172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
630 ms |
44152 KB |
Output is correct |
3 |
Correct |
685 ms |
44176 KB |
Output is correct |
4 |
Correct |
643 ms |
40172 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Incorrect |
585 ms |
40120 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
630 ms |
44152 KB |
Output is correct |
3 |
Correct |
685 ms |
44176 KB |
Output is correct |
4 |
Correct |
643 ms |
40172 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
62 ms |
7156 KB |
Output is correct |
7 |
Correct |
66 ms |
7160 KB |
Output is correct |
8 |
Correct |
64 ms |
7160 KB |
Output is correct |
9 |
Correct |
67 ms |
7160 KB |
Output is correct |
10 |
Correct |
59 ms |
7164 KB |
Output is correct |
11 |
Correct |
66 ms |
7288 KB |
Output is correct |
12 |
Correct |
64 ms |
7288 KB |
Output is correct |
13 |
Correct |
72 ms |
7296 KB |
Output is correct |
14 |
Correct |
62 ms |
7160 KB |
Output is correct |
15 |
Correct |
75 ms |
7128 KB |
Output is correct |
16 |
Correct |
72 ms |
7160 KB |
Output is correct |
17 |
Incorrect |
51 ms |
7208 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
70 ms |
7208 KB |
Output is correct |
3 |
Correct |
71 ms |
7288 KB |
Output is correct |
4 |
Correct |
834 ms |
40780 KB |
Output is correct |
5 |
Correct |
73 ms |
7160 KB |
Output is correct |
6 |
Incorrect |
76 ms |
7160 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
420 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 |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
372 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
404 KB |
Output is correct |
13 |
Correct |
2 ms |
348 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 |
76 ms |
7180 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
0 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
256 KB |
Output is correct |
22 |
Correct |
2 ms |
256 KB |
Output is correct |
23 |
Correct |
3 ms |
376 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 |
481 ms |
37576 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
630 ms |
44152 KB |
Output is correct |
31 |
Correct |
685 ms |
44176 KB |
Output is correct |
32 |
Correct |
643 ms |
40172 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Incorrect |
585 ms |
40120 KB |
Output isn't correct |
35 |
Halted |
0 ms |
0 KB |
- |