Submission #468449

# Submission time Handle Problem Language Result Execution time Memory
468449 2021-08-28T10:57:46 Z Killer2501 Strange Device (APIO19_strange_device) C++14
100 / 100
618 ms 92432 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define task "tests"
#define pll pair<ll, ll>
#define pi pair<ll, pll>
#define fi first
#define se second

using namespace std;
const ll mod = 1e18+7;
const ll N = 1e6+5;
const int base = 313;
ll n, m, t, k, T, ans, tong, c[N], a[N], b[N], h[N];
vector<pll> adj[N], kq;
ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n & 1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}

void sol()
{
    ll A, B;
    cin >> n >> A >> B;
    A /= __gcd(A, B+1);
    if(A > mod / B)tong = mod;
    else tong = A * B;
    for(int i = 0; i < n; i ++)
    {
        cin >> a[i] >> b[i];
        if(b[i]-a[i]+1 >= tong)
        {
            cout << tong;
            return;
        }
        a[i] %= tong;
        b[i] %= tong;
        if(a[i] <= b[i])kq.pb({a[i], b[i]});
        else
        {
            kq.pb({0, b[i]});
            kq.pb({a[i], tong-1});
        }
    }
    sort(kq.begin(), kq.end());
    ll l = kq[0].fi, r = kq[0].se;
    ans = r-l+1;
    for(int i = 1; i < kq.size(); i ++)
    {
        if(kq[i].fi > r)
        {
            ans += kq[i].se - kq[i].fi + 1;
            l = kq[i].fi;
            r = kq[i].se;
        }
        else
        {
            ans += max(0ll, kq[i].se-r);
            r = max(kq[i].se, r);
        }
    }
    cout << ans;
}
int main()
{
    if(fopen(task".in", "r"))
    {
       freopen(task".in", "r", stdin);
       freopen(task".out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}
/*
5 1
0 1 2
0 2 3
1 3 5
2 4 6
1 1
4 3
*/

Compilation message

strange_device.cpp: In function 'void sol()':
strange_device.cpp:54: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]
   54 |     for(int i = 1; i < kq.size(); i ++)
      |                    ~~^~~~~~~~~~~
strange_device.cpp: In function 'int main()':
strange_device.cpp:74:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |        freopen(task".in", "r", stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:75:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |        freopen(task".out", "w", stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23756 KB Output is correct
2 Correct 18 ms 24304 KB Output is correct
3 Correct 21 ms 24272 KB Output is correct
4 Correct 13 ms 23756 KB Output is correct
5 Correct 13 ms 23816 KB Output is correct
6 Correct 13 ms 23820 KB Output is correct
7 Correct 14 ms 23912 KB Output is correct
8 Correct 13 ms 23756 KB Output is correct
9 Correct 13 ms 23744 KB Output is correct
10 Correct 13 ms 23756 KB Output is correct
11 Correct 13 ms 23756 KB Output is correct
12 Correct 13 ms 23760 KB Output is correct
13 Correct 13 ms 23816 KB Output is correct
14 Correct 14 ms 23756 KB Output is correct
15 Correct 14 ms 23756 KB Output is correct
16 Correct 18 ms 24352 KB Output is correct
17 Correct 67 ms 27032 KB Output is correct
18 Correct 14 ms 23756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23772 KB Output is correct
2 Correct 14 ms 23812 KB Output is correct
3 Correct 14 ms 23756 KB Output is correct
4 Correct 13 ms 23792 KB Output is correct
5 Correct 13 ms 23756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23740 KB Output is correct
2 Correct 15 ms 23756 KB Output is correct
3 Correct 14 ms 23800 KB Output is correct
4 Correct 15 ms 23808 KB Output is correct
5 Correct 385 ms 70312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 531 ms 77304 KB Output is correct
3 Correct 513 ms 92356 KB Output is correct
4 Correct 542 ms 92344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 531 ms 77304 KB Output is correct
3 Correct 513 ms 92356 KB Output is correct
4 Correct 542 ms 92344 KB Output is correct
5 Correct 16 ms 23804 KB Output is correct
6 Correct 557 ms 92424 KB Output is correct
7 Correct 540 ms 92400 KB Output is correct
8 Correct 520 ms 92348 KB Output is correct
9 Correct 561 ms 92432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 531 ms 77304 KB Output is correct
3 Correct 513 ms 92356 KB Output is correct
4 Correct 542 ms 92344 KB Output is correct
5 Correct 15 ms 23752 KB Output is correct
6 Correct 72 ms 30728 KB Output is correct
7 Correct 81 ms 30688 KB Output is correct
8 Correct 68 ms 30808 KB Output is correct
9 Correct 66 ms 30776 KB Output is correct
10 Correct 69 ms 30700 KB Output is correct
11 Correct 66 ms 30748 KB Output is correct
12 Correct 64 ms 30708 KB Output is correct
13 Correct 66 ms 30748 KB Output is correct
14 Correct 65 ms 30716 KB Output is correct
15 Correct 68 ms 30776 KB Output is correct
16 Correct 68 ms 30724 KB Output is correct
17 Correct 67 ms 30796 KB Output is correct
18 Correct 531 ms 92296 KB Output is correct
19 Correct 544 ms 92248 KB Output is correct
20 Correct 613 ms 91784 KB Output is correct
21 Correct 85 ms 30780 KB Output is correct
22 Correct 66 ms 30760 KB Output is correct
23 Correct 174 ms 47228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23756 KB Output is correct
2 Correct 69 ms 27040 KB Output is correct
3 Correct 74 ms 26980 KB Output is correct
4 Correct 618 ms 77256 KB Output is correct
5 Correct 67 ms 30780 KB Output is correct
6 Correct 69 ms 30700 KB Output is correct
7 Correct 67 ms 30788 KB Output is correct
8 Correct 68 ms 30772 KB Output is correct
9 Correct 65 ms 30780 KB Output is correct
10 Correct 69 ms 30732 KB Output is correct
11 Correct 83 ms 30752 KB Output is correct
12 Correct 63 ms 30768 KB Output is correct
13 Correct 68 ms 30708 KB Output is correct
14 Correct 588 ms 92120 KB Output is correct
15 Correct 68 ms 30752 KB Output is correct
16 Correct 613 ms 92288 KB Output is correct
17 Correct 531 ms 91988 KB Output is correct
18 Correct 16 ms 23756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23756 KB Output is correct
2 Correct 18 ms 24304 KB Output is correct
3 Correct 21 ms 24272 KB Output is correct
4 Correct 13 ms 23756 KB Output is correct
5 Correct 13 ms 23816 KB Output is correct
6 Correct 13 ms 23820 KB Output is correct
7 Correct 14 ms 23912 KB Output is correct
8 Correct 13 ms 23756 KB Output is correct
9 Correct 13 ms 23744 KB Output is correct
10 Correct 13 ms 23756 KB Output is correct
11 Correct 13 ms 23756 KB Output is correct
12 Correct 13 ms 23760 KB Output is correct
13 Correct 13 ms 23816 KB Output is correct
14 Correct 14 ms 23756 KB Output is correct
15 Correct 14 ms 23756 KB Output is correct
16 Correct 18 ms 24352 KB Output is correct
17 Correct 67 ms 27032 KB Output is correct
18 Correct 14 ms 23756 KB Output is correct
19 Correct 14 ms 23772 KB Output is correct
20 Correct 14 ms 23812 KB Output is correct
21 Correct 14 ms 23756 KB Output is correct
22 Correct 13 ms 23792 KB Output is correct
23 Correct 13 ms 23756 KB Output is correct
24 Correct 16 ms 23740 KB Output is correct
25 Correct 15 ms 23756 KB Output is correct
26 Correct 14 ms 23800 KB Output is correct
27 Correct 15 ms 23808 KB Output is correct
28 Correct 385 ms 70312 KB Output is correct
29 Correct 13 ms 23756 KB Output is correct
30 Correct 531 ms 77304 KB Output is correct
31 Correct 513 ms 92356 KB Output is correct
32 Correct 542 ms 92344 KB Output is correct
33 Correct 16 ms 23804 KB Output is correct
34 Correct 557 ms 92424 KB Output is correct
35 Correct 540 ms 92400 KB Output is correct
36 Correct 520 ms 92348 KB Output is correct
37 Correct 561 ms 92432 KB Output is correct
38 Correct 15 ms 23752 KB Output is correct
39 Correct 72 ms 30728 KB Output is correct
40 Correct 81 ms 30688 KB Output is correct
41 Correct 68 ms 30808 KB Output is correct
42 Correct 66 ms 30776 KB Output is correct
43 Correct 69 ms 30700 KB Output is correct
44 Correct 66 ms 30748 KB Output is correct
45 Correct 64 ms 30708 KB Output is correct
46 Correct 66 ms 30748 KB Output is correct
47 Correct 65 ms 30716 KB Output is correct
48 Correct 68 ms 30776 KB Output is correct
49 Correct 68 ms 30724 KB Output is correct
50 Correct 67 ms 30796 KB Output is correct
51 Correct 531 ms 92296 KB Output is correct
52 Correct 544 ms 92248 KB Output is correct
53 Correct 613 ms 91784 KB Output is correct
54 Correct 85 ms 30780 KB Output is correct
55 Correct 66 ms 30760 KB Output is correct
56 Correct 174 ms 47228 KB Output is correct
57 Correct 17 ms 23756 KB Output is correct
58 Correct 69 ms 27040 KB Output is correct
59 Correct 74 ms 26980 KB Output is correct
60 Correct 618 ms 77256 KB Output is correct
61 Correct 67 ms 30780 KB Output is correct
62 Correct 69 ms 30700 KB Output is correct
63 Correct 67 ms 30788 KB Output is correct
64 Correct 68 ms 30772 KB Output is correct
65 Correct 65 ms 30780 KB Output is correct
66 Correct 69 ms 30732 KB Output is correct
67 Correct 83 ms 30752 KB Output is correct
68 Correct 63 ms 30768 KB Output is correct
69 Correct 68 ms 30708 KB Output is correct
70 Correct 588 ms 92120 KB Output is correct
71 Correct 68 ms 30752 KB Output is correct
72 Correct 613 ms 92288 KB Output is correct
73 Correct 531 ms 91988 KB Output is correct
74 Correct 16 ms 23756 KB Output is correct
75 Correct 16 ms 23704 KB Output is correct
76 Correct 15 ms 23804 KB Output is correct
77 Correct 15 ms 23756 KB Output is correct
78 Correct 16 ms 23716 KB Output is correct
79 Correct 20 ms 24652 KB Output is correct
80 Correct 615 ms 71652 KB Output is correct
81 Correct 617 ms 71460 KB Output is correct
82 Correct 568 ms 71876 KB Output is correct
83 Correct 573 ms 72784 KB Output is correct
84 Correct 585 ms 72396 KB Output is correct
85 Correct 572 ms 73176 KB Output is correct
86 Correct 181 ms 47012 KB Output is correct
87 Correct 16 ms 23756 KB Output is correct