Submission #240357

# Submission time Handle Problem Language Result Execution time Memory
240357 2020-06-19T13:42:20 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({{0, 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) {
                if (s.x <= s.y) {
                    tt.pb(s);
                } else {
                    tt.pb({0, s.y});
                    tt.pb({s.x, p - 1});
                }
            }
            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 57 ms 12412 KB Output is correct
3 Correct 84 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 5 ms 512 KB Output is correct
8 Correct 6 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 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 42 ms 7032 KB Output is correct
16 Correct 34 ms 6776 KB Output is correct
17 Correct 72 ms 6648 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 150 ms 32352 KB Output is correct
3 Correct 130 ms 32120 KB Output is correct
4 Correct 129 ms 30560 KB Output is correct
5 Execution timed out 5040 ms 62656 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 686 ms 80388 KB Output is correct
3 Correct 719 ms 80464 KB Output is correct
4 Correct 678 ms 80580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 686 ms 80388 KB Output is correct
3 Correct 719 ms 80464 KB Output is correct
4 Correct 678 ms 80580 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 1000 ms 112000 KB Output is correct
7 Correct 752 ms 54308 KB Output is correct
8 Correct 1356 ms 111896 KB Output is correct
9 Correct 1618 ms 112024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 686 ms 80388 KB Output is correct
3 Correct 719 ms 80464 KB Output is correct
4 Correct 678 ms 80580 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 304 ms 62816 KB Output is correct
7 Runtime error 2191 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 1938 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 57 ms 12412 KB Output is correct
3 Correct 84 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 5 ms 512 KB Output is correct
8 Correct 6 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 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 42 ms 7032 KB Output is correct
16 Correct 34 ms 6776 KB Output is correct
17 Correct 72 ms 6648 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 -