답안 #1035275

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1035275 2024-07-26T08:35:38 Z KasymK 이상한 기계 (APIO19_strange_device) C++17
100 / 100
334 ms 69820 KB
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int MOD = 1e9+7;
const int N = 1e6+5;
ll l[N], r[N];

int main(){
	int n;
	ll a, b;
	scanf("%d %lld %lld", &n, &a, &b);
	__int128 m = (__int128)a/__gcd(a, b+1)*b;
	for(int i = 1 ; i <= n; ++i)
		scanf("%lld %lld", &l[i], &r[i]);
	vector<pll> v;
	for(int i = 1; i <= n; ++i){
		if(r[i]-l[i]+1 >= m)
			v.pb({0, m-1});
		else if(l[i]%m > r[i]%m)
			v.pb({l[i]%m, m-1}), v.pb({0, r[i]%m});
		else
			v.pb({l[i]%m, r[i]%m});
	}
	sort(all(v));
	ll l_ = v[0].ff, r_ = v[0].ss;
	ll answer = 0;
	int n_ = (int)v.size();
	for(int i = 0; i < n_; ++i){
		// I am doing kerim's technique instead of sweep line
		// because Kerim's technique is O(n), but sweep line is O(nlog(n)) in worst case
		// because in sweep line we use like set data structure's
		if(v[i].ff <= r_)
			umax(r_, v[i].ss);
		else
			answer += (r_-l_+1), l_ = v[i].ff, r_ = v[i].ss;
	}
	answer += (r_-l_+1);
	printf("%lld\n", answer);
	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  scanf("%d %lld %lld", &n, &a, &b);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |   scanf("%lld %lld", &l[i], &r[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 5 ms 1224 KB Output is correct
3 Correct 3 ms 1368 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 440 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 1368 KB Output is correct
17 Correct 32 ms 7876 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 212 ms 57604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 302 ms 69692 KB Output is correct
3 Correct 308 ms 69560 KB Output is correct
4 Correct 292 ms 69564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 302 ms 69692 KB Output is correct
3 Correct 308 ms 69560 KB Output is correct
4 Correct 292 ms 69564 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 319 ms 69560 KB Output is correct
7 Correct 301 ms 69672 KB Output is correct
8 Correct 317 ms 69612 KB Output is correct
9 Correct 305 ms 69564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 302 ms 69692 KB Output is correct
3 Correct 308 ms 69560 KB Output is correct
4 Correct 292 ms 69564 KB Output is correct
5 Correct 0 ms 440 KB Output is correct
6 Correct 28 ms 7768 KB Output is correct
7 Correct 32 ms 7880 KB Output is correct
8 Correct 29 ms 7864 KB Output is correct
9 Correct 29 ms 7880 KB Output is correct
10 Correct 28 ms 7876 KB Output is correct
11 Correct 30 ms 7880 KB Output is correct
12 Correct 30 ms 7824 KB Output is correct
13 Correct 36 ms 7880 KB Output is correct
14 Correct 28 ms 7876 KB Output is correct
15 Correct 33 ms 7800 KB Output is correct
16 Correct 33 ms 7888 KB Output is correct
17 Correct 30 ms 7736 KB Output is correct
18 Correct 308 ms 69664 KB Output is correct
19 Correct 284 ms 69564 KB Output is correct
20 Correct 319 ms 69564 KB Output is correct
21 Correct 30 ms 7880 KB Output is correct
22 Correct 28 ms 7876 KB Output is correct
23 Correct 89 ms 26556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 31 ms 7880 KB Output is correct
3 Correct 36 ms 7732 KB Output is correct
4 Correct 316 ms 69560 KB Output is correct
5 Correct 31 ms 7880 KB Output is correct
6 Correct 31 ms 7884 KB Output is correct
7 Correct 34 ms 7876 KB Output is correct
8 Correct 32 ms 7884 KB Output is correct
9 Correct 30 ms 7876 KB Output is correct
10 Correct 31 ms 7888 KB Output is correct
11 Correct 31 ms 7920 KB Output is correct
12 Correct 28 ms 7672 KB Output is correct
13 Correct 30 ms 7880 KB Output is correct
14 Correct 320 ms 69664 KB Output is correct
15 Correct 31 ms 7888 KB Output is correct
16 Correct 285 ms 69508 KB Output is correct
17 Correct 297 ms 69560 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 5 ms 1224 KB Output is correct
3 Correct 3 ms 1368 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 440 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 1368 KB Output is correct
17 Correct 32 ms 7876 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 212 ms 57604 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 302 ms 69692 KB Output is correct
31 Correct 308 ms 69560 KB Output is correct
32 Correct 292 ms 69564 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 319 ms 69560 KB Output is correct
35 Correct 301 ms 69672 KB Output is correct
36 Correct 317 ms 69612 KB Output is correct
37 Correct 305 ms 69564 KB Output is correct
38 Correct 0 ms 440 KB Output is correct
39 Correct 28 ms 7768 KB Output is correct
40 Correct 32 ms 7880 KB Output is correct
41 Correct 29 ms 7864 KB Output is correct
42 Correct 29 ms 7880 KB Output is correct
43 Correct 28 ms 7876 KB Output is correct
44 Correct 30 ms 7880 KB Output is correct
45 Correct 30 ms 7824 KB Output is correct
46 Correct 36 ms 7880 KB Output is correct
47 Correct 28 ms 7876 KB Output is correct
48 Correct 33 ms 7800 KB Output is correct
49 Correct 33 ms 7888 KB Output is correct
50 Correct 30 ms 7736 KB Output is correct
51 Correct 308 ms 69664 KB Output is correct
52 Correct 284 ms 69564 KB Output is correct
53 Correct 319 ms 69564 KB Output is correct
54 Correct 30 ms 7880 KB Output is correct
55 Correct 28 ms 7876 KB Output is correct
56 Correct 89 ms 26556 KB Output is correct
57 Correct 0 ms 600 KB Output is correct
58 Correct 31 ms 7880 KB Output is correct
59 Correct 36 ms 7732 KB Output is correct
60 Correct 316 ms 69560 KB Output is correct
61 Correct 31 ms 7880 KB Output is correct
62 Correct 31 ms 7884 KB Output is correct
63 Correct 34 ms 7876 KB Output is correct
64 Correct 32 ms 7884 KB Output is correct
65 Correct 30 ms 7876 KB Output is correct
66 Correct 31 ms 7888 KB Output is correct
67 Correct 31 ms 7920 KB Output is correct
68 Correct 28 ms 7672 KB Output is correct
69 Correct 30 ms 7880 KB Output is correct
70 Correct 320 ms 69664 KB Output is correct
71 Correct 31 ms 7888 KB Output is correct
72 Correct 285 ms 69508 KB Output is correct
73 Correct 297 ms 69560 KB Output is correct
74 Correct 1 ms 344 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 0 ms 440 KB Output is correct
79 Correct 3 ms 1372 KB Output is correct
80 Correct 331 ms 69692 KB Output is correct
81 Correct 300 ms 69560 KB Output is correct
82 Correct 334 ms 69676 KB Output is correct
83 Correct 299 ms 69576 KB Output is correct
84 Correct 314 ms 69820 KB Output is correct
85 Correct 316 ms 69744 KB Output is correct
86 Correct 87 ms 26556 KB Output is correct
87 Correct 0 ms 344 KB Output is correct