Submission #403486

# Submission time Handle Problem Language Result Execution time Memory
403486 2021-05-13T08:36:40 Z Hazem Strange Device (APIO19_strange_device) C++14
100 / 100
636 ms 49684 KB
#include <bits/stdc++.h>
using namespace std;
 
#define LL long long
#define F first
#define S second
#define pii pair<int,int>
#define piii pair<pair<int,int>,int>

const int N = 1e6+10;
const int M = 200;
const LL INF = 1e9;
const LL LINF = 2e18;
const LL MOD = 1e9+7;
const double PI = 3.141592653589793;

pair<LL,LL>p[N];
vector<pair<LL,LL>>vec;

LL gcd(LL a,LL b){return !b?a:gcd(b,a%b);}

int main(){

    //freopen("out.txt","w",stdout);

    LL n,a,b,Len;
    scanf("%lld%lld%lld",&n,&a,&b);

    // for(int i=0;i<=n;i++)
    //     printf("%d %d\n",(i+i/b)%a,i%b);

    LL g = gcd(a,b+1);
    a /= g;

    if(log(a)+log(b+1)>=log(LLONG_MAX))    
        Len = LINF;
    else 
        Len = a*(b+1)-a;

    bool q = 0;
    for(int i=1;i<=n;i++){

        scanf("%lld%lld",&p[i].F,&p[i].S);
        q |= p[i].S-p[i].F+1>=Len;

        p[i].F %= Len;p[i].S %= Len;

        if(p[i].S>=p[i].F)
            vec.push_back({p[i].F,p[i].S});
        else 
            vec.push_back({p[i].F,Len-1}),vec.push_back({0,p[i].S});
    }

    sort(vec.begin(),vec.end());
    
    LL l = 0,r = -1,ans = 0;
    vec.push_back({LINF,LINF});

    for(int i=0;i<vec.size();i++){
        
        if(vec[i].F>r)
            ans += r-l+1,l = vec[i].F,r = vec[i].S;
        else 
            r = max(r,vec[i].S);
    }

    printf("%lld\n",q?Len:ans);
}   

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:59:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for(int i=0;i<vec.size();i++){
      |                 ~^~~~~~~~~~~
strange_device.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     scanf("%lld%lld%lld",&n,&a,&b);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         scanf("%lld%lld",&p[i].F,&p[i].S);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 6 ms 716 KB Output is correct
3 Correct 6 ms 832 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 6 ms 944 KB Output is correct
17 Correct 57 ms 3700 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 380 ms 33336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 513 ms 31788 KB Output is correct
3 Correct 523 ms 31748 KB Output is correct
4 Correct 504 ms 31624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 513 ms 31788 KB Output is correct
3 Correct 523 ms 31748 KB Output is correct
4 Correct 504 ms 31624 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 521 ms 31820 KB Output is correct
7 Correct 523 ms 31764 KB Output is correct
8 Correct 508 ms 31684 KB Output is correct
9 Correct 561 ms 31664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 513 ms 31788 KB Output is correct
3 Correct 523 ms 31748 KB Output is correct
4 Correct 504 ms 31624 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 49 ms 3464 KB Output is correct
7 Correct 59 ms 3576 KB Output is correct
8 Correct 53 ms 3532 KB Output is correct
9 Correct 50 ms 3548 KB Output is correct
10 Correct 50 ms 3508 KB Output is correct
11 Correct 52 ms 3504 KB Output is correct
12 Correct 50 ms 3508 KB Output is correct
13 Correct 52 ms 3532 KB Output is correct
14 Correct 51 ms 3480 KB Output is correct
15 Correct 54 ms 3524 KB Output is correct
16 Correct 56 ms 7256 KB Output is correct
17 Correct 53 ms 7224 KB Output is correct
18 Correct 524 ms 49612 KB Output is correct
19 Correct 514 ms 49500 KB Output is correct
20 Correct 606 ms 49600 KB Output is correct
21 Correct 58 ms 7332 KB Output is correct
22 Correct 58 ms 7168 KB Output is correct
23 Correct 162 ms 23604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 54 ms 3544 KB Output is correct
3 Correct 53 ms 3436 KB Output is correct
4 Correct 581 ms 31728 KB Output is correct
5 Correct 53 ms 3476 KB Output is correct
6 Correct 53 ms 3544 KB Output is correct
7 Correct 52 ms 3448 KB Output is correct
8 Correct 54 ms 3520 KB Output is correct
9 Correct 57 ms 3536 KB Output is correct
10 Correct 53 ms 3528 KB Output is correct
11 Correct 53 ms 3468 KB Output is correct
12 Correct 48 ms 3488 KB Output is correct
13 Correct 58 ms 3504 KB Output is correct
14 Correct 636 ms 31756 KB Output is correct
15 Correct 54 ms 7240 KB Output is correct
16 Correct 516 ms 49548 KB Output is correct
17 Correct 520 ms 49684 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 6 ms 716 KB Output is correct
3 Correct 6 ms 832 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 6 ms 944 KB Output is correct
17 Correct 57 ms 3700 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 380 ms 33336 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 513 ms 31788 KB Output is correct
31 Correct 523 ms 31748 KB Output is correct
32 Correct 504 ms 31624 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 521 ms 31820 KB Output is correct
35 Correct 523 ms 31764 KB Output is correct
36 Correct 508 ms 31684 KB Output is correct
37 Correct 561 ms 31664 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 49 ms 3464 KB Output is correct
40 Correct 59 ms 3576 KB Output is correct
41 Correct 53 ms 3532 KB Output is correct
42 Correct 50 ms 3548 KB Output is correct
43 Correct 50 ms 3508 KB Output is correct
44 Correct 52 ms 3504 KB Output is correct
45 Correct 50 ms 3508 KB Output is correct
46 Correct 52 ms 3532 KB Output is correct
47 Correct 51 ms 3480 KB Output is correct
48 Correct 54 ms 3524 KB Output is correct
49 Correct 56 ms 7256 KB Output is correct
50 Correct 53 ms 7224 KB Output is correct
51 Correct 524 ms 49612 KB Output is correct
52 Correct 514 ms 49500 KB Output is correct
53 Correct 606 ms 49600 KB Output is correct
54 Correct 58 ms 7332 KB Output is correct
55 Correct 58 ms 7168 KB Output is correct
56 Correct 162 ms 23604 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 54 ms 3544 KB Output is correct
59 Correct 53 ms 3436 KB Output is correct
60 Correct 581 ms 31728 KB Output is correct
61 Correct 53 ms 3476 KB Output is correct
62 Correct 53 ms 3544 KB Output is correct
63 Correct 52 ms 3448 KB Output is correct
64 Correct 54 ms 3520 KB Output is correct
65 Correct 57 ms 3536 KB Output is correct
66 Correct 53 ms 3528 KB Output is correct
67 Correct 53 ms 3468 KB Output is correct
68 Correct 48 ms 3488 KB Output is correct
69 Correct 58 ms 3504 KB Output is correct
70 Correct 636 ms 31756 KB Output is correct
71 Correct 54 ms 7240 KB Output is correct
72 Correct 516 ms 49548 KB Output is correct
73 Correct 520 ms 49684 KB Output is correct
74 Correct 1 ms 204 KB Output is correct
75 Correct 1 ms 204 KB Output is correct
76 Correct 1 ms 204 KB Output is correct
77 Correct 1 ms 296 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 6 ms 1100 KB Output is correct
80 Correct 585 ms 49584 KB Output is correct
81 Correct 601 ms 49572 KB Output is correct
82 Correct 562 ms 49668 KB Output is correct
83 Correct 565 ms 49532 KB Output is correct
84 Correct 552 ms 49592 KB Output is correct
85 Correct 551 ms 49636 KB Output is correct
86 Correct 161 ms 23576 KB Output is correct
87 Correct 1 ms 204 KB Output is correct