답안 #448192

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
448192 2021-07-29T08:35:02 Z Vladithur 이상한 기계 (APIO19_strange_device) C++17
100 / 100
952 ms 78796 KB
//#pragma GCC optimize ("Ofast")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")
//#include <x86intrin.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define PI 3.141592653589793L
#define FAST ios::sync_with_stdio(false); cin.tie(NULL);
// Use for file I/O;
#define FIN string _fname = "input"; \
			string _is = _fname + ".in", _os = _fname + ".out"; \
			freopen(_is.c_str(), "r", stdin); \
			freopen(_os.c_str(), "w", stdout);

#define FIN2 freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define RINIT mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define gsize(x) (int)((x).size())

using namespace std;
//using namespace __gnu_pbds;
//typedef gp_hash_table<int, int, hash<int>> ht;

const char nl = '\n';

typedef long long ll;
typedef long double ld;
// typedef unsigned int uint;
typedef unsigned long long ull;

const ll inf = 1e9 + 10;
const ll inf2 = 1e18 + 99LL;
const ld inf3 = 1e17;
const ll mod = 1e9+7, mod2 = 998244353;
const ld eps = 1e-9;
const bool local = false;

//RINIT;
const int logn = 21, maxn = 1000000, maxm = 100000, maxn2 = 3;	

int main() {
	FAST;
	
	int n;
	cin >> n;
	ll ta, tb;
	cin >> ta >> tb;
	ll g = gcd(ta, tb + 1);
	//auto g = gcd(ta, tb);
	//ta /= g; tb /= g;
	//cout << ta << ' ' << tb << ' ' << tn << nl;
	__int128 a = ta / g, b = tb;
	__int128 tn = a * b;
	
	vector<pair<__int128, ll>> segs;
	while (n--) {
		ll l, r;
		cin >> l >> r;
		
		if (r - l + 1 >= tn) {
			segs.emplace_back(0, 1);
			segs.emplace_back(tn, -1);
		} else {
			l %= tn;
			r %= tn;
			if (l <= r) {
				segs.emplace_back(l, 1);
				segs.emplace_back(r + 1, -1);
			} else {
				segs.emplace_back(0, 1);
				segs.emplace_back(r + 1, -1);
				segs.emplace_back(l, 1);
				segs.emplace_back(tn, -1);
			}
		}
	}
	
	sort(all(segs));
	__int128 ans = 0, ti = 0, px = -1, ct = 0;
	while (ti < gsize(segs)) {
		__int128 tx = segs[ti].first;
		if (ct) ans += tx - px;
		px = tx;
		while (ti < gsize(segs) && segs[ti].first == tx) {
			ct += segs[ti].second;
			ti++;
		}
	}
	
	cout << (ll)ans << nl;
}

// © Benq 
/* stuff you should look for
	* int overflow, array bounds	
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 7 ms 1484 KB Output is correct
3 Correct 8 ms 1484 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 7 ms 1484 KB Output is correct
17 Correct 80 ms 8588 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 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 484 ms 66072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 709 ms 66116 KB Output is correct
3 Correct 743 ms 66084 KB Output is correct
4 Correct 691 ms 68136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 709 ms 66116 KB Output is correct
3 Correct 743 ms 66084 KB Output is correct
4 Correct 691 ms 68136 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 729 ms 69836 KB Output is correct
7 Correct 690 ms 69888 KB Output is correct
8 Correct 717 ms 69776 KB Output is correct
9 Correct 877 ms 69740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 709 ms 66116 KB Output is correct
3 Correct 743 ms 66084 KB Output is correct
4 Correct 691 ms 68136 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 66 ms 11308 KB Output is correct
7 Correct 70 ms 11260 KB Output is correct
8 Correct 66 ms 11316 KB Output is correct
9 Correct 68 ms 11316 KB Output is correct
10 Correct 65 ms 11224 KB Output is correct
11 Correct 69 ms 11264 KB Output is correct
12 Correct 64 ms 11296 KB Output is correct
13 Correct 75 ms 11268 KB Output is correct
14 Correct 67 ms 11324 KB Output is correct
15 Correct 83 ms 11316 KB Output is correct
16 Correct 76 ms 11272 KB Output is correct
17 Correct 68 ms 11340 KB Output is correct
18 Correct 733 ms 76300 KB Output is correct
19 Correct 695 ms 77396 KB Output is correct
20 Correct 894 ms 77272 KB Output is correct
21 Correct 82 ms 11308 KB Output is correct
22 Correct 62 ms 11316 KB Output is correct
23 Correct 194 ms 41816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 76 ms 8732 KB Output is correct
3 Correct 76 ms 8564 KB Output is correct
4 Correct 915 ms 66028 KB Output is correct
5 Correct 77 ms 8624 KB Output is correct
6 Correct 73 ms 8644 KB Output is correct
7 Correct 86 ms 8552 KB Output is correct
8 Correct 79 ms 8636 KB Output is correct
9 Correct 79 ms 8628 KB Output is correct
10 Correct 77 ms 8640 KB Output is correct
11 Correct 74 ms 8640 KB Output is correct
12 Correct 66 ms 8540 KB Output is correct
13 Correct 79 ms 8624 KB Output is correct
14 Correct 868 ms 66296 KB Output is correct
15 Correct 80 ms 8628 KB Output is correct
16 Correct 672 ms 77452 KB Output is correct
17 Correct 702 ms 76068 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 7 ms 1484 KB Output is correct
3 Correct 8 ms 1484 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 7 ms 1484 KB Output is correct
17 Correct 80 ms 8588 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 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 484 ms 66072 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 709 ms 66116 KB Output is correct
31 Correct 743 ms 66084 KB Output is correct
32 Correct 691 ms 68136 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 729 ms 69836 KB Output is correct
35 Correct 690 ms 69888 KB Output is correct
36 Correct 717 ms 69776 KB Output is correct
37 Correct 877 ms 69740 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 66 ms 11308 KB Output is correct
40 Correct 70 ms 11260 KB Output is correct
41 Correct 66 ms 11316 KB Output is correct
42 Correct 68 ms 11316 KB Output is correct
43 Correct 65 ms 11224 KB Output is correct
44 Correct 69 ms 11264 KB Output is correct
45 Correct 64 ms 11296 KB Output is correct
46 Correct 75 ms 11268 KB Output is correct
47 Correct 67 ms 11324 KB Output is correct
48 Correct 83 ms 11316 KB Output is correct
49 Correct 76 ms 11272 KB Output is correct
50 Correct 68 ms 11340 KB Output is correct
51 Correct 733 ms 76300 KB Output is correct
52 Correct 695 ms 77396 KB Output is correct
53 Correct 894 ms 77272 KB Output is correct
54 Correct 82 ms 11308 KB Output is correct
55 Correct 62 ms 11316 KB Output is correct
56 Correct 194 ms 41816 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 76 ms 8732 KB Output is correct
59 Correct 76 ms 8564 KB Output is correct
60 Correct 915 ms 66028 KB Output is correct
61 Correct 77 ms 8624 KB Output is correct
62 Correct 73 ms 8644 KB Output is correct
63 Correct 86 ms 8552 KB Output is correct
64 Correct 79 ms 8636 KB Output is correct
65 Correct 79 ms 8628 KB Output is correct
66 Correct 77 ms 8640 KB Output is correct
67 Correct 74 ms 8640 KB Output is correct
68 Correct 66 ms 8540 KB Output is correct
69 Correct 79 ms 8624 KB Output is correct
70 Correct 868 ms 66296 KB Output is correct
71 Correct 80 ms 8628 KB Output is correct
72 Correct 672 ms 77452 KB Output is correct
73 Correct 702 ms 76068 KB Output is correct
74 Correct 0 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 0 ms 312 KB Output is correct
78 Correct 0 ms 204 KB Output is correct
79 Correct 7 ms 1740 KB Output is correct
80 Correct 952 ms 76284 KB Output is correct
81 Correct 935 ms 75788 KB Output is correct
82 Correct 887 ms 75696 KB Output is correct
83 Correct 886 ms 78796 KB Output is correct
84 Correct 883 ms 75580 KB Output is correct
85 Correct 908 ms 76000 KB Output is correct
86 Correct 201 ms 41488 KB Output is correct
87 Correct 1 ms 308 KB Output is correct