답안 #723156

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
723156 2023-04-13T09:37:42 Z nicky4321 이상한 기계 (APIO19_strange_device) C++17
100 / 100
919 ms 115888 KB
#include <bits/stdc++.h>
#include <numeric>
#define ll long long
#define ld long double
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define vi vector<int>
#define vl vector<ll>
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define CASE int t;cin>>t;for(int ca=1;ca<=t;ca++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int MAX = 1 << 20, MOD = 1e9 + 7;
ll l[MAX], r[MAX];

void solve(){
    ll n, a, b;
    cin >> n >> a >> b;
    for(int i = 1;i <= n;i++){
        cin >> l[i] >> r[i];
    }
    ll g = __gcd(a, b + 1);
    ll mod;
    if((__int128_t)a * b / g >= 2e18)
        mod = 2e18;
    else
        mod = a * b / g;
    map<ll, int> mp;
    for(int i = 1;i <= n;i++){
        if(r[i] - l[i] + 1 >= mod){
            cout << mod << '\n';
            return;
        }
        l[i] %= mod;
        r[i] %= mod;
        if(l[i] <= r[i]){
            mp[l[i]]++;
            mp[r[i] + 1]--;
        }else{
            mp[0]++;
            mp[r[i] + 1]--;
            mp[l[i]]++;
            mp[mod]--;
        }
    }
    ll lt = 0, now = 0, ans = 0;
    for(auto i : mp){
        if(now > 0)
            ans += i.F - lt;
        now += i.S;
        lt = i.F;
    }
    cout << ans << '\n';
}

int main(){
    IOS
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 6 ms 1108 KB Output is correct
3 Correct 5 ms 1108 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 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 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 7 ms 1508 KB Output is correct
17 Correct 69 ms 11908 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 254 ms 16020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 647 ms 78628 KB Output is correct
3 Correct 678 ms 78540 KB Output is correct
4 Correct 708 ms 115888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 647 ms 78628 KB Output is correct
3 Correct 678 ms 78540 KB Output is correct
4 Correct 708 ms 115888 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 685 ms 115616 KB Output is correct
7 Correct 701 ms 115720 KB Output is correct
8 Correct 695 ms 115644 KB Output is correct
9 Correct 919 ms 115612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 647 ms 78628 KB Output is correct
3 Correct 678 ms 78540 KB Output is correct
4 Correct 708 ms 115888 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 57 ms 11856 KB Output is correct
7 Correct 56 ms 11876 KB Output is correct
8 Correct 58 ms 11824 KB Output is correct
9 Correct 71 ms 11852 KB Output is correct
10 Correct 54 ms 11812 KB Output is correct
11 Correct 55 ms 11872 KB Output is correct
12 Correct 55 ms 11808 KB Output is correct
13 Correct 60 ms 11788 KB Output is correct
14 Correct 52 ms 11760 KB Output is correct
15 Correct 73 ms 11812 KB Output is correct
16 Correct 75 ms 11872 KB Output is correct
17 Correct 66 ms 11908 KB Output is correct
18 Correct 677 ms 115760 KB Output is correct
19 Correct 789 ms 115648 KB Output is correct
20 Correct 872 ms 115752 KB Output is correct
21 Correct 61 ms 11776 KB Output is correct
22 Correct 61 ms 11852 KB Output is correct
23 Correct 117 ms 18284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 71 ms 8072 KB Output is correct
3 Correct 66 ms 8120 KB Output is correct
4 Correct 727 ms 78644 KB Output is correct
5 Correct 64 ms 8124 KB Output is correct
6 Correct 64 ms 8076 KB Output is correct
7 Correct 62 ms 8140 KB Output is correct
8 Correct 64 ms 8108 KB Output is correct
9 Correct 60 ms 8124 KB Output is correct
10 Correct 60 ms 8084 KB Output is correct
11 Correct 60 ms 8092 KB Output is correct
12 Correct 72 ms 8036 KB Output is correct
13 Correct 65 ms 8140 KB Output is correct
14 Correct 894 ms 78548 KB Output is correct
15 Correct 64 ms 8164 KB Output is correct
16 Correct 640 ms 115700 KB Output is correct
17 Correct 658 ms 115724 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 6 ms 1108 KB Output is correct
3 Correct 5 ms 1108 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 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 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 7 ms 1508 KB Output is correct
17 Correct 69 ms 11908 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 254 ms 16020 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 647 ms 78628 KB Output is correct
31 Correct 678 ms 78540 KB Output is correct
32 Correct 708 ms 115888 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 685 ms 115616 KB Output is correct
35 Correct 701 ms 115720 KB Output is correct
36 Correct 695 ms 115644 KB Output is correct
37 Correct 919 ms 115612 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 57 ms 11856 KB Output is correct
40 Correct 56 ms 11876 KB Output is correct
41 Correct 58 ms 11824 KB Output is correct
42 Correct 71 ms 11852 KB Output is correct
43 Correct 54 ms 11812 KB Output is correct
44 Correct 55 ms 11872 KB Output is correct
45 Correct 55 ms 11808 KB Output is correct
46 Correct 60 ms 11788 KB Output is correct
47 Correct 52 ms 11760 KB Output is correct
48 Correct 73 ms 11812 KB Output is correct
49 Correct 75 ms 11872 KB Output is correct
50 Correct 66 ms 11908 KB Output is correct
51 Correct 677 ms 115760 KB Output is correct
52 Correct 789 ms 115648 KB Output is correct
53 Correct 872 ms 115752 KB Output is correct
54 Correct 61 ms 11776 KB Output is correct
55 Correct 61 ms 11852 KB Output is correct
56 Correct 117 ms 18284 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 71 ms 8072 KB Output is correct
59 Correct 66 ms 8120 KB Output is correct
60 Correct 727 ms 78644 KB Output is correct
61 Correct 64 ms 8124 KB Output is correct
62 Correct 64 ms 8076 KB Output is correct
63 Correct 62 ms 8140 KB Output is correct
64 Correct 64 ms 8108 KB Output is correct
65 Correct 60 ms 8124 KB Output is correct
66 Correct 60 ms 8084 KB Output is correct
67 Correct 60 ms 8092 KB Output is correct
68 Correct 72 ms 8036 KB Output is correct
69 Correct 65 ms 8140 KB Output is correct
70 Correct 894 ms 78548 KB Output is correct
71 Correct 64 ms 8164 KB Output is correct
72 Correct 640 ms 115700 KB Output is correct
73 Correct 658 ms 115724 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 1 ms 332 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 7 ms 1492 KB Output is correct
80 Correct 780 ms 115716 KB Output is correct
81 Correct 727 ms 115672 KB Output is correct
82 Correct 868 ms 115824 KB Output is correct
83 Correct 849 ms 115608 KB Output is correct
84 Correct 880 ms 115784 KB Output is correct
85 Correct 856 ms 115672 KB Output is correct
86 Correct 117 ms 18152 KB Output is correct
87 Correct 1 ms 212 KB Output is correct