답안 #598914

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
598914 2022-07-19T07:36:17 Z sentheta 이상한 기계 (APIO19_strange_device) C++17
100 / 100
497 ms 53220 KB
// author : sentheta aka vanwij
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<random>
#include<chrono>
#include<cmath>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;

#define Int long long
#define V vector
#define pii pair<int,int>
#define ff first
#define ss second

#define rand() (uniform_int_distribution<int>(0,1<<30)(rng))
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

#define pow2(x) (1LL<<(x))
#define msb(x) (63-__builtin_clzll(x))
#define bitcnt(x) (__builtin_popcountll(x))

#define nl '\n'
#define _ << ' ' <<
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define dbg(x) if(1) cout << "?" << #x << " : " << (x) << endl << flush;

#define int long long
const Int MOD = 1e9+7;
//const Int MOD = 998244353;
Int bpow(Int a,Int b){
	Int ret = 1;
	for(;b; a=a*a%MOD,b/=2) if(b&1) ret = ret*a%MOD;
	return ret;
}
Int inv(Int a){return bpow(a,MOD-2);}

void solve(); int TC;
signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	srand(chrono::steady_clock::now().time_since_epoch().count());
	cout << fixed << setprecision(7);
///cin >> TC; while(TC--) solve(); return 0;
	solve();
}





int n;
int A, B;
int len;

pii f(int x){
	return {(x+x/B)%A, x%B};
}


void solve(){
	


	cin >> n >> A >> B;

	if(A/gcd(A,B+1)*((double)(B)) > 1e18+5){
		len = 1e18+5;
	}
	else len = A/gcd(A,B+1)*B;

	//dbg(len);
	//set<pii> s;
	//rep(i,0,len) s.insert(f(i));
	//assert((int)s.size()==len);
	//rep(i,len,1e7) assert(f(i)==f(i-len));
	//return;

	priority_queue<pii> pq;

	rep(i,0,n){
		int l, r;
		cin >> l >> r;

		if(r-l+1 >= len){
			cout << len << nl; return;
		}
		l %= len; r %= len;

		if(l <= r){
			pq.push({-l, r});
		}
		else{
			pq.push({-l, len-1});
			pq.push({0, r});
		}
	}
	
	int ans = 0;

	int l = -1, r = -2;
	while(!pq.empty()){
		auto[tl,tr] = pq.top(); pq.pop();
		tl *= -1;
		//cout << tl _ tr << nl;

		if(r < tl){
			ans += r-l+1;

			l = tl; r = tr;
		}
		else{
			r = max(r, tr);
		}
	}
	ans += r-l+1;

	cout << ans << nl;
	
	
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 4 ms 724 KB Output is correct
3 Correct 8 ms 608 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 708 KB Output is correct
17 Correct 40 ms 2512 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 401 ms 16860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 448 ms 16780 KB Output is correct
3 Correct 497 ms 53180 KB Output is correct
4 Correct 485 ms 53204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 448 ms 16780 KB Output is correct
3 Correct 497 ms 53180 KB Output is correct
4 Correct 485 ms 53204 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 477 ms 53120 KB Output is correct
7 Correct 450 ms 53136 KB Output is correct
8 Correct 425 ms 53132 KB Output is correct
9 Correct 410 ms 53220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 448 ms 16780 KB Output is correct
3 Correct 497 ms 53180 KB Output is correct
4 Correct 485 ms 53204 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 44 ms 5736 KB Output is correct
7 Correct 46 ms 5700 KB Output is correct
8 Correct 42 ms 5640 KB Output is correct
9 Correct 41 ms 5740 KB Output is correct
10 Correct 43 ms 5740 KB Output is correct
11 Correct 44 ms 5692 KB Output is correct
12 Correct 42 ms 5716 KB Output is correct
13 Correct 40 ms 5700 KB Output is correct
14 Correct 48 ms 5836 KB Output is correct
15 Correct 42 ms 5704 KB Output is correct
16 Correct 41 ms 5700 KB Output is correct
17 Correct 40 ms 5704 KB Output is correct
18 Correct 433 ms 53144 KB Output is correct
19 Correct 431 ms 53116 KB Output is correct
20 Correct 405 ms 53136 KB Output is correct
21 Correct 41 ms 5756 KB Output is correct
22 Correct 41 ms 5652 KB Output is correct
23 Correct 144 ms 18472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 43 ms 5676 KB Output is correct
3 Correct 40 ms 5696 KB Output is correct
4 Correct 423 ms 53184 KB Output is correct
5 Correct 41 ms 5696 KB Output is correct
6 Correct 40 ms 5696 KB Output is correct
7 Correct 40 ms 5656 KB Output is correct
8 Correct 41 ms 5668 KB Output is correct
9 Correct 40 ms 5708 KB Output is correct
10 Correct 43 ms 5664 KB Output is correct
11 Correct 42 ms 5716 KB Output is correct
12 Correct 43 ms 5696 KB Output is correct
13 Correct 39 ms 5696 KB Output is correct
14 Correct 410 ms 53196 KB Output is correct
15 Correct 40 ms 5636 KB Output is correct
16 Correct 415 ms 53156 KB Output is correct
17 Correct 413 ms 53116 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 4 ms 724 KB Output is correct
3 Correct 8 ms 608 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 708 KB Output is correct
17 Correct 40 ms 2512 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 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 401 ms 16860 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 448 ms 16780 KB Output is correct
31 Correct 497 ms 53180 KB Output is correct
32 Correct 485 ms 53204 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 477 ms 53120 KB Output is correct
35 Correct 450 ms 53136 KB Output is correct
36 Correct 425 ms 53132 KB Output is correct
37 Correct 410 ms 53220 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 44 ms 5736 KB Output is correct
40 Correct 46 ms 5700 KB Output is correct
41 Correct 42 ms 5640 KB Output is correct
42 Correct 41 ms 5740 KB Output is correct
43 Correct 43 ms 5740 KB Output is correct
44 Correct 44 ms 5692 KB Output is correct
45 Correct 42 ms 5716 KB Output is correct
46 Correct 40 ms 5700 KB Output is correct
47 Correct 48 ms 5836 KB Output is correct
48 Correct 42 ms 5704 KB Output is correct
49 Correct 41 ms 5700 KB Output is correct
50 Correct 40 ms 5704 KB Output is correct
51 Correct 433 ms 53144 KB Output is correct
52 Correct 431 ms 53116 KB Output is correct
53 Correct 405 ms 53136 KB Output is correct
54 Correct 41 ms 5756 KB Output is correct
55 Correct 41 ms 5652 KB Output is correct
56 Correct 144 ms 18472 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 43 ms 5676 KB Output is correct
59 Correct 40 ms 5696 KB Output is correct
60 Correct 423 ms 53184 KB Output is correct
61 Correct 41 ms 5696 KB Output is correct
62 Correct 40 ms 5696 KB Output is correct
63 Correct 40 ms 5656 KB Output is correct
64 Correct 41 ms 5668 KB Output is correct
65 Correct 40 ms 5708 KB Output is correct
66 Correct 43 ms 5664 KB Output is correct
67 Correct 42 ms 5716 KB Output is correct
68 Correct 43 ms 5696 KB Output is correct
69 Correct 39 ms 5696 KB Output is correct
70 Correct 410 ms 53196 KB Output is correct
71 Correct 40 ms 5636 KB Output is correct
72 Correct 415 ms 53156 KB Output is correct
73 Correct 413 ms 53116 KB Output is correct
74 Correct 0 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 324 KB Output is correct
78 Correct 0 ms 324 KB Output is correct
79 Correct 5 ms 1064 KB Output is correct
80 Correct 408 ms 53184 KB Output is correct
81 Correct 433 ms 53144 KB Output is correct
82 Correct 424 ms 53192 KB Output is correct
83 Correct 440 ms 53108 KB Output is correct
84 Correct 445 ms 53172 KB Output is correct
85 Correct 430 ms 53172 KB Output is correct
86 Correct 148 ms 18464 KB Output is correct
87 Correct 1 ms 324 KB Output is correct