Submission #563610

# Submission time Handle Problem Language Result Execution time Memory
563610 2022-05-17T17:26:23 Z Ooops_sorry Strange Device (APIO19_strange_device) C++14
40 / 100
5000 ms 117464 KB
#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define ld long double
#define ll long long

mt19937 rnd(51);

ll solve(ll n, ll a, ll b, vector<ll> l, vector<ll> r) {
    ll ans = 0, need;
    bool was = 0, sum = 0;
    if (log2(a) + log2(b) > log2(1e18) + 1) {
        sum = 1;
    } else {
        for (ll k = 1;; k++) {
            if ((k * b + k) % a == 0) {
                need = k * b;
                break;
            }
        }
    }
    vector<pair<ll, ll>> seg, u;
    for (int i = 0; i < n; i++) {
        if (sum) {
            ans += r[i] - l[i] + 1;
        } else {
            if (r[i] - l[i] + 1 >= need) {
                was = 1;
            } else {
                ll l1 = l[i] % (need), r1 = r[i] % (need);
                if (l1 <= r1) {
                    seg.pb({l1, r1});
                } else {
                    seg.pb({l1, need - 1});
                    seg.pb({0, r1});
                }
            }
        }
    }
    if (was) {
        return need;
    }
    if (sum) {
        return ans;
    } else {
        for (auto to : seg) {
            u.pb({to.first, 1});
            u.pb({to.second + 1, -1});
        }
        sort(u.begin(), u.end());
        ll bal = 0, last = -1;
        for (auto to : u) {
            if (bal > 0) {
                ans += to.first - last;
            }
            bal += to.second;
            last = to.first;
        }
        return ans;
    }
}

ll solve2(ll n, ll a, ll b, vector<ll> l, vector<ll> r) {
    map<pair<int,int>, int> mp;
    for (int i = 0; i < n; i++) {
        for (int j = l[i]; j <= r[i]; j++) {
            mp[{(j + j / b) % a, j % b}]++;
        }
    }
    return mp.size();
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif // LCOAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n, a, b;
    cin >> n >> a >> b;
    vector<ll> l(n), r(n);
    for (int i = 0; i < n; i++) {
        cin >> l[i] >> r[i];
    }
    cout << solve(n, a, b, l, r) << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 6 ms 1744 KB Output is correct
3 Correct 6 ms 1748 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 6 ms 1740 KB Output is correct
17 Correct 58 ms 12888 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 396 ms 105392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 551 ms 92972 KB Output is correct
3 Execution timed out 5083 ms 48056 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 551 ms 92972 KB Output is correct
3 Execution timed out 5083 ms 48056 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 551 ms 92972 KB Output is correct
3 Execution timed out 5083 ms 48056 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 58 ms 12884 KB Output is correct
3 Correct 62 ms 13000 KB Output is correct
4 Correct 700 ms 97388 KB Output is correct
5 Correct 69 ms 12872 KB Output is correct
6 Correct 69 ms 12876 KB Output is correct
7 Correct 69 ms 12888 KB Output is correct
8 Correct 82 ms 12880 KB Output is correct
9 Correct 64 ms 12872 KB Output is correct
10 Correct 59 ms 12876 KB Output is correct
11 Correct 57 ms 12872 KB Output is correct
12 Correct 52 ms 12996 KB Output is correct
13 Correct 106 ms 12892 KB Output is correct
14 Correct 626 ms 117424 KB Output is correct
15 Correct 63 ms 12884 KB Output is correct
16 Correct 519 ms 117296 KB Output is correct
17 Correct 528 ms 117464 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 6 ms 1744 KB Output is correct
3 Correct 6 ms 1748 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 6 ms 1740 KB Output is correct
17 Correct 58 ms 12888 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 396 ms 105392 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 551 ms 92972 KB Output is correct
31 Execution timed out 5083 ms 48056 KB Time limit exceeded
32 Halted 0 ms 0 KB -