Submission #258897

# Submission time Handle Problem Language Result Execution time Memory
258897 2020-08-06T17:17:57 Z AM1648 Strange Device (APIO19_strange_device) C++17
65 / 100
1066 ms 68088 KB
/* be name khoda */

#define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <vector>
#include <fstream>
#include <set>
#include <map>
using namespace std;

#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

#define forifrom(i, s, n) for (ll i = s; i < n; ++i)
#define forirto(i, n, e) for (ll i = (n) - 1; i >= e; --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl

const ll MOD = 1000000007;
const long long BIG = 1446803456761533460LL;

#define XL (x << 1)
#define XR (XL | 1)
#define MD ((l + r) >> 1)
#define Add(a, b) a = ((a) + (b)) % MOD
#define Mul(a, b) a = (1LL * (a) * (b)) % MOD

// -----------------------------------------------------------------------

const ll maxn = 1000010;
const ll maxa = 2000000000000000000;

ll n, A, B, g, m;
map<ll, ll> seg;

void add(ll l, ll r) {
    seg[l]++;
    seg[r]--;
    if (l >= r) {
        seg[0]++;
        seg[m]--;
    }
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n >> A >> B;
    g = gcd(A, B + 1);
    m = A / g;
    if (B > maxa / m + 1) m = maxa;
    else m *= B;
    fori (i, n) {
        ll l, r; cin >> l >> r; ++r;
        add(l % m, r % m);
    }
    ll ans = 0;
    ll lst = 0, ps = 0;
    for (auto [x, v] : seg) {
        if (ps) ans += x - lst;
        lst = x, ps += v;
    }
    cout << ans << '\n';

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 7 ms 1408 KB Output is correct
3 Correct 7 ms 1408 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 512 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 7 ms 1408 KB Output is correct
17 Correct 91 ms 10360 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 314 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 802 ms 67900 KB Output is correct
3 Correct 827 ms 67952 KB Output is correct
4 Correct 1066 ms 67960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 802 ms 67900 KB Output is correct
3 Correct 827 ms 67952 KB Output is correct
4 Correct 1066 ms 67960 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 816 ms 68032 KB Output is correct
7 Correct 834 ms 67908 KB Output is correct
8 Correct 813 ms 68088 KB Output is correct
9 Correct 890 ms 68088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 802 ms 67900 KB Output is correct
3 Correct 827 ms 67952 KB Output is correct
4 Correct 1066 ms 67960 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 71 ms 10384 KB Output is correct
7 Correct 72 ms 10360 KB Output is correct
8 Correct 74 ms 10360 KB Output is correct
9 Correct 78 ms 10360 KB Output is correct
10 Correct 69 ms 10360 KB Output is correct
11 Correct 69 ms 10360 KB Output is correct
12 Correct 74 ms 10360 KB Output is correct
13 Correct 82 ms 10488 KB Output is correct
14 Correct 69 ms 10360 KB Output is correct
15 Correct 82 ms 10360 KB Output is correct
16 Correct 85 ms 10360 KB Output is correct
17 Correct 82 ms 10360 KB Output is correct
18 Correct 787 ms 68000 KB Output is correct
19 Correct 865 ms 67960 KB Output is correct
20 Correct 887 ms 67960 KB Output is correct
21 Correct 83 ms 10360 KB Output is correct
22 Correct 72 ms 10360 KB Output is correct
23 Correct 150 ms 12920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 90 ms 10360 KB Output is correct
3 Correct 83 ms 10360 KB Output is correct
4 Correct 862 ms 67996 KB Output is correct
5 Correct 87 ms 10360 KB Output is correct
6 Correct 95 ms 10364 KB Output is correct
7 Correct 90 ms 10360 KB Output is correct
8 Correct 88 ms 10360 KB Output is correct
9 Correct 80 ms 10360 KB Output is correct
10 Correct 75 ms 10360 KB Output is correct
11 Correct 79 ms 10360 KB Output is correct
12 Correct 84 ms 10360 KB Output is correct
13 Correct 87 ms 10344 KB Output is correct
14 Correct 916 ms 67912 KB Output is correct
15 Correct 84 ms 10360 KB Output is correct
16 Correct 818 ms 68080 KB Output is correct
17 Correct 810 ms 67908 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 7 ms 1408 KB Output is correct
3 Correct 7 ms 1408 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 512 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 7 ms 1408 KB Output is correct
17 Correct 91 ms 10360 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Incorrect 0 ms 384 KB Output isn't correct
21 Halted 0 ms 0 KB -