Submission #196918

# Submission time Handle Problem Language Result Execution time Memory
196918 2020-01-17T16:24:58 Z tincamatei Strange Device (APIO19_strange_device) C++14
100 / 100
1503 ms 100272 KB
#include <bits/stdc++.h>

using namespace std;

const long long INF = 1LL << 62;

long long gcd(long long a, long long b) {
	long long r;
	while(b > 0) {
		r = a % b;
		a = b;
		b = r;
	}
	return a;
}

set<pair<long long, long long> > ranges;

long long insertRange(long long a, long long b) {
	set<pair<long long, long long> >::iterator it;

	it = ranges.lower_bound(make_pair(a, -INF));

	if(it != ranges.begin()) {
		set<pair<long long, long long> >::iterator it2;
		it2 = it;
		it2--;

		if(it2->second >= a) {
			it--;
			a = it->first;
		}
	}
	
	long long rez = 0LL;
	vector<pair<long long, long long> > toErase;
	while(it != ranges.end() && it->first <= b) {
		toErase.push_back(*it);
		rez = rez - (it->second - it->first + 1);
		b = max(b, it->second);
		it++;
	}

	for(auto it: toErase)
		ranges.erase(it);
	ranges.insert(make_pair(a, b));
	rez = rez + b - a + 1;
	
	return rez;
}

int main() {
	int n;
	long long A, B, loopSize, xSkip, convolutions;

	scanf("%d%lld%lld", &n, &A, &B);
	xSkip = B % A + 1;
	convolutions = A / gcd(A, xSkip);

	if(convolutions <= INF / B)
		loopSize = B * convolutions;
	else
		loopSize = INF;

	long long rez = 0LL;
	for(int i = 0; i < n; ++i) {
		long long l, r;
		scanf("%lld%lld", &l, &r);
		
		if(r - l + 1 >= loopSize)
			rez = rez + insertRange(0, loopSize - 1);
		else {
			l = l % loopSize;
			r = r % loopSize;

			if(r >= l)
				rez = rez + insertRange(l, r);
			else {
				rez = rez + insertRange(0, r) +
				            insertRange(l, loopSize - 1);
			}
		}
	}

	printf("%lld\n", rez);

	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:56:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%lld%lld", &n, &A, &B);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:68:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &l, &r);
   ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 10 ms 888 KB Output is correct
3 Correct 17 ms 1244 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 252 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 9 ms 1400 KB Output is correct
17 Correct 95 ms 10232 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 252 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 537 ms 25080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 1130 ms 62868 KB Output is correct
3 Correct 1079 ms 63116 KB Output is correct
4 Correct 1173 ms 100212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 1130 ms 62868 KB Output is correct
3 Correct 1079 ms 63116 KB Output is correct
4 Correct 1173 ms 100212 KB Output is correct
5 Correct 1 ms 376 KB Output is correct
6 Correct 1063 ms 100032 KB Output is correct
7 Correct 1114 ms 100104 KB Output is correct
8 Correct 1081 ms 100088 KB Output is correct
9 Correct 1222 ms 100112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 1130 ms 62868 KB Output is correct
3 Correct 1079 ms 63116 KB Output is correct
4 Correct 1173 ms 100212 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 84 ms 10204 KB Output is correct
7 Correct 86 ms 10340 KB Output is correct
8 Correct 95 ms 10292 KB Output is correct
9 Correct 101 ms 10228 KB Output is correct
10 Correct 86 ms 10232 KB Output is correct
11 Correct 85 ms 10232 KB Output is correct
12 Correct 90 ms 10232 KB Output is correct
13 Correct 100 ms 10308 KB Output is correct
14 Correct 91 ms 10204 KB Output is correct
15 Correct 167 ms 10360 KB Output is correct
16 Correct 104 ms 10364 KB Output is correct
17 Correct 98 ms 10276 KB Output is correct
18 Correct 1061 ms 100216 KB Output is correct
19 Correct 1101 ms 100272 KB Output is correct
20 Correct 1175 ms 100268 KB Output is correct
21 Correct 91 ms 10360 KB Output is correct
22 Correct 97 ms 10360 KB Output is correct
23 Correct 244 ms 12892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 103 ms 6624 KB Output is correct
3 Correct 106 ms 10360 KB Output is correct
4 Correct 1140 ms 100208 KB Output is correct
5 Correct 104 ms 10268 KB Output is correct
6 Correct 107 ms 10232 KB Output is correct
7 Correct 106 ms 10360 KB Output is correct
8 Correct 105 ms 10360 KB Output is correct
9 Correct 111 ms 10352 KB Output is correct
10 Correct 91 ms 10360 KB Output is correct
11 Correct 96 ms 10440 KB Output is correct
12 Correct 95 ms 10360 KB Output is correct
13 Correct 105 ms 10240 KB Output is correct
14 Correct 1249 ms 100172 KB Output is correct
15 Correct 88 ms 9768 KB Output is correct
16 Correct 1032 ms 100188 KB Output is correct
17 Correct 1039 ms 100216 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 10 ms 888 KB Output is correct
3 Correct 17 ms 1244 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 252 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 9 ms 1400 KB Output is correct
17 Correct 95 ms 10232 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 252 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 537 ms 25080 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 1130 ms 62868 KB Output is correct
31 Correct 1079 ms 63116 KB Output is correct
32 Correct 1173 ms 100212 KB Output is correct
33 Correct 1 ms 376 KB Output is correct
34 Correct 1063 ms 100032 KB Output is correct
35 Correct 1114 ms 100104 KB Output is correct
36 Correct 1081 ms 100088 KB Output is correct
37 Correct 1222 ms 100112 KB Output is correct
38 Correct 2 ms 256 KB Output is correct
39 Correct 84 ms 10204 KB Output is correct
40 Correct 86 ms 10340 KB Output is correct
41 Correct 95 ms 10292 KB Output is correct
42 Correct 101 ms 10228 KB Output is correct
43 Correct 86 ms 10232 KB Output is correct
44 Correct 85 ms 10232 KB Output is correct
45 Correct 90 ms 10232 KB Output is correct
46 Correct 100 ms 10308 KB Output is correct
47 Correct 91 ms 10204 KB Output is correct
48 Correct 167 ms 10360 KB Output is correct
49 Correct 104 ms 10364 KB Output is correct
50 Correct 98 ms 10276 KB Output is correct
51 Correct 1061 ms 100216 KB Output is correct
52 Correct 1101 ms 100272 KB Output is correct
53 Correct 1175 ms 100268 KB Output is correct
54 Correct 91 ms 10360 KB Output is correct
55 Correct 97 ms 10360 KB Output is correct
56 Correct 244 ms 12892 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 103 ms 6624 KB Output is correct
59 Correct 106 ms 10360 KB Output is correct
60 Correct 1140 ms 100208 KB Output is correct
61 Correct 104 ms 10268 KB Output is correct
62 Correct 107 ms 10232 KB Output is correct
63 Correct 106 ms 10360 KB Output is correct
64 Correct 105 ms 10360 KB Output is correct
65 Correct 111 ms 10352 KB Output is correct
66 Correct 91 ms 10360 KB Output is correct
67 Correct 96 ms 10440 KB Output is correct
68 Correct 95 ms 10360 KB Output is correct
69 Correct 105 ms 10240 KB Output is correct
70 Correct 1249 ms 100172 KB Output is correct
71 Correct 88 ms 9768 KB Output is correct
72 Correct 1032 ms 100188 KB Output is correct
73 Correct 1039 ms 100216 KB Output is correct
74 Correct 2 ms 376 KB Output is correct
75 Correct 2 ms 376 KB Output is correct
76 Correct 2 ms 376 KB Output is correct
77 Correct 2 ms 376 KB Output is correct
78 Correct 2 ms 256 KB Output is correct
79 Correct 10 ms 1272 KB Output is correct
80 Correct 1188 ms 99924 KB Output is correct
81 Correct 1154 ms 100196 KB Output is correct
82 Correct 1399 ms 100272 KB Output is correct
83 Correct 1503 ms 100128 KB Output is correct
84 Correct 1451 ms 100080 KB Output is correct
85 Correct 1344 ms 100064 KB Output is correct
86 Correct 235 ms 12920 KB Output is correct
87 Correct 2 ms 376 KB Output is correct