Submission #211605

# Submission time Handle Problem Language Result Execution time Memory
211605 2020-03-20T19:23:51 Z devid Strange Device (APIO19_strange_device) C++17
100 / 100
808 ms 47552 KB
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
 
#include <bits/stdc++.h>
 
#define int ll
//#define double long double
#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair 
#define pb emplace_back
#define dbg(x) cerr << #x << " : " << x << endl
//#define PI 3.141592653589
 
using namespace std;
        
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;
using pld = pair <ld, ld>;

/*
const ll MAX_MEM = 4e8;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
*/
        
template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}
        
template <class T> 
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}
        
template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}
        
template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}
        
inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen("lol.in", "r", stdin);
    //freopen("lol.out", "w", stdout);
}

const int OPEN = 0, CLOSE = 1;
struct event
{
    int x, t;
    event() {}
    event(int x, int t) : x(x), t(t) {}
};

signed main()
{
    Start();
    int n, a, b;
    cin >> n >> a >> b;
    int k = a / gcd(a, b + 1);
    int t = k * b;
    vector <event> e;
    for (int i = 0; i < n; ++i)
    {
        int l, r;
        cin >> l >> r;
        if (l / t == r / t)
        {
            e.pb(l % t, OPEN);
            e.pb(r % t + 1, CLOSE);
            continue;
        }
        if (l / t + 1 == r / t)
        {
            if (r - l + 1 < t)
            {
                e.pb(l % t, OPEN);
                e.pb(t, CLOSE);
                e.pb(0, OPEN);
                e.pb(r % t + 1, CLOSE);
                continue;
            }
        }
        cout << t;
        return 0;
    }
    sort(all(e), [] (event a, event b) {return a.x < b.x || (a.x == b.x && a.t < b.t);});
    int lst = -1, bal = 0, ans = 0;
    for (auto f : e)
    {
        if (f.t == OPEN)
        {
            ++bal;
            if (bal == 1)
                lst = f.x;
        }
        else
        {
            --bal;
            if (!bal)
            {
                ans += f.x - lst;
            }
        }
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 13 ms 1408 KB Output is correct
3 Correct 11 ms 1408 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 11 ms 1400 KB Output is correct
17 Correct 82 ms 7272 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 492 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 420 ms 46528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 623 ms 47384 KB Output is correct
3 Correct 667 ms 47188 KB Output is correct
4 Correct 616 ms 47296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 623 ms 47384 KB Output is correct
3 Correct 667 ms 47188 KB Output is correct
4 Correct 616 ms 47296 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 659 ms 47552 KB Output is correct
7 Correct 646 ms 47432 KB Output is correct
8 Correct 641 ms 47276 KB Output is correct
9 Correct 720 ms 47168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 623 ms 47384 KB Output is correct
3 Correct 667 ms 47188 KB Output is correct
4 Correct 616 ms 47296 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 65 ms 7276 KB Output is correct
7 Correct 69 ms 7276 KB Output is correct
8 Correct 62 ms 7396 KB Output is correct
9 Correct 63 ms 7272 KB Output is correct
10 Correct 63 ms 7404 KB Output is correct
11 Correct 68 ms 7276 KB Output is correct
12 Correct 63 ms 7276 KB Output is correct
13 Correct 71 ms 7276 KB Output is correct
14 Correct 62 ms 7276 KB Output is correct
15 Correct 75 ms 7276 KB Output is correct
16 Correct 74 ms 7392 KB Output is correct
17 Correct 65 ms 7396 KB Output is correct
18 Correct 646 ms 47292 KB Output is correct
19 Correct 609 ms 47296 KB Output is correct
20 Correct 739 ms 47404 KB Output is correct
21 Correct 75 ms 7276 KB Output is correct
22 Correct 64 ms 7272 KB Output is correct
23 Correct 187 ms 26904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 73 ms 7348 KB Output is correct
3 Correct 76 ms 7264 KB Output is correct
4 Correct 792 ms 47168 KB Output is correct
5 Correct 75 ms 7396 KB Output is correct
6 Correct 77 ms 7396 KB Output is correct
7 Correct 71 ms 7272 KB Output is correct
8 Correct 75 ms 7396 KB Output is correct
9 Correct 71 ms 7276 KB Output is correct
10 Correct 76 ms 7400 KB Output is correct
11 Correct 77 ms 7396 KB Output is correct
12 Correct 69 ms 7272 KB Output is correct
13 Correct 79 ms 7276 KB Output is correct
14 Correct 763 ms 47288 KB Output is correct
15 Correct 76 ms 7272 KB Output is correct
16 Correct 631 ms 47328 KB Output is correct
17 Correct 655 ms 47292 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 13 ms 1408 KB Output is correct
3 Correct 11 ms 1408 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 11 ms 1400 KB Output is correct
17 Correct 82 ms 7272 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 492 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 4 ms 384 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 504 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 420 ms 46528 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 623 ms 47384 KB Output is correct
31 Correct 667 ms 47188 KB Output is correct
32 Correct 616 ms 47296 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 659 ms 47552 KB Output is correct
35 Correct 646 ms 47432 KB Output is correct
36 Correct 641 ms 47276 KB Output is correct
37 Correct 720 ms 47168 KB Output is correct
38 Correct 4 ms 384 KB Output is correct
39 Correct 65 ms 7276 KB Output is correct
40 Correct 69 ms 7276 KB Output is correct
41 Correct 62 ms 7396 KB Output is correct
42 Correct 63 ms 7272 KB Output is correct
43 Correct 63 ms 7404 KB Output is correct
44 Correct 68 ms 7276 KB Output is correct
45 Correct 63 ms 7276 KB Output is correct
46 Correct 71 ms 7276 KB Output is correct
47 Correct 62 ms 7276 KB Output is correct
48 Correct 75 ms 7276 KB Output is correct
49 Correct 74 ms 7392 KB Output is correct
50 Correct 65 ms 7396 KB Output is correct
51 Correct 646 ms 47292 KB Output is correct
52 Correct 609 ms 47296 KB Output is correct
53 Correct 739 ms 47404 KB Output is correct
54 Correct 75 ms 7276 KB Output is correct
55 Correct 64 ms 7272 KB Output is correct
56 Correct 187 ms 26904 KB Output is correct
57 Correct 4 ms 384 KB Output is correct
58 Correct 73 ms 7348 KB Output is correct
59 Correct 76 ms 7264 KB Output is correct
60 Correct 792 ms 47168 KB Output is correct
61 Correct 75 ms 7396 KB Output is correct
62 Correct 77 ms 7396 KB Output is correct
63 Correct 71 ms 7272 KB Output is correct
64 Correct 75 ms 7396 KB Output is correct
65 Correct 71 ms 7276 KB Output is correct
66 Correct 76 ms 7400 KB Output is correct
67 Correct 77 ms 7396 KB Output is correct
68 Correct 69 ms 7272 KB Output is correct
69 Correct 79 ms 7276 KB Output is correct
70 Correct 763 ms 47288 KB Output is correct
71 Correct 76 ms 7272 KB Output is correct
72 Correct 631 ms 47328 KB Output is correct
73 Correct 655 ms 47292 KB Output is correct
74 Correct 5 ms 384 KB Output is correct
75 Correct 5 ms 384 KB Output is correct
76 Correct 4 ms 384 KB Output is correct
77 Correct 5 ms 384 KB Output is correct
78 Correct 4 ms 384 KB Output is correct
79 Correct 10 ms 1408 KB Output is correct
80 Correct 797 ms 47388 KB Output is correct
81 Correct 808 ms 47420 KB Output is correct
82 Correct 737 ms 47552 KB Output is correct
83 Correct 731 ms 47292 KB Output is correct
84 Correct 742 ms 47296 KB Output is correct
85 Correct 716 ms 47296 KB Output is correct
86 Correct 179 ms 26708 KB Output is correct
87 Correct 5 ms 384 KB Output is correct