답안 #359425

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
359425 2021-01-27T01:37:59 Z eyangch 이상한 기계 (APIO19_strange_device) C++17
100 / 100
940 ms 100328 KB
#include <bits/stdc++.h>
#define endl "\n"
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;

int N;
ll A, B, MOD;
set<pii> s;

ll gcdf(ll a, ll b){
    return (b == 0 ? a : gcdf(b, a%b));
}

void upd(ll l, ll r){
    auto it = s.upper_bound({l, LLONG_MAX});
    vector<pii> rm;
    if(it != s.begin()){
        it--;
        if(it -> second >= r){
            return;
        }
        if(it -> second >= l){
            l = it -> first;
            rm.push_back(*it);
        }
        it++;
    }
    for(; it != s.end(); it++){
        if(it -> first > r) break;
        l = min(l, it -> first);
        r = max(r, it -> second);
        rm.push_back(*it);
    }
    for(pii i : rm){
        s.erase(i);
    }
    s.insert({l, r});
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> A >> B;
    __int128 mp = (__int128)(A / gcdf(A, B+1)) * B;
    MOD = (mp > 1e18 ? 1e18+5 : (ll)mp);
    for(int i = 0; i < N; i++){
        ll l, r; cin >> l >> r;
        if(r - l + 1 >= MOD){
            upd(0, MOD-1);
        }
        l %= MOD, r %= MOD;
        if(l > r){
            upd(l, MOD-1);
            upd(0, r);
        }else{
            upd(l, r);
        }
    }
    ll ans = 0;
    for(pii i : s){
        ans += i.se - i.fi + 1;
    }
    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 7 ms 1260 KB Output is correct
3 Correct 9 ms 1260 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 364 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 7 ms 1260 KB Output is correct
17 Correct 76 ms 8684 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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 2 ms 364 KB Output is correct
5 Correct 304 ms 580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 787 ms 64364 KB Output is correct
3 Correct 784 ms 63340 KB Output is correct
4 Correct 884 ms 63384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 787 ms 64364 KB Output is correct
3 Correct 784 ms 63340 KB Output is correct
4 Correct 884 ms 63384 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 773 ms 63320 KB Output is correct
7 Correct 818 ms 63340 KB Output is correct
8 Correct 775 ms 63600 KB Output is correct
9 Correct 851 ms 63292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 787 ms 64364 KB Output is correct
3 Correct 784 ms 63340 KB Output is correct
4 Correct 884 ms 63384 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 70 ms 8556 KB Output is correct
7 Correct 73 ms 8556 KB Output is correct
8 Correct 73 ms 8684 KB Output is correct
9 Correct 77 ms 8684 KB Output is correct
10 Correct 78 ms 8556 KB Output is correct
11 Correct 74 ms 8684 KB Output is correct
12 Correct 80 ms 8684 KB Output is correct
13 Correct 77 ms 8684 KB Output is correct
14 Correct 74 ms 8684 KB Output is correct
15 Correct 84 ms 8684 KB Output is correct
16 Correct 80 ms 8812 KB Output is correct
17 Correct 79 ms 8772 KB Output is correct
18 Correct 753 ms 63340 KB Output is correct
19 Correct 789 ms 63340 KB Output is correct
20 Correct 814 ms 63408 KB Output is correct
21 Correct 72 ms 8684 KB Output is correct
22 Correct 81 ms 8684 KB Output is correct
23 Correct 126 ms 1388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 77 ms 8556 KB Output is correct
3 Correct 81 ms 8684 KB Output is correct
4 Correct 811 ms 63340 KB Output is correct
5 Correct 80 ms 8684 KB Output is correct
6 Correct 80 ms 8684 KB Output is correct
7 Correct 82 ms 8684 KB Output is correct
8 Correct 80 ms 8812 KB Output is correct
9 Correct 77 ms 8684 KB Output is correct
10 Correct 72 ms 8812 KB Output is correct
11 Correct 74 ms 8684 KB Output is correct
12 Correct 77 ms 8684 KB Output is correct
13 Correct 80 ms 8684 KB Output is correct
14 Correct 852 ms 63332 KB Output is correct
15 Correct 68 ms 8044 KB Output is correct
16 Correct 767 ms 63212 KB Output is correct
17 Correct 770 ms 63364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 7 ms 1260 KB Output is correct
3 Correct 9 ms 1260 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 364 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 7 ms 1260 KB Output is correct
17 Correct 76 ms 8684 KB Output is correct
18 Correct 1 ms 364 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 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 304 ms 580 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 787 ms 64364 KB Output is correct
31 Correct 784 ms 63340 KB Output is correct
32 Correct 884 ms 63384 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 773 ms 63320 KB Output is correct
35 Correct 818 ms 63340 KB Output is correct
36 Correct 775 ms 63600 KB Output is correct
37 Correct 851 ms 63292 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 70 ms 8556 KB Output is correct
40 Correct 73 ms 8556 KB Output is correct
41 Correct 73 ms 8684 KB Output is correct
42 Correct 77 ms 8684 KB Output is correct
43 Correct 78 ms 8556 KB Output is correct
44 Correct 74 ms 8684 KB Output is correct
45 Correct 80 ms 8684 KB Output is correct
46 Correct 77 ms 8684 KB Output is correct
47 Correct 74 ms 8684 KB Output is correct
48 Correct 84 ms 8684 KB Output is correct
49 Correct 80 ms 8812 KB Output is correct
50 Correct 79 ms 8772 KB Output is correct
51 Correct 753 ms 63340 KB Output is correct
52 Correct 789 ms 63340 KB Output is correct
53 Correct 814 ms 63408 KB Output is correct
54 Correct 72 ms 8684 KB Output is correct
55 Correct 81 ms 8684 KB Output is correct
56 Correct 126 ms 1388 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 77 ms 8556 KB Output is correct
59 Correct 81 ms 8684 KB Output is correct
60 Correct 811 ms 63340 KB Output is correct
61 Correct 80 ms 8684 KB Output is correct
62 Correct 80 ms 8684 KB Output is correct
63 Correct 82 ms 8684 KB Output is correct
64 Correct 80 ms 8812 KB Output is correct
65 Correct 77 ms 8684 KB Output is correct
66 Correct 72 ms 8812 KB Output is correct
67 Correct 74 ms 8684 KB Output is correct
68 Correct 77 ms 8684 KB Output is correct
69 Correct 80 ms 8684 KB Output is correct
70 Correct 852 ms 63332 KB Output is correct
71 Correct 68 ms 8044 KB Output is correct
72 Correct 767 ms 63212 KB Output is correct
73 Correct 770 ms 63364 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 11 ms 1388 KB Output is correct
80 Correct 858 ms 100124 KB Output is correct
81 Correct 827 ms 100196 KB Output is correct
82 Correct 893 ms 100328 KB Output is correct
83 Correct 876 ms 100324 KB Output is correct
84 Correct 940 ms 100200 KB Output is correct
85 Correct 862 ms 99996 KB Output is correct
86 Correct 136 ms 13036 KB Output is correct
87 Correct 1 ms 364 KB Output is correct