Submission #964821

# Submission time Handle Problem Language Result Execution time Memory
964821 2024-04-17T15:36:06 Z LCJLY Strange Device (APIO19_strange_device) C++14
100 / 100
655 ms 100376 KB
#include <bits/stdc++.h>
using namespace std;	
 
#define int long long 
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<long long,long long>pii;
typedef pair<int,pii>pi2;

int n,a,b;
int f(int index){	
	return (index+index/b)%a;
}

int f2(int index){
	return index%b;
}

void solve(){
	cin >> n >> a >> b;
	
	__int128 lcm=(__int128)a*(__int128)b/__gcd(a,b+1);
	
	map<int,int>mp;
	
	int temp,temp2;
	for(int x=0;x<n;x++){
		cin >> temp >> temp2;
		int blk=temp/lcm;
		int blk2=temp2/lcm;
		temp%=lcm;
		temp2%=lcm;
		
		if(blk==blk2){
			mp[temp]++;
			mp[temp2+1]--;
		}
		else{
			mp[temp]++;
			mp[lcm]--;
			mp[0]++;	
			mp[temp2+1]--;
		}
	}
	
	int counter=0;
	int last=-1;
	int ans=0;
	for(auto it:mp){
		if(last!=-1&&counter>0){
			ans+=it.first-last;
		}
		counter+=it.second;
		last=it.first;
	}
	cout << ans;
}
 
int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 5 ms 1372 KB Output is correct
3 Correct 5 ms 1256 KB Output is correct
4 Correct 1 ms 344 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 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 6 ms 1292 KB Output is correct
17 Correct 50 ms 10316 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 193 ms 25544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 543 ms 100176 KB Output is correct
3 Correct 588 ms 100376 KB Output is correct
4 Correct 573 ms 100212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 543 ms 100176 KB Output is correct
3 Correct 588 ms 100376 KB Output is correct
4 Correct 573 ms 100212 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 582 ms 99780 KB Output is correct
7 Correct 545 ms 100228 KB Output is correct
8 Correct 604 ms 99848 KB Output is correct
9 Correct 589 ms 100108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 543 ms 100176 KB Output is correct
3 Correct 588 ms 100376 KB Output is correct
4 Correct 573 ms 100212 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 45 ms 10264 KB Output is correct
7 Correct 49 ms 10320 KB Output is correct
8 Correct 45 ms 10348 KB Output is correct
9 Correct 57 ms 10512 KB Output is correct
10 Correct 54 ms 10324 KB Output is correct
11 Correct 43 ms 10208 KB Output is correct
12 Correct 58 ms 10320 KB Output is correct
13 Correct 49 ms 10236 KB Output is correct
14 Correct 44 ms 10324 KB Output is correct
15 Correct 52 ms 10472 KB Output is correct
16 Correct 64 ms 10320 KB Output is correct
17 Correct 51 ms 10316 KB Output is correct
18 Correct 526 ms 100324 KB Output is correct
19 Correct 588 ms 100212 KB Output is correct
20 Correct 616 ms 99944 KB Output is correct
21 Correct 58 ms 10356 KB Output is correct
22 Correct 63 ms 10428 KB Output is correct
23 Correct 87 ms 12852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 452 KB Output is correct
2 Correct 49 ms 10308 KB Output is correct
3 Correct 50 ms 10348 KB Output is correct
4 Correct 603 ms 100000 KB Output is correct
5 Correct 61 ms 10356 KB Output is correct
6 Correct 52 ms 10408 KB Output is correct
7 Correct 54 ms 10244 KB Output is correct
8 Correct 49 ms 10348 KB Output is correct
9 Correct 56 ms 10320 KB Output is correct
10 Correct 46 ms 10260 KB Output is correct
11 Correct 49 ms 10384 KB Output is correct
12 Correct 53 ms 10292 KB Output is correct
13 Correct 51 ms 10320 KB Output is correct
14 Correct 613 ms 100132 KB Output is correct
15 Correct 46 ms 10260 KB Output is correct
16 Correct 530 ms 99864 KB Output is correct
17 Correct 562 ms 100052 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 5 ms 1372 KB Output is correct
3 Correct 5 ms 1256 KB Output is correct
4 Correct 1 ms 344 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 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 6 ms 1292 KB Output is correct
17 Correct 50 ms 10316 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 500 KB Output is correct
24 Correct 0 ms 344 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 193 ms 25544 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 543 ms 100176 KB Output is correct
31 Correct 588 ms 100376 KB Output is correct
32 Correct 573 ms 100212 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 582 ms 99780 KB Output is correct
35 Correct 545 ms 100228 KB Output is correct
36 Correct 604 ms 99848 KB Output is correct
37 Correct 589 ms 100108 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 45 ms 10264 KB Output is correct
40 Correct 49 ms 10320 KB Output is correct
41 Correct 45 ms 10348 KB Output is correct
42 Correct 57 ms 10512 KB Output is correct
43 Correct 54 ms 10324 KB Output is correct
44 Correct 43 ms 10208 KB Output is correct
45 Correct 58 ms 10320 KB Output is correct
46 Correct 49 ms 10236 KB Output is correct
47 Correct 44 ms 10324 KB Output is correct
48 Correct 52 ms 10472 KB Output is correct
49 Correct 64 ms 10320 KB Output is correct
50 Correct 51 ms 10316 KB Output is correct
51 Correct 526 ms 100324 KB Output is correct
52 Correct 588 ms 100212 KB Output is correct
53 Correct 616 ms 99944 KB Output is correct
54 Correct 58 ms 10356 KB Output is correct
55 Correct 63 ms 10428 KB Output is correct
56 Correct 87 ms 12852 KB Output is correct
57 Correct 1 ms 452 KB Output is correct
58 Correct 49 ms 10308 KB Output is correct
59 Correct 50 ms 10348 KB Output is correct
60 Correct 603 ms 100000 KB Output is correct
61 Correct 61 ms 10356 KB Output is correct
62 Correct 52 ms 10408 KB Output is correct
63 Correct 54 ms 10244 KB Output is correct
64 Correct 49 ms 10348 KB Output is correct
65 Correct 56 ms 10320 KB Output is correct
66 Correct 46 ms 10260 KB Output is correct
67 Correct 49 ms 10384 KB Output is correct
68 Correct 53 ms 10292 KB Output is correct
69 Correct 51 ms 10320 KB Output is correct
70 Correct 613 ms 100132 KB Output is correct
71 Correct 46 ms 10260 KB Output is correct
72 Correct 530 ms 99864 KB Output is correct
73 Correct 562 ms 100052 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 0 ms 344 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 1 ms 348 KB Output is correct
78 Correct 1 ms 348 KB Output is correct
79 Correct 7 ms 1372 KB Output is correct
80 Correct 583 ms 99920 KB Output is correct
81 Correct 580 ms 100188 KB Output is correct
82 Correct 584 ms 100064 KB Output is correct
83 Correct 611 ms 100000 KB Output is correct
84 Correct 655 ms 100176 KB Output is correct
85 Correct 571 ms 99892 KB Output is correct
86 Correct 82 ms 12984 KB Output is correct
87 Correct 1 ms 348 KB Output is correct