Submission #713522

# Submission time Handle Problem Language Result Execution time Memory
713522 2023-03-22T11:27:32 Z bin9638 Strange Device (APIO19_strange_device) C++17
100 / 100
668 ms 51752 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define N 2000010
#define ii pair<int,int>
#define fs first
#define sc second
#define ld double
#define int ll

const int MAX_VAL=2e18;

int S,cnt[N],n,A,B,dem=0,ans=0;
vector<int>s;

void sub_AB()
{
    int res=0;
    for(int i=1;i<=n;i++)
    {
        int l,r;
        cin>>l>>r;
        res+=(r-l+1);
    }
    cout<<res;
    exit(0);
}

ii a[N];

int32_t main()
{
    #ifdef SKY
    freopen("A.inp","r",stdin);
    freopen("A.out","w",stdout);
    #endif // SKY
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>A>>B;
    if(MAX_VAL/B<=A/__gcd(A,B+1))
        sub_AB();
    S=B*(A/__gcd(A,B+1));
    for(int i=1;i<=n;i++)
    {
        int l,r;
        cin>>l>>r;
        if(r-l+1>=S)
        {
            cout<<S;
            return 0;
        }
        int lef=l%S,righ=r%S;
        if(lef<=righ)
        {
            a[++dem]={lef,righ};
        }else
        {
            a[++dem]={lef,S-1};
            a[++dem]={0,righ};
        }
    }
    for(int i=1;i<=dem;i++)
    {
        s.pb(a[i].fs);
        s.pb(a[i].sc+1);
    }
    sort(s.begin(),s.end());
    s.erase(unique(s.begin(),s.end()),s.end());
    for(int i=1;i<=dem;i++)
    {
        cnt[lower_bound(s.begin(),s.end(),a[i].fs)-s.begin()]++;
        cnt[lower_bound(s.begin(),s.end(),a[i].sc+1)-s.begin()]--;
    }
    for(int i=0;i<s.size()-1;i++)
    {
        if(i>0)
            cnt[i]+=cnt[i-1];
        if(cnt[i]>0)
            ans+=(s[i+1]-s[i]);
    }
    cout<<ans;
    return 0;
}

Compilation message

strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:78:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for(int i=0;i<s.size()-1;i++)
      |                 ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 9 ms 856 KB Output is correct
3 Correct 6 ms 852 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 6 ms 980 KB Output is correct
17 Correct 61 ms 4348 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 339 ms 32456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 533 ms 39636 KB Output is correct
3 Correct 553 ms 39688 KB Output is correct
4 Correct 566 ms 39580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 533 ms 39636 KB Output is correct
3 Correct 553 ms 39688 KB Output is correct
4 Correct 566 ms 39580 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 571 ms 39648 KB Output is correct
7 Correct 552 ms 39544 KB Output is correct
8 Correct 539 ms 39520 KB Output is correct
9 Correct 631 ms 39644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 533 ms 39636 KB Output is correct
3 Correct 553 ms 39688 KB Output is correct
4 Correct 566 ms 39580 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 56 ms 4356 KB Output is correct
7 Correct 60 ms 4252 KB Output is correct
8 Correct 49 ms 4308 KB Output is correct
9 Correct 54 ms 4352 KB Output is correct
10 Correct 49 ms 4324 KB Output is correct
11 Correct 55 ms 4340 KB Output is correct
12 Correct 56 ms 4292 KB Output is correct
13 Correct 59 ms 4264 KB Output is correct
14 Correct 52 ms 4296 KB Output is correct
15 Correct 61 ms 4336 KB Output is correct
16 Correct 56 ms 4292 KB Output is correct
17 Correct 52 ms 4252 KB Output is correct
18 Correct 551 ms 39560 KB Output is correct
19 Correct 508 ms 39532 KB Output is correct
20 Correct 599 ms 39516 KB Output is correct
21 Correct 65 ms 4364 KB Output is correct
22 Correct 50 ms 4420 KB Output is correct
23 Correct 121 ms 13952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 73 ms 4352 KB Output is correct
3 Correct 60 ms 4252 KB Output is correct
4 Correct 622 ms 39584 KB Output is correct
5 Correct 61 ms 4364 KB Output is correct
6 Correct 58 ms 4276 KB Output is correct
7 Correct 55 ms 4372 KB Output is correct
8 Correct 57 ms 4368 KB Output is correct
9 Correct 54 ms 4304 KB Output is correct
10 Correct 58 ms 4280 KB Output is correct
11 Correct 61 ms 4292 KB Output is correct
12 Correct 52 ms 4372 KB Output is correct
13 Correct 58 ms 4288 KB Output is correct
14 Correct 593 ms 39536 KB Output is correct
15 Correct 63 ms 4436 KB Output is correct
16 Correct 527 ms 39632 KB Output is correct
17 Correct 550 ms 39516 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 9 ms 856 KB Output is correct
3 Correct 6 ms 852 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 6 ms 980 KB Output is correct
17 Correct 61 ms 4348 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 339 ms 32456 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 533 ms 39636 KB Output is correct
31 Correct 553 ms 39688 KB Output is correct
32 Correct 566 ms 39580 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 571 ms 39648 KB Output is correct
35 Correct 552 ms 39544 KB Output is correct
36 Correct 539 ms 39520 KB Output is correct
37 Correct 631 ms 39644 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 56 ms 4356 KB Output is correct
40 Correct 60 ms 4252 KB Output is correct
41 Correct 49 ms 4308 KB Output is correct
42 Correct 54 ms 4352 KB Output is correct
43 Correct 49 ms 4324 KB Output is correct
44 Correct 55 ms 4340 KB Output is correct
45 Correct 56 ms 4292 KB Output is correct
46 Correct 59 ms 4264 KB Output is correct
47 Correct 52 ms 4296 KB Output is correct
48 Correct 61 ms 4336 KB Output is correct
49 Correct 56 ms 4292 KB Output is correct
50 Correct 52 ms 4252 KB Output is correct
51 Correct 551 ms 39560 KB Output is correct
52 Correct 508 ms 39532 KB Output is correct
53 Correct 599 ms 39516 KB Output is correct
54 Correct 65 ms 4364 KB Output is correct
55 Correct 50 ms 4420 KB Output is correct
56 Correct 121 ms 13952 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 73 ms 4352 KB Output is correct
59 Correct 60 ms 4252 KB Output is correct
60 Correct 622 ms 39584 KB Output is correct
61 Correct 61 ms 4364 KB Output is correct
62 Correct 58 ms 4276 KB Output is correct
63 Correct 55 ms 4372 KB Output is correct
64 Correct 57 ms 4368 KB Output is correct
65 Correct 54 ms 4304 KB Output is correct
66 Correct 58 ms 4280 KB Output is correct
67 Correct 61 ms 4292 KB Output is correct
68 Correct 52 ms 4372 KB Output is correct
69 Correct 58 ms 4288 KB Output is correct
70 Correct 593 ms 39536 KB Output is correct
71 Correct 63 ms 4436 KB Output is correct
72 Correct 527 ms 39632 KB Output is correct
73 Correct 550 ms 39516 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 0 ms 212 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 1 ms 332 KB Output is correct
79 Correct 6 ms 1240 KB Output is correct
80 Correct 668 ms 51692 KB Output is correct
81 Correct 645 ms 51608 KB Output is correct
82 Correct 650 ms 51752 KB Output is correct
83 Correct 650 ms 51640 KB Output is correct
84 Correct 626 ms 51636 KB Output is correct
85 Correct 613 ms 51740 KB Output is correct
86 Correct 139 ms 26500 KB Output is correct
87 Correct 1 ms 340 KB Output is correct