답안 #203149

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
203149 2020-02-19T14:13:57 Z Mercenary 이상한 기계 (APIO19_strange_device) C++14
100 / 100
810 ms 53524 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int n;
ll A , B;
const ll inf = (ll)1e18 + 3;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n >> A >> B;
    ll d = __gcd(A,B+1);A /= d;
    if(A > inf / B)A = inf;
    else A *= B;
    vector<pair<ll,ll>> val;
    while(n--){
        ll l ,r;cin >> l >> r;
        if(r - l + 1 >= A)tie(l,r) = mp(0,A-1);
        l %= A;r %= A;
//        cout << l << " " << r << endl;
        if(l <= r)val.pb(mp(l,r));
        else val.pb(mp(0,r)),val.pb(mp(l,A-1));
    }
    sort(val.begin(),val.end());
    ll cur = 0 , res = 0;
    for(auto c : val){
        if(cur <= c.second){
            res += c.second - max(cur,c.first) + 1;
        }
//        cout << c.first << " " <<  c.second << " " << cur << " " << res << endl;
        cur = max(cur,c.second+1);
    }
    cout << res;
}


Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:28:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:29:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 11 ms 1144 KB Output is correct
3 Correct 11 ms 1144 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 11 ms 1144 KB Output is correct
17 Correct 65 ms 3692 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 429 ms 17140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 532 ms 17332 KB Output is correct
3 Correct 564 ms 53524 KB Output is correct
4 Correct 562 ms 53316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 532 ms 17332 KB Output is correct
3 Correct 564 ms 53524 KB Output is correct
4 Correct 562 ms 53316 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 599 ms 53184 KB Output is correct
7 Correct 579 ms 53260 KB Output is correct
8 Correct 577 ms 53260 KB Output is correct
9 Correct 665 ms 53128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 532 ms 17332 KB Output is correct
3 Correct 564 ms 53524 KB Output is correct
4 Correct 562 ms 53316 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 58 ms 5756 KB Output is correct
7 Correct 65 ms 5736 KB Output is correct
8 Correct 61 ms 5736 KB Output is correct
9 Correct 64 ms 5776 KB Output is correct
10 Correct 63 ms 5712 KB Output is correct
11 Correct 67 ms 5760 KB Output is correct
12 Correct 59 ms 5740 KB Output is correct
13 Correct 74 ms 5788 KB Output is correct
14 Correct 62 ms 5692 KB Output is correct
15 Correct 68 ms 5740 KB Output is correct
16 Correct 79 ms 5828 KB Output is correct
17 Correct 64 ms 5780 KB Output is correct
18 Correct 602 ms 53156 KB Output is correct
19 Correct 601 ms 53112 KB Output is correct
20 Correct 677 ms 53092 KB Output is correct
21 Correct 70 ms 5736 KB Output is correct
22 Correct 62 ms 5684 KB Output is correct
23 Correct 218 ms 18488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 66 ms 5820 KB Output is correct
3 Correct 62 ms 5736 KB Output is correct
4 Correct 673 ms 53064 KB Output is correct
5 Correct 69 ms 5736 KB Output is correct
6 Correct 68 ms 5756 KB Output is correct
7 Correct 72 ms 5684 KB Output is correct
8 Correct 67 ms 5812 KB Output is correct
9 Correct 75 ms 5840 KB Output is correct
10 Correct 75 ms 5756 KB Output is correct
11 Correct 72 ms 5776 KB Output is correct
12 Correct 65 ms 5740 KB Output is correct
13 Correct 66 ms 5680 KB Output is correct
14 Correct 810 ms 53136 KB Output is correct
15 Correct 74 ms 5736 KB Output is correct
16 Correct 668 ms 53076 KB Output is correct
17 Correct 667 ms 53008 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 11 ms 1144 KB Output is correct
3 Correct 11 ms 1144 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 11 ms 1144 KB Output is correct
17 Correct 65 ms 3692 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 6 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 429 ms 17140 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 532 ms 17332 KB Output is correct
31 Correct 564 ms 53524 KB Output is correct
32 Correct 562 ms 53316 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 599 ms 53184 KB Output is correct
35 Correct 579 ms 53260 KB Output is correct
36 Correct 577 ms 53260 KB Output is correct
37 Correct 665 ms 53128 KB Output is correct
38 Correct 5 ms 376 KB Output is correct
39 Correct 58 ms 5756 KB Output is correct
40 Correct 65 ms 5736 KB Output is correct
41 Correct 61 ms 5736 KB Output is correct
42 Correct 64 ms 5776 KB Output is correct
43 Correct 63 ms 5712 KB Output is correct
44 Correct 67 ms 5760 KB Output is correct
45 Correct 59 ms 5740 KB Output is correct
46 Correct 74 ms 5788 KB Output is correct
47 Correct 62 ms 5692 KB Output is correct
48 Correct 68 ms 5740 KB Output is correct
49 Correct 79 ms 5828 KB Output is correct
50 Correct 64 ms 5780 KB Output is correct
51 Correct 602 ms 53156 KB Output is correct
52 Correct 601 ms 53112 KB Output is correct
53 Correct 677 ms 53092 KB Output is correct
54 Correct 70 ms 5736 KB Output is correct
55 Correct 62 ms 5684 KB Output is correct
56 Correct 218 ms 18488 KB Output is correct
57 Correct 5 ms 376 KB Output is correct
58 Correct 66 ms 5820 KB Output is correct
59 Correct 62 ms 5736 KB Output is correct
60 Correct 673 ms 53064 KB Output is correct
61 Correct 69 ms 5736 KB Output is correct
62 Correct 68 ms 5756 KB Output is correct
63 Correct 72 ms 5684 KB Output is correct
64 Correct 67 ms 5812 KB Output is correct
65 Correct 75 ms 5840 KB Output is correct
66 Correct 75 ms 5756 KB Output is correct
67 Correct 72 ms 5776 KB Output is correct
68 Correct 65 ms 5740 KB Output is correct
69 Correct 66 ms 5680 KB Output is correct
70 Correct 810 ms 53136 KB Output is correct
71 Correct 74 ms 5736 KB Output is correct
72 Correct 668 ms 53076 KB Output is correct
73 Correct 667 ms 53008 KB Output is correct
74 Correct 5 ms 376 KB Output is correct
75 Correct 5 ms 376 KB Output is correct
76 Correct 5 ms 376 KB Output is correct
77 Correct 5 ms 376 KB Output is correct
78 Correct 5 ms 376 KB Output is correct
79 Correct 10 ms 1144 KB Output is correct
80 Correct 806 ms 52900 KB Output is correct
81 Correct 777 ms 52952 KB Output is correct
82 Correct 675 ms 52992 KB Output is correct
83 Correct 666 ms 52840 KB Output is correct
84 Correct 675 ms 52992 KB Output is correct
85 Correct 644 ms 53184 KB Output is correct
86 Correct 206 ms 18528 KB Output is correct
87 Correct 5 ms 376 KB Output is correct