Submission #369486

# Submission time Handle Problem Language Result Execution time Memory
369486 2021-02-21T18:41:57 Z ali_tavakoli Strange Device (APIO19_strange_device) C++14
100 / 100
667 ms 53492 KB
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define pb push_back
#define F first
#define S second
#define pll pair<ll, ll>
//#pragma GCC optimize("Ofast")

const int maxn = 1e6 + 5;
const ll inf = 1e18 + 5;

bool cmp(pll x, pll y)
{
    if(x.F != y.F)
        return x.F < y.F;
    return x.S > y.S;
}

ll n, A, B, g, ans;
vector<pll> seg;

int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> A >> B;
    g = A / __gcd(A, B + 1);
    if(inf / g < B)
        g = inf;
    else
        g = g * B;
    
    //cout << g << '\n';
    for(int i = 0; i < n; i++)
    {
        ll l, r;
        cin >> l >> r;
        if(r - l + 1 >= g)
            seg.pb({0, g - 1});
        else if(l % g <= r % g)
            seg.pb({l % g, r % g});
        else
        {
            seg.pb({l % g, g - 1});
            seg.pb({0, r % g});
        }
    }
    sort(seg.begin(), seg.end(), cmp);
    for(int i = 1; i < seg.size(); i++)
        if(seg[i].F <= seg[i - 1].S)
        {
            seg[i].F = min(seg[i].F, seg[i - 1].F);
            seg[i].S = max(seg[i].S, seg[i - 1].S);
            seg[i - 1] = {1, 0};
        }
    for(auto x : seg)
        ans += x.S - x.F + 1;
    //sort(seg.begin(), seg.end());
    cout << ans << '\n';
}

/*
3 3 3
4 4
7 9
17 18


3 5 10
1 20
50 68
89 98

2 16 13
2 5
18 18
*/

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:51:22: 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]
   51 |     for(int i = 1; i < seg.size(); i++)
      |                    ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 5 ms 1132 KB Output is correct
3 Correct 6 ms 1132 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 1140 KB Output is correct
17 Correct 60 ms 5732 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 375 ms 41404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 558 ms 53492 KB Output is correct
3 Correct 534 ms 53280 KB Output is correct
4 Correct 534 ms 53460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 558 ms 53492 KB Output is correct
3 Correct 534 ms 53280 KB Output is correct
4 Correct 534 ms 53460 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 535 ms 53308 KB Output is correct
7 Correct 551 ms 53308 KB Output is correct
8 Correct 535 ms 53308 KB Output is correct
9 Correct 611 ms 53436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 558 ms 53492 KB Output is correct
3 Correct 534 ms 53280 KB Output is correct
4 Correct 534 ms 53460 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 51 ms 5732 KB Output is correct
7 Correct 59 ms 5860 KB Output is correct
8 Correct 52 ms 5732 KB Output is correct
9 Correct 66 ms 5732 KB Output is correct
10 Correct 52 ms 5732 KB Output is correct
11 Correct 54 ms 5732 KB Output is correct
12 Correct 50 ms 5752 KB Output is correct
13 Correct 59 ms 5732 KB Output is correct
14 Correct 50 ms 5732 KB Output is correct
15 Correct 74 ms 5732 KB Output is correct
16 Correct 58 ms 5732 KB Output is correct
17 Correct 53 ms 5732 KB Output is correct
18 Correct 548 ms 53308 KB Output is correct
19 Correct 526 ms 53436 KB Output is correct
20 Correct 619 ms 53436 KB Output is correct
21 Correct 69 ms 5732 KB Output is correct
22 Correct 48 ms 5732 KB Output is correct
23 Correct 152 ms 18524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 58 ms 5732 KB Output is correct
3 Correct 58 ms 5732 KB Output is correct
4 Correct 644 ms 53308 KB Output is correct
5 Correct 62 ms 5864 KB Output is correct
6 Correct 56 ms 5732 KB Output is correct
7 Correct 56 ms 5732 KB Output is correct
8 Correct 61 ms 5732 KB Output is correct
9 Correct 55 ms 5732 KB Output is correct
10 Correct 67 ms 5732 KB Output is correct
11 Correct 60 ms 5732 KB Output is correct
12 Correct 48 ms 5732 KB Output is correct
13 Correct 57 ms 5732 KB Output is correct
14 Correct 630 ms 53308 KB Output is correct
15 Correct 56 ms 5732 KB Output is correct
16 Correct 572 ms 53404 KB Output is correct
17 Correct 531 ms 53308 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 5 ms 1132 KB Output is correct
3 Correct 6 ms 1132 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 1140 KB Output is correct
17 Correct 60 ms 5732 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 0 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 0 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 375 ms 41404 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 558 ms 53492 KB Output is correct
31 Correct 534 ms 53280 KB Output is correct
32 Correct 534 ms 53460 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 535 ms 53308 KB Output is correct
35 Correct 551 ms 53308 KB Output is correct
36 Correct 535 ms 53308 KB Output is correct
37 Correct 611 ms 53436 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 51 ms 5732 KB Output is correct
40 Correct 59 ms 5860 KB Output is correct
41 Correct 52 ms 5732 KB Output is correct
42 Correct 66 ms 5732 KB Output is correct
43 Correct 52 ms 5732 KB Output is correct
44 Correct 54 ms 5732 KB Output is correct
45 Correct 50 ms 5752 KB Output is correct
46 Correct 59 ms 5732 KB Output is correct
47 Correct 50 ms 5732 KB Output is correct
48 Correct 74 ms 5732 KB Output is correct
49 Correct 58 ms 5732 KB Output is correct
50 Correct 53 ms 5732 KB Output is correct
51 Correct 548 ms 53308 KB Output is correct
52 Correct 526 ms 53436 KB Output is correct
53 Correct 619 ms 53436 KB Output is correct
54 Correct 69 ms 5732 KB Output is correct
55 Correct 48 ms 5732 KB Output is correct
56 Correct 152 ms 18524 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 58 ms 5732 KB Output is correct
59 Correct 58 ms 5732 KB Output is correct
60 Correct 644 ms 53308 KB Output is correct
61 Correct 62 ms 5864 KB Output is correct
62 Correct 56 ms 5732 KB Output is correct
63 Correct 56 ms 5732 KB Output is correct
64 Correct 61 ms 5732 KB Output is correct
65 Correct 55 ms 5732 KB Output is correct
66 Correct 67 ms 5732 KB Output is correct
67 Correct 60 ms 5732 KB Output is correct
68 Correct 48 ms 5732 KB Output is correct
69 Correct 57 ms 5732 KB Output is correct
70 Correct 630 ms 53308 KB Output is correct
71 Correct 56 ms 5732 KB Output is correct
72 Correct 572 ms 53404 KB Output is correct
73 Correct 531 ms 53308 KB Output is correct
74 Correct 1 ms 364 KB Output is correct
75 Correct 1 ms 364 KB Output is correct
76 Correct 1 ms 364 KB Output is correct
77 Correct 1 ms 364 KB Output is correct
78 Correct 1 ms 364 KB Output is correct
79 Correct 6 ms 1260 KB Output is correct
80 Correct 646 ms 53308 KB Output is correct
81 Correct 667 ms 53368 KB Output is correct
82 Correct 639 ms 53328 KB Output is correct
83 Correct 664 ms 53392 KB Output is correct
84 Correct 630 ms 53352 KB Output is correct
85 Correct 618 ms 53328 KB Output is correct
86 Correct 150 ms 18524 KB Output is correct
87 Correct 1 ms 364 KB Output is correct