Submission #366565

# Submission time Handle Problem Language Result Execution time Memory
366565 2021-02-14T14:12:23 Z Nima_Naderi Strange Device (APIO19_strange_device) C++14
100 / 100
1161 ms 108528 KB
///In the name of GOD
//#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MXN = 4e6 + 10;
const ll INF = 1e18;
ll n, A, B, g, k, m;
ll L[MXN], R[MXN], cnt[MXN];
vector<ll> Num;
vector<pair<ll, ll>> seg;
inline int GetId(ll x){
    return lower_bound(Num.begin(), Num.end(), x) - Num.begin();
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    cin >> n >> A >> B;
    g = __gcd(A, B + 1);
    k = (A / g);
    m = (k > (INF + B - 1) / B ? INF + 1 : k * B);
    for(int i = 1; i <= n; i ++){
        cin >> L[i] >> R[i];
        if(R[i] - L[i] + 1 >= m) return cout << m, 0;
        L[i] %= m, R[i] %= m;
        Num.push_back(L[i]), Num.push_back(R[i]), Num.push_back(R[i] + 1);
        if(R[i] < L[i]){
            seg.push_back({L[i], m - 1});
            seg.push_back({0, R[i]});
        }
        else{
            seg.push_back({L[i], R[i]});
        }
    }
    Num.push_back(0), Num.push_back(m - 1);
    Num.push_back(1), Num.push_back(m);
    sort(Num.begin(), Num.end());
    Num.resize(unique(Num.begin(), Num.end()) - Num.begin());
    sort(seg.begin(), seg.end());
    for(auto LR : seg){
        ll l, r; tie(l, r) = LR;
        cnt[GetId(l)] ++, cnt[GetId(r + 1)] --;
    }
    ll ans = 0, bal = 0, len;
    for(int i = 0; i < Num.size() - 1; i ++){
        len = (Num[i + 1] - 1) - Num[i] + 1;
        bal += cnt[i];
        assert(bal >= 0);
        if(bal > 0) ans += len;
    }
    cout << ans << '\n';
    return 0;
}
/*!
    HE'S AN INSTIGATOR,
    ENEMY ELIMINATOR,
    AND WHEN HE KNOCKS YOU BETTER
    YOU BETTER LET HIM IN.
*/
//! N.N

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:45:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for(int i = 0; i < Num.size() - 1; i ++){
      |                    ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 9 ms 1640 KB Output is correct
3 Correct 9 ms 1640 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 8 ms 1640 KB Output is correct
17 Correct 102 ms 10064 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 450 ms 55648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 372 KB Output is correct
2 Correct 867 ms 63604 KB Output is correct
3 Correct 948 ms 71588 KB Output is correct
4 Correct 870 ms 71392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 372 KB Output is correct
2 Correct 867 ms 63604 KB Output is correct
3 Correct 948 ms 71588 KB Output is correct
4 Correct 870 ms 71392 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 858 ms 71788 KB Output is correct
7 Correct 885 ms 63840 KB Output is correct
8 Correct 907 ms 71524 KB Output is correct
9 Correct 1121 ms 71972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 372 KB Output is correct
2 Correct 867 ms 63604 KB Output is correct
3 Correct 948 ms 71588 KB Output is correct
4 Correct 870 ms 71392 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 87 ms 11296 KB Output is correct
7 Correct 94 ms 11336 KB Output is correct
8 Correct 90 ms 11372 KB Output is correct
9 Correct 91 ms 11336 KB Output is correct
10 Correct 83 ms 11336 KB Output is correct
11 Correct 88 ms 11336 KB Output is correct
12 Correct 83 ms 11336 KB Output is correct
13 Correct 105 ms 11336 KB Output is correct
14 Correct 95 ms 11336 KB Output is correct
15 Correct 107 ms 11336 KB Output is correct
16 Correct 100 ms 11376 KB Output is correct
17 Correct 94 ms 11336 KB Output is correct
18 Correct 899 ms 72032 KB Output is correct
19 Correct 889 ms 71952 KB Output is correct
20 Correct 1080 ms 71776 KB Output is correct
21 Correct 102 ms 11336 KB Output is correct
22 Correct 97 ms 11336 KB Output is correct
23 Correct 185 ms 31916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 99 ms 11336 KB Output is correct
3 Correct 101 ms 11336 KB Output is correct
4 Correct 1147 ms 71532 KB Output is correct
5 Correct 99 ms 11336 KB Output is correct
6 Correct 100 ms 11336 KB Output is correct
7 Correct 99 ms 11336 KB Output is correct
8 Correct 114 ms 11336 KB Output is correct
9 Correct 97 ms 11464 KB Output is correct
10 Correct 103 ms 11336 KB Output is correct
11 Correct 98 ms 11464 KB Output is correct
12 Correct 87 ms 11468 KB Output is correct
13 Correct 102 ms 11336 KB Output is correct
14 Correct 1091 ms 108384 KB Output is correct
15 Correct 103 ms 11336 KB Output is correct
16 Correct 888 ms 108528 KB Output is correct
17 Correct 862 ms 108388 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 9 ms 1640 KB Output is correct
3 Correct 9 ms 1640 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 8 ms 1640 KB Output is correct
17 Correct 102 ms 10064 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 450 ms 55648 KB Output is correct
29 Correct 1 ms 372 KB Output is correct
30 Correct 867 ms 63604 KB Output is correct
31 Correct 948 ms 71588 KB Output is correct
32 Correct 870 ms 71392 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 858 ms 71788 KB Output is correct
35 Correct 885 ms 63840 KB Output is correct
36 Correct 907 ms 71524 KB Output is correct
37 Correct 1121 ms 71972 KB Output is correct
38 Correct 1 ms 512 KB Output is correct
39 Correct 87 ms 11296 KB Output is correct
40 Correct 94 ms 11336 KB Output is correct
41 Correct 90 ms 11372 KB Output is correct
42 Correct 91 ms 11336 KB Output is correct
43 Correct 83 ms 11336 KB Output is correct
44 Correct 88 ms 11336 KB Output is correct
45 Correct 83 ms 11336 KB Output is correct
46 Correct 105 ms 11336 KB Output is correct
47 Correct 95 ms 11336 KB Output is correct
48 Correct 107 ms 11336 KB Output is correct
49 Correct 100 ms 11376 KB Output is correct
50 Correct 94 ms 11336 KB Output is correct
51 Correct 899 ms 72032 KB Output is correct
52 Correct 889 ms 71952 KB Output is correct
53 Correct 1080 ms 71776 KB Output is correct
54 Correct 102 ms 11336 KB Output is correct
55 Correct 97 ms 11336 KB Output is correct
56 Correct 185 ms 31916 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 99 ms 11336 KB Output is correct
59 Correct 101 ms 11336 KB Output is correct
60 Correct 1147 ms 71532 KB Output is correct
61 Correct 99 ms 11336 KB Output is correct
62 Correct 100 ms 11336 KB Output is correct
63 Correct 99 ms 11336 KB Output is correct
64 Correct 114 ms 11336 KB Output is correct
65 Correct 97 ms 11464 KB Output is correct
66 Correct 103 ms 11336 KB Output is correct
67 Correct 98 ms 11464 KB Output is correct
68 Correct 87 ms 11468 KB Output is correct
69 Correct 102 ms 11336 KB Output is correct
70 Correct 1091 ms 108384 KB Output is correct
71 Correct 103 ms 11336 KB Output is correct
72 Correct 888 ms 108528 KB Output is correct
73 Correct 862 ms 108388 KB Output is correct
74 Correct 1 ms 364 KB Output is correct
75 Correct 1 ms 364 KB Output is correct
76 Correct 1 ms 364 KB Output is correct
77 Correct 1 ms 364 KB Output is correct
78 Correct 1 ms 364 KB Output is correct
79 Correct 8 ms 1640 KB Output is correct
80 Correct 1161 ms 108288 KB Output is correct
81 Correct 1153 ms 108256 KB Output is correct
82 Correct 1076 ms 108408 KB Output is correct
83 Correct 1067 ms 108236 KB Output is correct
84 Correct 1071 ms 108400 KB Output is correct
85 Correct 1051 ms 108384 KB Output is correct
86 Correct 183 ms 31788 KB Output is correct
87 Correct 1 ms 364 KB Output is correct