답안 #404764

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
404764 2021-05-15T00:12:39 Z gevacrt 이상한 기계 (APIO19_strange_device) C++17
100 / 100
584 ms 35144 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define int ll

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

#define INF INT_MAX
#define MOD 1000000007
#define all(x) x.begin(), x.end()

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int Q, A, B; cin >> Q >> A >> B;
    int A1 = A/__gcd(A, B+1);

    if(A1 <= int(1e18)/B) A1 *= B;
    else A1 = 1e18+10;


    vii RC; RC.reserve(Q*2);
    while(Q--){
        int l, r; cin >> l >> r;
        if(r-l+1 >= A1) RC.push_back({0, A1-1});
        else{
            int lm = l%A1, rm = r%A1;
            if(lm <= rm) RC.push_back({lm, rm});
            else RC.push_back({lm, A1-1}), RC.push_back({0, rm});
        }
    }

    sort(all(RC)); int ans = 0, prev = -1;
    for(auto [l, r] : RC){
        l = max(l, prev+1);
        ans += max(0ll, r-l+1);
        prev = max(prev, r);
    }
    cout << ans << endl;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 6 ms 460 KB Output is correct
3 Correct 6 ms 460 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 460 KB Output is correct
17 Correct 52 ms 1764 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 358 ms 15840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 544 ms 15892 KB Output is correct
3 Correct 472 ms 15844 KB Output is correct
4 Correct 463 ms 16040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 544 ms 15892 KB Output is correct
3 Correct 472 ms 15844 KB Output is correct
4 Correct 463 ms 16040 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 474 ms 16200 KB Output is correct
7 Correct 476 ms 15960 KB Output is correct
8 Correct 483 ms 15992 KB Output is correct
9 Correct 505 ms 16000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 544 ms 15892 KB Output is correct
3 Correct 472 ms 15844 KB Output is correct
4 Correct 463 ms 16040 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 48 ms 1752 KB Output is correct
7 Correct 52 ms 1800 KB Output is correct
8 Correct 48 ms 1860 KB Output is correct
9 Correct 47 ms 1852 KB Output is correct
10 Correct 46 ms 1860 KB Output is correct
11 Correct 48 ms 1784 KB Output is correct
12 Correct 46 ms 1796 KB Output is correct
13 Correct 49 ms 1860 KB Output is correct
14 Correct 48 ms 1780 KB Output is correct
15 Correct 53 ms 1764 KB Output is correct
16 Correct 50 ms 1748 KB Output is correct
17 Correct 47 ms 1868 KB Output is correct
18 Correct 534 ms 16004 KB Output is correct
19 Correct 467 ms 35076 KB Output is correct
20 Correct 539 ms 34992 KB Output is correct
21 Correct 51 ms 5568 KB Output is correct
22 Correct 50 ms 5568 KB Output is correct
23 Correct 152 ms 18100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 60 ms 1780 KB Output is correct
3 Correct 49 ms 1868 KB Output is correct
4 Correct 556 ms 15980 KB Output is correct
5 Correct 50 ms 5564 KB Output is correct
6 Correct 51 ms 5580 KB Output is correct
7 Correct 50 ms 5532 KB Output is correct
8 Correct 52 ms 5520 KB Output is correct
9 Correct 50 ms 5572 KB Output is correct
10 Correct 60 ms 5688 KB Output is correct
11 Correct 51 ms 5572 KB Output is correct
12 Correct 46 ms 5576 KB Output is correct
13 Correct 53 ms 5572 KB Output is correct
14 Correct 548 ms 34460 KB Output is correct
15 Correct 51 ms 5560 KB Output is correct
16 Correct 481 ms 35144 KB Output is correct
17 Correct 519 ms 35084 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 6 ms 460 KB Output is correct
3 Correct 6 ms 460 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 5 ms 460 KB Output is correct
17 Correct 52 ms 1764 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 358 ms 15840 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 544 ms 15892 KB Output is correct
31 Correct 472 ms 15844 KB Output is correct
32 Correct 463 ms 16040 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 474 ms 16200 KB Output is correct
35 Correct 476 ms 15960 KB Output is correct
36 Correct 483 ms 15992 KB Output is correct
37 Correct 505 ms 16000 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 48 ms 1752 KB Output is correct
40 Correct 52 ms 1800 KB Output is correct
41 Correct 48 ms 1860 KB Output is correct
42 Correct 47 ms 1852 KB Output is correct
43 Correct 46 ms 1860 KB Output is correct
44 Correct 48 ms 1784 KB Output is correct
45 Correct 46 ms 1796 KB Output is correct
46 Correct 49 ms 1860 KB Output is correct
47 Correct 48 ms 1780 KB Output is correct
48 Correct 53 ms 1764 KB Output is correct
49 Correct 50 ms 1748 KB Output is correct
50 Correct 47 ms 1868 KB Output is correct
51 Correct 534 ms 16004 KB Output is correct
52 Correct 467 ms 35076 KB Output is correct
53 Correct 539 ms 34992 KB Output is correct
54 Correct 51 ms 5568 KB Output is correct
55 Correct 50 ms 5568 KB Output is correct
56 Correct 152 ms 18100 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 60 ms 1780 KB Output is correct
59 Correct 49 ms 1868 KB Output is correct
60 Correct 556 ms 15980 KB Output is correct
61 Correct 50 ms 5564 KB Output is correct
62 Correct 51 ms 5580 KB Output is correct
63 Correct 50 ms 5532 KB Output is correct
64 Correct 52 ms 5520 KB Output is correct
65 Correct 50 ms 5572 KB Output is correct
66 Correct 60 ms 5688 KB Output is correct
67 Correct 51 ms 5572 KB Output is correct
68 Correct 46 ms 5576 KB Output is correct
69 Correct 53 ms 5572 KB Output is correct
70 Correct 548 ms 34460 KB Output is correct
71 Correct 51 ms 5560 KB Output is correct
72 Correct 481 ms 35144 KB Output is correct
73 Correct 519 ms 35084 KB Output is correct
74 Correct 1 ms 204 KB Output is correct
75 Correct 1 ms 204 KB Output is correct
76 Correct 1 ms 204 KB Output is correct
77 Correct 1 ms 204 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 5 ms 844 KB Output is correct
80 Correct 549 ms 34936 KB Output is correct
81 Correct 565 ms 35012 KB Output is correct
82 Correct 528 ms 35092 KB Output is correct
83 Correct 528 ms 35016 KB Output is correct
84 Correct 532 ms 34996 KB Output is correct
85 Correct 584 ms 35096 KB Output is correct
86 Correct 150 ms 18116 KB Output is correct
87 Correct 1 ms 204 KB Output is correct