Submission #432641

# Submission time Handle Problem Language Result Execution time Memory
432641 2021-06-18T11:55:21 Z TLP39 Strange Device (APIO19_strange_device) C++14
100 / 100
737 ms 69804 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;

const ll HIGH=1000000000000000000;
ll gcd(ll x,ll y)
{
    if(!x || !y) return x+y;
    return gcd(y,x%y);
}

int n;
ll a,b,c,d;
ll res=0;
ll l,r;
pll t[2000004];
vector<pll> v;
int cou=0;
int main()
{
    scanf("%d %lld %lld",&n,&a,&b);
    c=gcd(a,b+1);
    if(a/c>HIGH/b)
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%lld %lld",&l,&r);
            res+=(r-l+1ll);
        }
        printf("%lld",res);
        return 0;
    }
    d=(a/c)*b;
    for(int i=0;i<n;i++)
    {
        scanf("%lld %lld",&l,&r);
        if(r-l+1>=d)
        {
            printf("%lld",d);
            return 0;
        }
        if(l/d==r/d)
        {
            t[cou]={l%d,r%d};
            cou++;
        }
        else
        {
            t[cou]={l%d,d-1ll};
            cou++;
            t[cou]={0ll,r%d};
            cou++;
        }
    }
    sort(t,t+cou);
    for(int i=0;i<cou;i++)
    {
        if(!v.empty() && v[v.size()-1].second>=t[i].first)
        {
            v[v.size()-1].second=max(v[v.size()-1].second,t[i].second);
        }
        else
        {
            v.push_back(t[i]);
        }
    }
    for(int i=0;i<v.size();i++)
    {
        res+=(v[i].second-v[i].first+1ll);
    }
    printf("%lld",res);
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:68: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]
   68 |     for(int i=0;i<v.size();i++)
      |                 ~^~~~~~~~~
strange_device.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf("%d %lld %lld",&n,&a,&b);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:28:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |             scanf("%lld %lld",&l,&r);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~
strange_device.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         scanf("%lld %lld",&l,&r);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 7 ms 1148 KB Output is correct
3 Correct 6 ms 1092 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 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 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 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 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 7 ms 1228 KB Output is correct
17 Correct 57 ms 7736 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 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 316 KB Output is correct
5 Correct 386 ms 41124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 574 ms 69664 KB Output is correct
3 Correct 571 ms 69620 KB Output is correct
4 Correct 540 ms 69696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 574 ms 69664 KB Output is correct
3 Correct 571 ms 69620 KB Output is correct
4 Correct 540 ms 69696 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 573 ms 69600 KB Output is correct
7 Correct 564 ms 69804 KB Output is correct
8 Correct 578 ms 69684 KB Output is correct
9 Correct 608 ms 69740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 574 ms 69664 KB Output is correct
3 Correct 571 ms 69620 KB Output is correct
4 Correct 540 ms 69696 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 53 ms 7756 KB Output is correct
7 Correct 57 ms 7748 KB Output is correct
8 Correct 63 ms 7772 KB Output is correct
9 Correct 53 ms 7704 KB Output is correct
10 Correct 59 ms 7732 KB Output is correct
11 Correct 55 ms 7756 KB Output is correct
12 Correct 54 ms 7744 KB Output is correct
13 Correct 58 ms 7736 KB Output is correct
14 Correct 54 ms 7760 KB Output is correct
15 Correct 58 ms 7704 KB Output is correct
16 Correct 56 ms 7748 KB Output is correct
17 Correct 71 ms 7720 KB Output is correct
18 Correct 578 ms 69640 KB Output is correct
19 Correct 552 ms 69700 KB Output is correct
20 Correct 719 ms 69620 KB Output is correct
21 Correct 56 ms 7752 KB Output is correct
22 Correct 57 ms 7648 KB Output is correct
23 Correct 201 ms 18228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 56 ms 7660 KB Output is correct
3 Correct 68 ms 7756 KB Output is correct
4 Correct 737 ms 69716 KB Output is correct
5 Correct 56 ms 7720 KB Output is correct
6 Correct 69 ms 7732 KB Output is correct
7 Correct 80 ms 7684 KB Output is correct
8 Correct 59 ms 7648 KB Output is correct
9 Correct 73 ms 7728 KB Output is correct
10 Correct 56 ms 7724 KB Output is correct
11 Correct 64 ms 7736 KB Output is correct
12 Correct 50 ms 7736 KB Output is correct
13 Correct 71 ms 7748 KB Output is correct
14 Correct 600 ms 69624 KB Output is correct
15 Correct 56 ms 7736 KB Output is correct
16 Correct 587 ms 69616 KB Output is correct
17 Correct 621 ms 69804 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 7 ms 1148 KB Output is correct
3 Correct 6 ms 1092 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 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 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 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 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 7 ms 1228 KB Output is correct
17 Correct 57 ms 7736 KB Output is correct
18 Correct 1 ms 204 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 316 KB Output is correct
28 Correct 386 ms 41124 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 574 ms 69664 KB Output is correct
31 Correct 571 ms 69620 KB Output is correct
32 Correct 540 ms 69696 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 573 ms 69600 KB Output is correct
35 Correct 564 ms 69804 KB Output is correct
36 Correct 578 ms 69684 KB Output is correct
37 Correct 608 ms 69740 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 53 ms 7756 KB Output is correct
40 Correct 57 ms 7748 KB Output is correct
41 Correct 63 ms 7772 KB Output is correct
42 Correct 53 ms 7704 KB Output is correct
43 Correct 59 ms 7732 KB Output is correct
44 Correct 55 ms 7756 KB Output is correct
45 Correct 54 ms 7744 KB Output is correct
46 Correct 58 ms 7736 KB Output is correct
47 Correct 54 ms 7760 KB Output is correct
48 Correct 58 ms 7704 KB Output is correct
49 Correct 56 ms 7748 KB Output is correct
50 Correct 71 ms 7720 KB Output is correct
51 Correct 578 ms 69640 KB Output is correct
52 Correct 552 ms 69700 KB Output is correct
53 Correct 719 ms 69620 KB Output is correct
54 Correct 56 ms 7752 KB Output is correct
55 Correct 57 ms 7648 KB Output is correct
56 Correct 201 ms 18228 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 56 ms 7660 KB Output is correct
59 Correct 68 ms 7756 KB Output is correct
60 Correct 737 ms 69716 KB Output is correct
61 Correct 56 ms 7720 KB Output is correct
62 Correct 69 ms 7732 KB Output is correct
63 Correct 80 ms 7684 KB Output is correct
64 Correct 59 ms 7648 KB Output is correct
65 Correct 73 ms 7728 KB Output is correct
66 Correct 56 ms 7724 KB Output is correct
67 Correct 64 ms 7736 KB Output is correct
68 Correct 50 ms 7736 KB Output is correct
69 Correct 71 ms 7748 KB Output is correct
70 Correct 600 ms 69624 KB Output is correct
71 Correct 56 ms 7736 KB Output is correct
72 Correct 587 ms 69616 KB Output is correct
73 Correct 621 ms 69804 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 304 KB Output is correct
77 Correct 1 ms 204 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 6 ms 1228 KB Output is correct
80 Correct 665 ms 69624 KB Output is correct
81 Correct 734 ms 69636 KB Output is correct
82 Correct 684 ms 69656 KB Output is correct
83 Correct 609 ms 69616 KB Output is correct
84 Correct 622 ms 69684 KB Output is correct
85 Correct 593 ms 69596 KB Output is correct
86 Correct 157 ms 18148 KB Output is correct
87 Correct 1 ms 204 KB Output is correct