Submission #902306

# Submission time Handle Problem Language Result Execution time Memory
902306 2024-01-10T08:18:45 Z Boycl07 Strange Device (APIO19_strange_device) C++17
100 / 100
625 ms 70436 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define int ll
#define rep(i, n) for(int i = 1; i <= n; ++i)
#define forn(i, l, r) for(int i = l; i <= r; ++i)
#define ford(i, r, l) for(int i = r; i >= l; --i)
#define FOR(i, n) for(int i = 0; i < n; ++i)
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define endl "\n"
#define task ""
#define sz(a) int(a.size())
#define C(x, y) make_pair(x, y)
#define all(a) (a).begin(), (a).end()
#define bit(i, mask) (mask >> i & 1)

template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }

inline int readInt()       {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();int n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
inline ll readLong()       {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();ll  n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
inline string readString() {char c;while(c=getchar(),c==' '||c=='\n'||c=='\t');string s({c});while(c=getchar(),c!=EOF&&c!=' '&&c!='\n'&&c!='\t')s+=c;return s;}


const int N =  2e5 + 10;
const int M = 1e3 + 3;
const int N1 = 2e3 + 10;
const int K = 1e2 + 1;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const ll LINF = 1e17 + 2;
const int block_size = 500;
const int LOG = 29;
const int offset = N;
const int LIM = 1e4 ;
const int AL = 26;

int n;
ll a, b;

vector<pii> p;

void add(int l, int r)
{
    p.pb({l, 1});
    p.pb({r + 1, -1});
}

void solve()
{
    cin >> n >> a >> b;
	ll period = a / __gcd(a, b + 1)  > INF / b ? INF : a / __gcd(a, b + 1) * b;
    rep(i, n)
    {
        ll l, r;
        cin >> l >> r;
        if(r - l + 1 >= period) return cout << period, void();
        l %= period;
        r %= period;
        if(l > r)
            add(0, r), add(l, period - 1);
        else
            add(l, r);
    }
    sort(all(p));
    int cnt = 0;
    ll last = 0;
    ll res = 0;
    for(int i = 0; i < sz(p); ++i)
    {
        int j = i;
        if(i > 0 && cnt)
            res += (p[i].fi - p[i - 1].fi);
        while(j < sz(p) && p[i].fi == p[j].fi)
        {
            cnt += p[j].se;
            ++j;
        }
        i = j - 1;
    }
    cout << res;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int TC = 1;


    while(TC--)
    {
        solve();
        cout << endl;
    }

    return 0;
}
//ha

Compilation message

strange_device.cpp: In function 'void solve()':
strange_device.cpp:74:8: warning: unused variable 'last' [-Wunused-variable]
   74 |     ll last = 0;
      |        ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 6 ms 1364 KB Output is correct
3 Correct 4 ms 1248 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 456 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 0 ms 360 KB Output is correct
12 Correct 0 ms 360 KB Output is correct
13 Correct 0 ms 360 KB Output is correct
14 Correct 0 ms 360 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 6 ms 1248 KB Output is correct
17 Correct 46 ms 7380 KB Output is correct
18 Correct 1 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 356 KB Output is correct
2 Correct 0 ms 360 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 0 ms 360 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 524 KB Output is correct
5 Correct 262 ms 56924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 385 ms 69720 KB Output is correct
3 Correct 393 ms 69380 KB Output is correct
4 Correct 369 ms 69116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 385 ms 69720 KB Output is correct
3 Correct 393 ms 69380 KB Output is correct
4 Correct 369 ms 69116 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 399 ms 68572 KB Output is correct
7 Correct 410 ms 70304 KB Output is correct
8 Correct 412 ms 70024 KB Output is correct
9 Correct 434 ms 68912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 385 ms 69720 KB Output is correct
3 Correct 393 ms 69380 KB Output is correct
4 Correct 369 ms 69116 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 37 ms 8436 KB Output is correct
7 Correct 53 ms 8492 KB Output is correct
8 Correct 38 ms 7612 KB Output is correct
9 Correct 39 ms 8696 KB Output is correct
10 Correct 47 ms 9100 KB Output is correct
11 Correct 41 ms 7880 KB Output is correct
12 Correct 35 ms 7624 KB Output is correct
13 Correct 41 ms 8916 KB Output is correct
14 Correct 39 ms 7884 KB Output is correct
15 Correct 44 ms 8664 KB Output is correct
16 Correct 51 ms 8408 KB Output is correct
17 Correct 38 ms 9168 KB Output is correct
18 Correct 425 ms 70200 KB Output is correct
19 Correct 434 ms 70436 KB Output is correct
20 Correct 532 ms 69120 KB Output is correct
21 Correct 45 ms 7928 KB Output is correct
22 Correct 39 ms 8648 KB Output is correct
23 Correct 112 ms 28680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 452 KB Output is correct
2 Correct 46 ms 8156 KB Output is correct
3 Correct 52 ms 8896 KB Output is correct
4 Correct 625 ms 68840 KB Output is correct
5 Correct 46 ms 8640 KB Output is correct
6 Correct 48 ms 7752 KB Output is correct
7 Correct 52 ms 8476 KB Output is correct
8 Correct 64 ms 8148 KB Output is correct
9 Correct 54 ms 8152 KB Output is correct
10 Correct 51 ms 8600 KB Output is correct
11 Correct 62 ms 7896 KB Output is correct
12 Correct 40 ms 9160 KB Output is correct
13 Correct 53 ms 8676 KB Output is correct
14 Correct 510 ms 68676 KB Output is correct
15 Correct 48 ms 8396 KB Output is correct
16 Correct 412 ms 68772 KB Output is correct
17 Correct 397 ms 69800 KB Output is correct
18 Correct 0 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 6 ms 1364 KB Output is correct
3 Correct 4 ms 1248 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 456 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 0 ms 360 KB Output is correct
12 Correct 0 ms 360 KB Output is correct
13 Correct 0 ms 360 KB Output is correct
14 Correct 0 ms 360 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 6 ms 1248 KB Output is correct
17 Correct 46 ms 7380 KB Output is correct
18 Correct 1 ms 504 KB Output is correct
19 Correct 1 ms 356 KB Output is correct
20 Correct 0 ms 360 KB Output is correct
21 Correct 0 ms 464 KB Output is correct
22 Correct 0 ms 360 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 524 KB Output is correct
28 Correct 262 ms 56924 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 385 ms 69720 KB Output is correct
31 Correct 393 ms 69380 KB Output is correct
32 Correct 369 ms 69116 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 399 ms 68572 KB Output is correct
35 Correct 410 ms 70304 KB Output is correct
36 Correct 412 ms 70024 KB Output is correct
37 Correct 434 ms 68912 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 37 ms 8436 KB Output is correct
40 Correct 53 ms 8492 KB Output is correct
41 Correct 38 ms 7612 KB Output is correct
42 Correct 39 ms 8696 KB Output is correct
43 Correct 47 ms 9100 KB Output is correct
44 Correct 41 ms 7880 KB Output is correct
45 Correct 35 ms 7624 KB Output is correct
46 Correct 41 ms 8916 KB Output is correct
47 Correct 39 ms 7884 KB Output is correct
48 Correct 44 ms 8664 KB Output is correct
49 Correct 51 ms 8408 KB Output is correct
50 Correct 38 ms 9168 KB Output is correct
51 Correct 425 ms 70200 KB Output is correct
52 Correct 434 ms 70436 KB Output is correct
53 Correct 532 ms 69120 KB Output is correct
54 Correct 45 ms 7928 KB Output is correct
55 Correct 39 ms 8648 KB Output is correct
56 Correct 112 ms 28680 KB Output is correct
57 Correct 0 ms 452 KB Output is correct
58 Correct 46 ms 8156 KB Output is correct
59 Correct 52 ms 8896 KB Output is correct
60 Correct 625 ms 68840 KB Output is correct
61 Correct 46 ms 8640 KB Output is correct
62 Correct 48 ms 7752 KB Output is correct
63 Correct 52 ms 8476 KB Output is correct
64 Correct 64 ms 8148 KB Output is correct
65 Correct 54 ms 8152 KB Output is correct
66 Correct 51 ms 8600 KB Output is correct
67 Correct 62 ms 7896 KB Output is correct
68 Correct 40 ms 9160 KB Output is correct
69 Correct 53 ms 8676 KB Output is correct
70 Correct 510 ms 68676 KB Output is correct
71 Correct 48 ms 8396 KB Output is correct
72 Correct 412 ms 68772 KB Output is correct
73 Correct 397 ms 69800 KB Output is correct
74 Correct 0 ms 456 KB Output is correct
75 Correct 1 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 1 ms 348 KB Output is correct
78 Correct 0 ms 448 KB Output is correct
79 Correct 4 ms 1444 KB Output is correct
80 Correct 563 ms 68840 KB Output is correct
81 Correct 592 ms 68780 KB Output is correct
82 Correct 521 ms 69256 KB Output is correct
83 Correct 487 ms 69720 KB Output is correct
84 Correct 476 ms 68808 KB Output is correct
85 Correct 466 ms 70200 KB Output is correct
86 Correct 107 ms 28320 KB Output is correct
87 Correct 1 ms 348 KB Output is correct