Submission #240355

# Submission time Handle Problem Language Result Execution time Memory
240355 2020-06-19T13:38: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 (n == 1) {
        int l, r;
        cin >> l >> r;
        vector<pair<pii, pii>> v;
        int bl = l / b, br = r / b;
        if (bl == br) {
            cout << r - l + 1;
            return 0;
        }
        if (bl + 1 < br) {
            v.pb({{0, 0}, {(bl + 1) % p, (br - 1) % p}});
            v.pb({{b, 1}, {(bl + 1) % p, (br - 1) % p}});
        }
        v.pb({{l % b, 0}, {bl % p, bl % p}});
        v.pb({{b, 1}, {bl % p, bl % p}});
        v.pb({{br % b, 0}, {br % p, br % p}});
        v.pb({{r % b + 1, 1}, {br % p, br % p}});
        multiset<pii> ss;
        int ans = 0;
        f(i, sz(v) - 1) {
            if (v[i].x.y == 0) {
                ss.insert(v[i].y);
            } else {
                ss.erase(ss.find(v[i].y));
            }
            vector<pii> tt;
            for (auto s : ss) tt.pb(s);
            ans += ob(tt) * (v[i + 1].x.x - v[i].x.x);
        }
        cout << ans;
        return 0;
    }
    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 54 ms 12792 KB Output is correct
3 Correct 81 ms 18424 KB Output is correct
4 Correct 7 ms 896 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 12 ms 1280 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 5 ms 384 KB Output is correct
15 Correct 46 ms 7160 KB Output is correct
16 Correct 38 ms 7160 KB Output is correct
17 Correct 72 ms 7672 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 144 ms 32324 KB Output is correct
3 Correct 133 ms 32120 KB Output is correct
4 Correct 143 ms 30712 KB Output is correct
5 Execution timed out 5022 ms 62584 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 724 ms 81196 KB Output is correct
3 Correct 744 ms 80964 KB Output is correct
4 Correct 685 ms 80960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 724 ms 81196 KB Output is correct
3 Correct 744 ms 80964 KB Output is correct
4 Correct 685 ms 80960 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 1004 ms 112468 KB Output is correct
7 Correct 759 ms 54816 KB Output is correct
8 Correct 1257 ms 112440 KB Output is correct
9 Correct 1642 ms 112604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 724 ms 81196 KB Output is correct
3 Correct 744 ms 80964 KB Output is correct
4 Correct 685 ms 80960 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 314 ms 63608 KB Output is correct
7 Runtime error 2245 ms 524292 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 1939 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 54 ms 12792 KB Output is correct
3 Correct 81 ms 18424 KB Output is correct
4 Correct 7 ms 896 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 12 ms 1280 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 5 ms 384 KB Output is correct
15 Correct 46 ms 7160 KB Output is correct
16 Correct 38 ms 7160 KB Output is correct
17 Correct 72 ms 7672 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Incorrect 5 ms 384 KB Output isn't correct
21 Halted 0 ms 0 KB -