이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |