Submission #566832

# Submission time Handle Problem Language Result Execution time Memory
566832 2022-05-23T02:51:29 Z Aktan Strange Device (APIO19_strange_device) C++14
100 / 100
750 ms 100108 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template<class T>
using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define ft first
#define sc second
const int mod=1e9+7,INF=1e18+10,N=1e5;

main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	int n,a,b;
	cin >> n >> a >> b;
	int ans=0,tot=a/__gcd(a,b+1);
	if(tot>INF/b){
		tot=INF;
	}
	else{
		tot*=b;
	}
	set<pair<int,int>> s;
	for(int i=0;i<n;i++){
		int l,r;
		cin >> l >> r;
		if(r-l+1>=tot){
			cout << tot ;
			return 0;
		}
		l%=tot;
		r%=tot;
		if(l<=r){
			s.insert({l,r});		
		}
		else{
			s.insert({l,tot-1});
			s.insert({0,r});
		}
	}
	int r=-1;
	for(auto x : s){
		if(r<x.ft){
			ans+=x.sc-x.ft+1;
		}
		else if(r<x.sc){
			ans+=x.sc-r;
		}
		r=max(x.sc,r);
	}
	cout << ans << "\n";
}



Compilation message

strange_device.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   13 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 8 ms 1212 KB Output is correct
3 Correct 6 ms 1228 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 6 ms 1224 KB Output is correct
17 Correct 56 ms 6876 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 456 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 280 ms 25368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 639 ms 63060 KB Output is correct
3 Correct 676 ms 80572 KB Output is correct
4 Correct 673 ms 99912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 639 ms 63060 KB Output is correct
3 Correct 676 ms 80572 KB Output is correct
4 Correct 673 ms 99912 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 645 ms 100068 KB Output is correct
7 Correct 692 ms 99936 KB Output is correct
8 Correct 649 ms 100044 KB Output is correct
9 Correct 699 ms 100108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 639 ms 63060 KB Output is correct
3 Correct 676 ms 80572 KB Output is correct
4 Correct 673 ms 99912 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 57 ms 10164 KB Output is correct
7 Correct 56 ms 10256 KB Output is correct
8 Correct 80 ms 10220 KB Output is correct
9 Correct 70 ms 10280 KB Output is correct
10 Correct 57 ms 10172 KB Output is correct
11 Correct 58 ms 10208 KB Output is correct
12 Correct 53 ms 10176 KB Output is correct
13 Correct 61 ms 10168 KB Output is correct
14 Correct 56 ms 10272 KB Output is correct
15 Correct 68 ms 10308 KB Output is correct
16 Correct 69 ms 10292 KB Output is correct
17 Correct 57 ms 10284 KB Output is correct
18 Correct 623 ms 83108 KB Output is correct
19 Correct 668 ms 99956 KB Output is correct
20 Correct 677 ms 99980 KB Output is correct
21 Correct 58 ms 10320 KB Output is correct
22 Correct 55 ms 10220 KB Output is correct
23 Correct 134 ms 12824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 61 ms 10228 KB Output is correct
3 Correct 62 ms 10164 KB Output is correct
4 Correct 705 ms 81620 KB Output is correct
5 Correct 57 ms 10288 KB Output is correct
6 Correct 62 ms 10236 KB Output is correct
7 Correct 62 ms 10164 KB Output is correct
8 Correct 64 ms 10220 KB Output is correct
9 Correct 68 ms 10320 KB Output is correct
10 Correct 59 ms 10216 KB Output is correct
11 Correct 59 ms 10200 KB Output is correct
12 Correct 54 ms 10248 KB Output is correct
13 Correct 61 ms 10276 KB Output is correct
14 Correct 702 ms 100032 KB Output is correct
15 Correct 57 ms 10228 KB Output is correct
16 Correct 684 ms 99912 KB Output is correct
17 Correct 683 ms 100092 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 8 ms 1212 KB Output is correct
3 Correct 6 ms 1228 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 6 ms 1224 KB Output is correct
17 Correct 56 ms 6876 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 324 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 316 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 316 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 2 ms 456 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 280 ms 25368 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 639 ms 63060 KB Output is correct
31 Correct 676 ms 80572 KB Output is correct
32 Correct 673 ms 99912 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 645 ms 100068 KB Output is correct
35 Correct 692 ms 99936 KB Output is correct
36 Correct 649 ms 100044 KB Output is correct
37 Correct 699 ms 100108 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 57 ms 10164 KB Output is correct
40 Correct 56 ms 10256 KB Output is correct
41 Correct 80 ms 10220 KB Output is correct
42 Correct 70 ms 10280 KB Output is correct
43 Correct 57 ms 10172 KB Output is correct
44 Correct 58 ms 10208 KB Output is correct
45 Correct 53 ms 10176 KB Output is correct
46 Correct 61 ms 10168 KB Output is correct
47 Correct 56 ms 10272 KB Output is correct
48 Correct 68 ms 10308 KB Output is correct
49 Correct 69 ms 10292 KB Output is correct
50 Correct 57 ms 10284 KB Output is correct
51 Correct 623 ms 83108 KB Output is correct
52 Correct 668 ms 99956 KB Output is correct
53 Correct 677 ms 99980 KB Output is correct
54 Correct 58 ms 10320 KB Output is correct
55 Correct 55 ms 10220 KB Output is correct
56 Correct 134 ms 12824 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 61 ms 10228 KB Output is correct
59 Correct 62 ms 10164 KB Output is correct
60 Correct 705 ms 81620 KB Output is correct
61 Correct 57 ms 10288 KB Output is correct
62 Correct 62 ms 10236 KB Output is correct
63 Correct 62 ms 10164 KB Output is correct
64 Correct 64 ms 10220 KB Output is correct
65 Correct 68 ms 10320 KB Output is correct
66 Correct 59 ms 10216 KB Output is correct
67 Correct 59 ms 10200 KB Output is correct
68 Correct 54 ms 10248 KB Output is correct
69 Correct 61 ms 10276 KB Output is correct
70 Correct 702 ms 100032 KB Output is correct
71 Correct 57 ms 10228 KB Output is correct
72 Correct 684 ms 99912 KB Output is correct
73 Correct 683 ms 100092 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 320 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 1 ms 324 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 7 ms 1228 KB Output is correct
80 Correct 692 ms 83392 KB Output is correct
81 Correct 719 ms 83452 KB Output is correct
82 Correct 706 ms 83460 KB Output is correct
83 Correct 732 ms 83080 KB Output is correct
84 Correct 692 ms 83152 KB Output is correct
85 Correct 750 ms 83232 KB Output is correct
86 Correct 119 ms 12880 KB Output is correct
87 Correct 1 ms 320 KB Output is correct