Submission #957894

# Submission time Handle Problem Language Result Execution time Memory
957894 2024-04-04T12:50:06 Z steveonalex Strange Device (APIO19_strange_device) C++17
100 / 100
389 ms 96184 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ll mask){return __builtin_ctzll(mask);}
int logOf(ll mask){return 63 - __builtin_clzll(mask);}

mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
// mt19937_64 rng(69);
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}

template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }

template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }

template <class T>
    void printArr(T& container, string separator = " ", string finish = "\n", ostream &out = cout){
        for(auto item: container) out << item << separator;
        out << finish;
    }

template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }


int main(void){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n; ll a, b; cin >> n >> a >> b;

    vector<pair<ll, ll>> r(n);
    for(int i= 0; i<n; ++i) cin >> r[i].first >> r[i].second;

    __int128 wut = a; wut *= b;
    __int128 wow = __gcd((__int128)(b+1), wut);
    __int128 cycle = wut / wow;

    vector<pair<ll,ll>> ligma;
    for(auto i: r){
        if (i.second - i.first + 1 >= cycle){
            ligma.push_back({0, cycle-1});
        }
        else{
            i.first %= cycle; i.second %= cycle;
            if (i.second < i.first ){
                ligma.push_back({i.first, cycle - 1});
                ligma.push_back({0, i.second});
            }
            else{
                ligma.push_back({i.first, i.second});
            }
        }
    }

    sort(ALL(ligma));

    vector<pair<ll, ll>> real;
    for(auto i: ligma){
        if (real.size() && real.back().second >= i.first){
            maximize(real.back().second, i.second);
        }
        else real.push_back(i);
    }

    ll ans = 0;
    for(auto i: real) ans += i.second - i.first + 1;

    cout << ans << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 4 ms 1756 KB Output is correct
3 Correct 4 ms 1372 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 5 ms 1504 KB Output is correct
17 Correct 38 ms 10276 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 212 ms 59104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 323 ms 96184 KB Output is correct
3 Correct 367 ms 95156 KB Output is correct
4 Correct 312 ms 96056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 323 ms 96184 KB Output is correct
3 Correct 367 ms 95156 KB Output is correct
4 Correct 312 ms 96056 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 312 ms 94696 KB Output is correct
7 Correct 326 ms 94720 KB Output is correct
8 Correct 310 ms 95560 KB Output is correct
9 Correct 372 ms 94300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 323 ms 96184 KB Output is correct
3 Correct 367 ms 95156 KB Output is correct
4 Correct 312 ms 96056 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 39 ms 10336 KB Output is correct
7 Correct 39 ms 10452 KB Output is correct
8 Correct 32 ms 10184 KB Output is correct
9 Correct 36 ms 10192 KB Output is correct
10 Correct 35 ms 10208 KB Output is correct
11 Correct 34 ms 10184 KB Output is correct
12 Correct 32 ms 10276 KB Output is correct
13 Correct 36 ms 10188 KB Output is correct
14 Correct 34 ms 10216 KB Output is correct
15 Correct 37 ms 10188 KB Output is correct
16 Correct 45 ms 10252 KB Output is correct
17 Correct 36 ms 10196 KB Output is correct
18 Correct 340 ms 95612 KB Output is correct
19 Correct 319 ms 93636 KB Output is correct
20 Correct 358 ms 95160 KB Output is correct
21 Correct 37 ms 10188 KB Output is correct
22 Correct 31 ms 10184 KB Output is correct
23 Correct 101 ms 27028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 38 ms 10368 KB Output is correct
3 Correct 35 ms 10188 KB Output is correct
4 Correct 366 ms 93876 KB Output is correct
5 Correct 35 ms 10192 KB Output is correct
6 Correct 35 ms 10188 KB Output is correct
7 Correct 36 ms 10200 KB Output is correct
8 Correct 36 ms 10324 KB Output is correct
9 Correct 35 ms 10188 KB Output is correct
10 Correct 35 ms 10188 KB Output is correct
11 Correct 39 ms 10440 KB Output is correct
12 Correct 30 ms 10196 KB Output is correct
13 Correct 36 ms 10328 KB Output is correct
14 Correct 389 ms 96112 KB Output is correct
15 Correct 39 ms 10192 KB Output is correct
16 Correct 327 ms 95152 KB Output is correct
17 Correct 326 ms 94748 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 4 ms 1756 KB Output is correct
3 Correct 4 ms 1372 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 5 ms 1504 KB Output is correct
17 Correct 38 ms 10276 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 212 ms 59104 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 323 ms 96184 KB Output is correct
31 Correct 367 ms 95156 KB Output is correct
32 Correct 312 ms 96056 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 312 ms 94696 KB Output is correct
35 Correct 326 ms 94720 KB Output is correct
36 Correct 310 ms 95560 KB Output is correct
37 Correct 372 ms 94300 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 39 ms 10336 KB Output is correct
40 Correct 39 ms 10452 KB Output is correct
41 Correct 32 ms 10184 KB Output is correct
42 Correct 36 ms 10192 KB Output is correct
43 Correct 35 ms 10208 KB Output is correct
44 Correct 34 ms 10184 KB Output is correct
45 Correct 32 ms 10276 KB Output is correct
46 Correct 36 ms 10188 KB Output is correct
47 Correct 34 ms 10216 KB Output is correct
48 Correct 37 ms 10188 KB Output is correct
49 Correct 45 ms 10252 KB Output is correct
50 Correct 36 ms 10196 KB Output is correct
51 Correct 340 ms 95612 KB Output is correct
52 Correct 319 ms 93636 KB Output is correct
53 Correct 358 ms 95160 KB Output is correct
54 Correct 37 ms 10188 KB Output is correct
55 Correct 31 ms 10184 KB Output is correct
56 Correct 101 ms 27028 KB Output is correct
57 Correct 1 ms 344 KB Output is correct
58 Correct 38 ms 10368 KB Output is correct
59 Correct 35 ms 10188 KB Output is correct
60 Correct 366 ms 93876 KB Output is correct
61 Correct 35 ms 10192 KB Output is correct
62 Correct 35 ms 10188 KB Output is correct
63 Correct 36 ms 10200 KB Output is correct
64 Correct 36 ms 10324 KB Output is correct
65 Correct 35 ms 10188 KB Output is correct
66 Correct 35 ms 10188 KB Output is correct
67 Correct 39 ms 10440 KB Output is correct
68 Correct 30 ms 10196 KB Output is correct
69 Correct 36 ms 10328 KB Output is correct
70 Correct 389 ms 96112 KB Output is correct
71 Correct 39 ms 10192 KB Output is correct
72 Correct 327 ms 95152 KB Output is correct
73 Correct 326 ms 94748 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 4 ms 1512 KB Output is correct
80 Correct 382 ms 94592 KB Output is correct
81 Correct 373 ms 94644 KB Output is correct
82 Correct 353 ms 93916 KB Output is correct
83 Correct 349 ms 95372 KB Output is correct
84 Correct 342 ms 95148 KB Output is correct
85 Correct 350 ms 94304 KB Output is correct
86 Correct 91 ms 26880 KB Output is correct
87 Correct 0 ms 344 KB Output is correct