Submission #910913

# Submission time Handle Problem Language Result Execution time Memory
910913 2024-01-18T09:21:02 Z green_gold_dog Strange Device (APIO19_strange_device) C++17
10 / 100
800 ms 100292 KB
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,abm,popcnt,mmx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;
typedef complex<double> cd;

constexpr ll INF64 = 1'000'000'000'000'000'000, INF32 = 2'000'000'000, MOD = 1'000'000'007;
constexpr db PI = acos(-1);
constexpr bool IS_FILE = false, IS_TEST_CASES = false;

random_device rd;
mt19937 rnd32(rd());
mt19937_64 rnd64(rd());

template<typename T>
bool assign_max(T& a, T b) {
        if (b > a) {
                a = b;
                return true;
        }
        return false;
}

template<typename T>
bool assign_min(T& a, T b) {
        if (b < a) {
                a = b;
                return true;
        }
        return false;
}

template<typename T>
T square(T a) {
        return a * a;
}

template<>
struct std::hash<pair<ll, ll>> {
        ll operator() (pair<ll, ll> p) const {
                return ((__int128)p.first * MOD + p.second) % INF64;
        }
};

void solve() {
        ll n, a, b;
        cin >> n >> a >> b;
        ll mod = INF64;
        if (mod / a >= b) {
                mod = a * b;
        }
        map<ll, ll> add;
        for (ll i = 0; i < n; i++) {
                ll l, r;
                cin >> l >> r;
                r++;
                if (r - l >= mod) {
                        cout << mod << '\n';
                        return;
                }
                l %= mod;
                r %= mod;
                if (l <= r) {
                        add[l]++;
                        add[r]--;
                } else {
                        add[0]++;
                        add[mod]--;
                        add[l]++;
                        add[r]--;
                }
        }
        ll now = 0;
        ll ans = 0;
        ll lst = 0;
        for (auto[a, b] : add) {
                if (now) {
                        ans += a - lst;
                }
                lst = a;
                now += b;
        }
        cout << ans << '\n';
}

int main() {
        if (IS_FILE) {
                freopen("", "r", stdin);
                freopen("", "w", stdout);
        }
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        ll t = 1;
        if (IS_TEST_CASES) {
                cin >> t;
        }
        for (ll i = 0; i < t; i++) {
                solve();
        }
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:93:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |                 freopen("", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~
strange_device.cpp:94:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |                 freopen("", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 5 ms 1428 KB Output is correct
3 Correct 5 ms 1368 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 600 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 556 KB Output is correct
5 Correct 186 ms 25428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 565 ms 100260 KB Output is correct
3 Incorrect 682 ms 100292 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 565 ms 100260 KB Output is correct
3 Incorrect 682 ms 100292 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 565 ms 100260 KB Output is correct
3 Incorrect 682 ms 100292 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 55 ms 10336 KB Output is correct
3 Correct 58 ms 10576 KB Output is correct
4 Correct 667 ms 100260 KB Output is correct
5 Correct 55 ms 10300 KB Output is correct
6 Correct 56 ms 10356 KB Output is correct
7 Correct 57 ms 10320 KB Output is correct
8 Correct 56 ms 10200 KB Output is correct
9 Correct 66 ms 10428 KB Output is correct
10 Correct 51 ms 10320 KB Output is correct
11 Correct 51 ms 10428 KB Output is correct
12 Correct 51 ms 10404 KB Output is correct
13 Correct 53 ms 10320 KB Output is correct
14 Correct 800 ms 100268 KB Output is correct
15 Incorrect 54 ms 10324 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 5 ms 1428 KB Output is correct
3 Correct 5 ms 1368 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -