Submission #240345

# Submission time Handle Problem Language Result Execution time Memory
240345 2020-06-19T13:25:08 Z valerikk Strange Device (APIO19_strange_device) C++14
20 / 100
5000 ms 524292 KB
#include<bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define f(i, n) for (int i = 0; i < (n); i++)

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

#define ll long long
#define ld long double
#define int long long
#define pii pair<int, int>

int ob(vector<pii> a) {
    vector<pii> v;
    for (auto s : a) {
        v.eb(s.x, 0);
        v.eb(s.y + 1, 1);
    }
    sort(all(v));
    int res = 0, cnt = 0;
    f(i, sz(v) - 1) {
        if (v[i].y == 0) cnt++; else cnt--;
        if (cnt) res += v[i + 1].x - v[i].x;
    }
    return res;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    int p = a / __gcd(a, b + 1);
    if (b <= 3) {
    vector<int> l(n), r(n);
    f(i, n) cin >> l[i] >> r[i];
    int ans = 0;
    f(z, b) {
        vector<pii> v;
        f(i, n) {
            if (r[i] < z) continue;
            int ql = max(0LL, (l[i] - z + b - 1) / b), qr = (r[i] - z) / b;
            if (ql <= qr) {
                ql %= p;
                qr %= p;
                if (ql <= qr) {
                    v.eb(ql, qr);
                } else {
                    v.eb(0, qr);
                    v.eb(ql, p - 1);
                }
            }
        }
        ans += ob(v);
    }
    cout << ans;
    } else {
        set<pii> s;
        while (n--) {
            int l, r;
            cin >> l >> r;
            for (int i = l; i <= r; i++) s.insert({i / b % p, i % b});
        }
        cout << sz(s);
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 59 ms 12408 KB Output is correct
3 Correct 78 ms 17912 KB Output is correct
4 Correct 6 ms 896 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 11 ms 1280 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 416 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 45 ms 7000 KB Output is correct
16 Correct 31 ms 6784 KB Output is correct
17 Correct 73 ms 6648 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 Runtime error 2484 ms 524288 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 134 ms 32376 KB Output is correct
3 Correct 132 ms 32120 KB Output is correct
4 Correct 128 ms 30712 KB Output is correct
5 Execution timed out 5054 ms 62584 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 675 ms 80452 KB Output is correct
3 Correct 726 ms 80708 KB Output is correct
4 Correct 683 ms 80720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 675 ms 80452 KB Output is correct
3 Correct 726 ms 80708 KB Output is correct
4 Correct 683 ms 80720 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 970 ms 112200 KB Output is correct
7 Correct 749 ms 54560 KB Output is correct
8 Correct 1212 ms 112104 KB Output is correct
9 Correct 1598 ms 112188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 675 ms 80452 KB Output is correct
3 Correct 726 ms 80708 KB Output is correct
4 Correct 683 ms 80720 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 299 ms 63096 KB Output is correct
7 Runtime error 2214 ms 524288 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Runtime error 1890 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 59 ms 12408 KB Output is correct
3 Correct 78 ms 17912 KB Output is correct
4 Correct 6 ms 896 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 11 ms 1280 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 5 ms 416 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 45 ms 7000 KB Output is correct
16 Correct 31 ms 6784 KB Output is correct
17 Correct 73 ms 6648 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Runtime error 2484 ms 524288 KB Execution killed with signal 9 (could be triggered by violating memory limits)
21 Halted 0 ms 0 KB -