Submission #252092

# Submission time Handle Problem Language Result Execution time Memory
252092 2020-07-24T06:17:10 Z jeqcho Strange Device (APIO19_strange_device) C++17
100 / 100
618 ms 23768 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpi;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define pb push_back
#define rsz resize
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define f first
#define s second

// solved subtask 4 and 5

ll A,B;

ll gcd(ll a, ll b)
{
    // O((log n)^2)
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n>>A>>B;
    ll l,r;
    ll q = A / gcd(A,B+1);
    ll maxlen = q*B;
    if(q*B < 0)
    {
        ll ans=0;
        F0R(i,n)
        {
            cin>>l>>r;
            ans+=r-l+1;
        }
        cout<<ans<<'\n';
        return 0;
    }
    vector<pair<ll,ll>> segments;
    F0R(i,n)
    {
        cin>>l>>r;
        if(r-l+1 >= maxlen)
        {
            FOR(j,i+1,n)cin>>l>>r;
            cout<<maxlen<<endl;
            return 0;
        }
        l %= maxlen;
        r %= maxlen;
        if(r<l)
        {
            segments.pb({0,r});
            segments.pb({l,maxlen-1});
        }
        else segments.pb({l,r});
    }
    sort(all(segments));
    bool init=0;
    ll ldex,rdex;
    ll ans=0;
    pair<ll,ll> seg;
    F0R(i,sz(segments)+1)
    {
        if(i==sz(segments))
        {
            ans += rdex-ldex+1;
            break;
        }
        seg = segments[i];
        if(!init)
        {
            ldex=seg.f;
            rdex=seg.s;
            init=1;
        }
        else if(seg.f==ldex)
        {
            rdex = seg.s;
        }
        else
        {
            // seg.f > ldex
            if(seg.f <= rdex)
            {
                rdex = max(rdex,seg.s);
            }
            else
            {
                ans += rdex-ldex+1;
                ldex=seg.f;
                rdex=seg.s;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:81:24: warning: 'rdex' may be used uninitialized in this function [-Wmaybe-uninitialized]
             ans += rdex-ldex+1;
                    ~~~~^~~~~
strange_device.cpp:81:24: warning: 'ldex' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
3 Correct 6 ms 1152 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 6 ms 1152 KB Output is correct
17 Correct 57 ms 5740 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 384 ms 17620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 545 ms 21868 KB Output is correct
3 Correct 506 ms 21844 KB Output is correct
4 Correct 502 ms 21844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 545 ms 21868 KB Output is correct
3 Correct 506 ms 21844 KB Output is correct
4 Correct 502 ms 21844 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 511 ms 21836 KB Output is correct
7 Correct 524 ms 21928 KB Output is correct
8 Correct 514 ms 21844 KB Output is correct
9 Correct 556 ms 21996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 545 ms 21868 KB Output is correct
3 Correct 506 ms 21844 KB Output is correct
4 Correct 502 ms 21844 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 51 ms 5740 KB Output is correct
7 Correct 59 ms 6032 KB Output is correct
8 Correct 52 ms 5736 KB Output is correct
9 Correct 52 ms 5740 KB Output is correct
10 Correct 52 ms 5764 KB Output is correct
11 Correct 57 ms 5736 KB Output is correct
12 Correct 52 ms 5740 KB Output is correct
13 Correct 57 ms 5880 KB Output is correct
14 Correct 52 ms 5740 KB Output is correct
15 Correct 56 ms 5864 KB Output is correct
16 Correct 56 ms 5740 KB Output is correct
17 Correct 51 ms 5744 KB Output is correct
18 Correct 505 ms 23688 KB Output is correct
19 Correct 490 ms 23508 KB Output is correct
20 Correct 601 ms 23556 KB Output is correct
21 Correct 53 ms 5736 KB Output is correct
22 Correct 47 ms 5736 KB Output is correct
23 Correct 169 ms 15200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 54 ms 5736 KB Output is correct
3 Correct 54 ms 5736 KB Output is correct
4 Correct 618 ms 22356 KB Output is correct
5 Correct 53 ms 5740 KB Output is correct
6 Correct 56 ms 5736 KB Output is correct
7 Correct 58 ms 5740 KB Output is correct
8 Correct 59 ms 5736 KB Output is correct
9 Correct 54 ms 5740 KB Output is correct
10 Correct 57 ms 5772 KB Output is correct
11 Correct 53 ms 5736 KB Output is correct
12 Correct 53 ms 5740 KB Output is correct
13 Correct 56 ms 5740 KB Output is correct
14 Correct 556 ms 22520 KB Output is correct
15 Correct 54 ms 5736 KB Output is correct
16 Correct 502 ms 23520 KB Output is correct
17 Correct 505 ms 23768 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
3 Correct 6 ms 1152 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 6 ms 1152 KB Output is correct
17 Correct 57 ms 5740 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 384 ms 17620 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 545 ms 21868 KB Output is correct
31 Correct 506 ms 21844 KB Output is correct
32 Correct 502 ms 21844 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 511 ms 21836 KB Output is correct
35 Correct 524 ms 21928 KB Output is correct
36 Correct 514 ms 21844 KB Output is correct
37 Correct 556 ms 21996 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 51 ms 5740 KB Output is correct
40 Correct 59 ms 6032 KB Output is correct
41 Correct 52 ms 5736 KB Output is correct
42 Correct 52 ms 5740 KB Output is correct
43 Correct 52 ms 5764 KB Output is correct
44 Correct 57 ms 5736 KB Output is correct
45 Correct 52 ms 5740 KB Output is correct
46 Correct 57 ms 5880 KB Output is correct
47 Correct 52 ms 5740 KB Output is correct
48 Correct 56 ms 5864 KB Output is correct
49 Correct 56 ms 5740 KB Output is correct
50 Correct 51 ms 5744 KB Output is correct
51 Correct 505 ms 23688 KB Output is correct
52 Correct 490 ms 23508 KB Output is correct
53 Correct 601 ms 23556 KB Output is correct
54 Correct 53 ms 5736 KB Output is correct
55 Correct 47 ms 5736 KB Output is correct
56 Correct 169 ms 15200 KB Output is correct
57 Correct 0 ms 384 KB Output is correct
58 Correct 54 ms 5736 KB Output is correct
59 Correct 54 ms 5736 KB Output is correct
60 Correct 618 ms 22356 KB Output is correct
61 Correct 53 ms 5740 KB Output is correct
62 Correct 56 ms 5736 KB Output is correct
63 Correct 58 ms 5740 KB Output is correct
64 Correct 59 ms 5736 KB Output is correct
65 Correct 54 ms 5740 KB Output is correct
66 Correct 57 ms 5772 KB Output is correct
67 Correct 53 ms 5736 KB Output is correct
68 Correct 53 ms 5740 KB Output is correct
69 Correct 56 ms 5740 KB Output is correct
70 Correct 556 ms 22520 KB Output is correct
71 Correct 54 ms 5736 KB Output is correct
72 Correct 502 ms 23520 KB Output is correct
73 Correct 505 ms 23768 KB Output is correct
74 Correct 0 ms 384 KB Output is correct
75 Correct 0 ms 384 KB Output is correct
76 Correct 0 ms 384 KB Output is correct
77 Correct 0 ms 384 KB Output is correct
78 Correct 0 ms 384 KB Output is correct
79 Correct 6 ms 1152 KB Output is correct
80 Correct 586 ms 23760 KB Output is correct
81 Correct 593 ms 23764 KB Output is correct
82 Correct 561 ms 23764 KB Output is correct
83 Correct 571 ms 23764 KB Output is correct
84 Correct 575 ms 23764 KB Output is correct
85 Correct 560 ms 23768 KB Output is correct
86 Correct 160 ms 15328 KB Output is correct
87 Correct 0 ms 384 KB Output is correct