Submission #256828

# Submission time Handle Problem Language Result Execution time Memory
256828 2020-08-03T09:06:26 Z 2qbingxuan Strange Device (APIO19_strange_device) C++17
100 / 100
875 ms 48964 KB
//   __________________
//  | ________________ |
//  ||          ____  ||
//  ||   /\    |      ||
//  ||  /__\   |      ||
//  || /    \  |____  ||
//  ||________________||
//  |__________________|
//  \###################\
//   \###################\
//    \        ____       \
//     \_______\___\_______\
// An AC a day keeps the doctor away.

#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/extc++.h>
#ifdef local
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(...) qqbx(#__VA_ARGS__,  __VA_ARGS__)
template <typename H, typename ...T> constexpr void qqbx(const char *s, const H &h, T &&...args) {
    for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr << *s;
    std::cerr << " = " << h << (sizeof...(T) ? ", " : "\n");
    if constexpr(sizeof...(T)) qqbx(++s, args...); // C++ 17!
}
#else
#include <bits/stdc++.h>
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
#define all(v) begin(v),end(v)
#define get_pos(v,x) int(lower_bound(begin(v),end(v),x)-begin(v))
#define sort_uni(v) sort(begin(v),end(v)),v.erase(unique(begin(v),end(v)),end(v))
#define pb emplace_back
#define ff first
#define ss second
#define mem(v,x) memset(v,x,sizeof v)

using namespace std;
using namespace __gnu_pbds;
typedef int64_t ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
template <typename T> using max_heap = std::priority_queue<T,vector<T>,less<T> >;
template <typename T> using min_heap = std::priority_queue<T,vector<T>,greater<T> >;
template <typename T> using rbt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr ld PI = acos(-1), eps = 1e-9;
constexpr ll N = 1000325, INF = 2e18, MOD = 1000000007, K = 105, inf = 1e9;
constexpr inline ll cdiv(ll x, ll m) { return x/m + ((x<0 ^ m>0) && (x%m)); } // ceiling divide
constexpr inline ll modpow(ll e,ll p,ll m=MOD) { ll r=1; for(e%=m;p;p>>=1,e=e*e%m) if(p&1) r=r*e%m; return r; }

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    ll A, B;
    cin >> n >> A >> B;
    __int128 k = A / __gcd(A, B+1) * __int128(B);
    vector<pair<ll,int>> evt;
    for(int i = 0; i < n; i++) {
        ll l, r;
        cin >> l >> r;
        ++r;
        if(r-l >= k) return cout << ll(k) << '\n', 0;
        l %= k;
        r %= k;
        if(l < r)
            evt.pb(l, 1), evt.pb(r, -1);
        else
            evt.pb(0, 1), evt.pb(r, -1), evt.pb(l, 1), evt.pb(k, -1);
    }
    evt.pb(k, 0);
    sort(all(evt));
    ll ans = 0;
    for(int i = 0, j, c = 0; i < evt.size(); i = j) {
        for(j = i; j < evt.size(); j++) {
            if(evt[j].first != evt[i].first) break;
            c += evt[j].second;
        }
        if(c && j != evt.size()) ans += evt[j].first - evt[i].first;
    }
    cout << ans << '\n';
}

Compilation message

strange_device.cpp:9:1: warning: multi-line comment [-Wcomment]
 //  \###################\
 ^
strange_device.cpp:16:0: warning: ignoring #pragma loop_opt  [-Wunknown-pragmas]
 #pragma loop_opt(on)
 
strange_device.cpp: In function 'constexpr ll cdiv(ll, ll)':
strange_device.cpp:50:56: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
 constexpr inline ll cdiv(ll x, ll m) { return x/m + ((x<0 ^ m>0) && (x%m)); } // ceiling divide
                                                       ~^~
strange_device.cpp: In function 'int main()':
strange_device.cpp:75:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0, j, c = 0; i < evt.size(); i = j) {
                              ~~^~~~~~~~~~~~
strange_device.cpp:76:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(j = i; j < evt.size(); j++) {
                    ~~^~~~~~~~~~~~
strange_device.cpp:80:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(c && j != evt.size()) ans += evt[j].first - evt[i].first;
                 ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 7 ms 1152 KB Output is correct
3 Correct 7 ms 1152 KB Output is correct
4 Correct 0 ms 388 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 308 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 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 74 ms 4976 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 0 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 451 ms 33412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 648 ms 33308 KB Output is correct
3 Correct 700 ms 33344 KB Output is correct
4 Correct 625 ms 33344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 648 ms 33308 KB Output is correct
3 Correct 700 ms 33344 KB Output is correct
4 Correct 625 ms 33344 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 662 ms 33344 KB Output is correct
7 Correct 649 ms 33348 KB Output is correct
8 Correct 645 ms 33476 KB Output is correct
9 Correct 779 ms 33360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 648 ms 33308 KB Output is correct
3 Correct 700 ms 33344 KB Output is correct
4 Correct 625 ms 33344 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 75 ms 4836 KB Output is correct
7 Correct 68 ms 4844 KB Output is correct
8 Correct 61 ms 4844 KB Output is correct
9 Correct 66 ms 4844 KB Output is correct
10 Correct 60 ms 4844 KB Output is correct
11 Correct 70 ms 4848 KB Output is correct
12 Correct 63 ms 4844 KB Output is correct
13 Correct 73 ms 4872 KB Output is correct
14 Correct 60 ms 4844 KB Output is correct
15 Correct 70 ms 4844 KB Output is correct
16 Correct 82 ms 4816 KB Output is correct
17 Correct 84 ms 4876 KB Output is correct
18 Correct 665 ms 33344 KB Output is correct
19 Correct 669 ms 33376 KB Output is correct
20 Correct 858 ms 33568 KB Output is correct
21 Correct 76 ms 4852 KB Output is correct
22 Correct 66 ms 4848 KB Output is correct
23 Correct 201 ms 17088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 70 ms 4972 KB Output is correct
3 Correct 78 ms 4840 KB Output is correct
4 Correct 829 ms 33344 KB Output is correct
5 Correct 74 ms 4892 KB Output is correct
6 Correct 74 ms 4840 KB Output is correct
7 Correct 73 ms 4840 KB Output is correct
8 Correct 75 ms 4844 KB Output is correct
9 Correct 71 ms 4976 KB Output is correct
10 Correct 75 ms 4844 KB Output is correct
11 Correct 72 ms 4836 KB Output is correct
12 Correct 64 ms 4872 KB Output is correct
13 Correct 76 ms 4852 KB Output is correct
14 Correct 798 ms 33368 KB Output is correct
15 Correct 76 ms 4840 KB Output is correct
16 Correct 660 ms 33580 KB Output is correct
17 Correct 639 ms 33644 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 7 ms 1152 KB Output is correct
3 Correct 7 ms 1152 KB Output is correct
4 Correct 0 ms 388 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 308 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 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 74 ms 4976 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 0 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 451 ms 33412 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 648 ms 33308 KB Output is correct
31 Correct 700 ms 33344 KB Output is correct
32 Correct 625 ms 33344 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 662 ms 33344 KB Output is correct
35 Correct 649 ms 33348 KB Output is correct
36 Correct 645 ms 33476 KB Output is correct
37 Correct 779 ms 33360 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 75 ms 4836 KB Output is correct
40 Correct 68 ms 4844 KB Output is correct
41 Correct 61 ms 4844 KB Output is correct
42 Correct 66 ms 4844 KB Output is correct
43 Correct 60 ms 4844 KB Output is correct
44 Correct 70 ms 4848 KB Output is correct
45 Correct 63 ms 4844 KB Output is correct
46 Correct 73 ms 4872 KB Output is correct
47 Correct 60 ms 4844 KB Output is correct
48 Correct 70 ms 4844 KB Output is correct
49 Correct 82 ms 4816 KB Output is correct
50 Correct 84 ms 4876 KB Output is correct
51 Correct 665 ms 33344 KB Output is correct
52 Correct 669 ms 33376 KB Output is correct
53 Correct 858 ms 33568 KB Output is correct
54 Correct 76 ms 4852 KB Output is correct
55 Correct 66 ms 4848 KB Output is correct
56 Correct 201 ms 17088 KB Output is correct
57 Correct 1 ms 384 KB Output is correct
58 Correct 70 ms 4972 KB Output is correct
59 Correct 78 ms 4840 KB Output is correct
60 Correct 829 ms 33344 KB Output is correct
61 Correct 74 ms 4892 KB Output is correct
62 Correct 74 ms 4840 KB Output is correct
63 Correct 73 ms 4840 KB Output is correct
64 Correct 75 ms 4844 KB Output is correct
65 Correct 71 ms 4976 KB Output is correct
66 Correct 75 ms 4844 KB Output is correct
67 Correct 72 ms 4836 KB Output is correct
68 Correct 64 ms 4872 KB Output is correct
69 Correct 76 ms 4852 KB Output is correct
70 Correct 798 ms 33368 KB Output is correct
71 Correct 76 ms 4840 KB Output is correct
72 Correct 660 ms 33580 KB Output is correct
73 Correct 639 ms 33644 KB Output is correct
74 Correct 0 ms 384 KB Output is correct
75 Correct 1 ms 384 KB Output is correct
76 Correct 0 ms 384 KB Output is correct
77 Correct 1 ms 384 KB Output is correct
78 Correct 0 ms 384 KB Output is correct
79 Correct 9 ms 1432 KB Output is correct
80 Correct 832 ms 48964 KB Output is correct
81 Correct 830 ms 48960 KB Output is correct
82 Correct 875 ms 48960 KB Output is correct
83 Correct 778 ms 48960 KB Output is correct
84 Correct 831 ms 48960 KB Output is correct
85 Correct 791 ms 48960 KB Output is correct
86 Correct 211 ms 26796 KB Output is correct
87 Correct 1 ms 384 KB Output is correct