Submission #137000

# Submission time Handle Problem Language Result Execution time Memory
137000 2019-07-26T20:53:29 Z nikolapesic2802 Strange Device (APIO19_strange_device) C++14
100 / 100
888 ms 34964 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define D(x) cerr << #x << " is " << (x) << "\n";
#define ld long double

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}

int n;
ll a,b;
ll nzd(ll aa,ll bb)
{
    if(bb==0)
        return aa;
    return nzd(bb,aa%bb);
}
int main()
{
    scanf("%i %lld %lld",&n,&a,&b);
    ll z=a/nzd(a,b+1);
    ll first=LLONG_MAX;
    if(LLONG_MAX/z>b)
        first=z*b;
    vector<pair<ll,int> > events;
    for(int i=0;i<n;i++)
    {
        ll l,r;
        scanf("%lld %lld",&l,&r);
        if(r-l+1>=first)
        {
            printf("%lld\n",first);
            return 0;
        }
        l%=first;
        r%=first;
        events.pb({l,1});
        events.pb({r+1,-1});
        if(l>r)
            events.pb({first,-1}),events.pb({0,1});
    }
    int cnt=0;
    ll last=0,ans=0;
    sort(all(events));
    for(auto p:events)
    {
        if(cnt)
            ans+=p.f-last;
        cnt+=p.s;
        last=p.f;
    }
    printf("%lld\n",ans);
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i %lld %lld",&n,&a,&b);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld",&l,&r);
         ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 9 ms 968 KB Output is correct
3 Correct 9 ms 1008 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 312 KB Output is correct
16 Correct 8 ms 1012 KB Output is correct
17 Correct 78 ms 4552 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 0 ms 376 KB Output is correct
5 Correct 521 ms 33312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 676 ms 34452 KB Output is correct
3 Correct 728 ms 33696 KB Output is correct
4 Correct 684 ms 34832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 676 ms 34452 KB Output is correct
3 Correct 728 ms 33696 KB Output is correct
4 Correct 684 ms 34832 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 707 ms 34844 KB Output is correct
7 Correct 674 ms 34876 KB Output is correct
8 Correct 697 ms 34832 KB Output is correct
9 Correct 812 ms 34876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 676 ms 34452 KB Output is correct
3 Correct 728 ms 33696 KB Output is correct
4 Correct 684 ms 34832 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 68 ms 7144 KB Output is correct
7 Correct 72 ms 7284 KB Output is correct
8 Correct 69 ms 7140 KB Output is correct
9 Correct 73 ms 7268 KB Output is correct
10 Correct 65 ms 7140 KB Output is correct
11 Correct 72 ms 7244 KB Output is correct
12 Correct 69 ms 7268 KB Output is correct
13 Correct 81 ms 7260 KB Output is correct
14 Correct 67 ms 6868 KB Output is correct
15 Correct 81 ms 6748 KB Output is correct
16 Correct 78 ms 6748 KB Output is correct
17 Correct 74 ms 6756 KB Output is correct
18 Correct 715 ms 34772 KB Output is correct
19 Correct 664 ms 34964 KB Output is correct
20 Correct 864 ms 34928 KB Output is correct
21 Correct 81 ms 6760 KB Output is correct
22 Correct 64 ms 7012 KB Output is correct
23 Correct 234 ms 22784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 77 ms 6568 KB Output is correct
3 Correct 77 ms 6628 KB Output is correct
4 Correct 883 ms 34832 KB Output is correct
5 Correct 77 ms 6748 KB Output is correct
6 Correct 78 ms 6752 KB Output is correct
7 Correct 80 ms 6900 KB Output is correct
8 Correct 84 ms 6884 KB Output is correct
9 Correct 80 ms 7140 KB Output is correct
10 Correct 80 ms 7112 KB Output is correct
11 Correct 77 ms 7012 KB Output is correct
12 Correct 73 ms 6884 KB Output is correct
13 Correct 81 ms 6948 KB Output is correct
14 Correct 788 ms 34916 KB Output is correct
15 Correct 80 ms 7004 KB Output is correct
16 Correct 653 ms 34748 KB Output is correct
17 Correct 700 ms 34848 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 9 ms 968 KB Output is correct
3 Correct 9 ms 1008 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 312 KB Output is correct
16 Correct 8 ms 1012 KB Output is correct
17 Correct 78 ms 4552 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 256 KB Output is correct
24 Correct 2 ms 252 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 0 ms 376 KB Output is correct
28 Correct 521 ms 33312 KB Output is correct
29 Correct 2 ms 348 KB Output is correct
30 Correct 676 ms 34452 KB Output is correct
31 Correct 728 ms 33696 KB Output is correct
32 Correct 684 ms 34832 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 707 ms 34844 KB Output is correct
35 Correct 674 ms 34876 KB Output is correct
36 Correct 697 ms 34832 KB Output is correct
37 Correct 812 ms 34876 KB Output is correct
38 Correct 2 ms 256 KB Output is correct
39 Correct 68 ms 7144 KB Output is correct
40 Correct 72 ms 7284 KB Output is correct
41 Correct 69 ms 7140 KB Output is correct
42 Correct 73 ms 7268 KB Output is correct
43 Correct 65 ms 7140 KB Output is correct
44 Correct 72 ms 7244 KB Output is correct
45 Correct 69 ms 7268 KB Output is correct
46 Correct 81 ms 7260 KB Output is correct
47 Correct 67 ms 6868 KB Output is correct
48 Correct 81 ms 6748 KB Output is correct
49 Correct 78 ms 6748 KB Output is correct
50 Correct 74 ms 6756 KB Output is correct
51 Correct 715 ms 34772 KB Output is correct
52 Correct 664 ms 34964 KB Output is correct
53 Correct 864 ms 34928 KB Output is correct
54 Correct 81 ms 6760 KB Output is correct
55 Correct 64 ms 7012 KB Output is correct
56 Correct 234 ms 22784 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 77 ms 6568 KB Output is correct
59 Correct 77 ms 6628 KB Output is correct
60 Correct 883 ms 34832 KB Output is correct
61 Correct 77 ms 6748 KB Output is correct
62 Correct 78 ms 6752 KB Output is correct
63 Correct 80 ms 6900 KB Output is correct
64 Correct 84 ms 6884 KB Output is correct
65 Correct 80 ms 7140 KB Output is correct
66 Correct 80 ms 7112 KB Output is correct
67 Correct 77 ms 7012 KB Output is correct
68 Correct 73 ms 6884 KB Output is correct
69 Correct 81 ms 6948 KB Output is correct
70 Correct 788 ms 34916 KB Output is correct
71 Correct 80 ms 7004 KB Output is correct
72 Correct 653 ms 34748 KB Output is correct
73 Correct 700 ms 34848 KB Output is correct
74 Correct 2 ms 256 KB Output is correct
75 Correct 2 ms 256 KB Output is correct
76 Correct 3 ms 368 KB Output is correct
77 Correct 2 ms 368 KB Output is correct
78 Correct 2 ms 396 KB Output is correct
79 Correct 9 ms 1268 KB Output is correct
80 Correct 881 ms 34812 KB Output is correct
81 Correct 888 ms 34772 KB Output is correct
82 Correct 845 ms 34692 KB Output is correct
83 Correct 786 ms 34620 KB Output is correct
84 Correct 803 ms 34568 KB Output is correct
85 Correct 819 ms 34724 KB Output is correct
86 Correct 230 ms 20324 KB Output is correct
87 Correct 2 ms 296 KB Output is correct