Submission #372475

# Submission time Handle Problem Language Result Execution time Memory
372475 2021-02-28T09:48:21 Z peijar Strange Device (APIO19_strange_device) C++17
65 / 100
656 ms 34972 KB
#include <bits/stdc++.h>
#define SZ(v) ((int)(v).size())
using namespace std;

using ll = long long;

template<typename... Args>
void read(Args&... args)
{
	((cin >> args), ...);
}
template<typename T>
void read(vector<T> &vec)
{
	for (auto &v : vec) read(v);
}

void write() {}
template<typename H, typename... T>
void write(const H &h, const T&... t)
{
	cout << h;
	if (sizeof...(t)) {cout << ' '; write(t...);}
}

template<typename T>
void write(const vector<T> &vec)
{
	if (SZ(vec) == 0) return;
	write(vec[0]);
	for (int i(1); i < SZ(vec); ++i)
	{cout << ' '; write(vec[i]);}
}

template<typename... Args>
void writeln(Args... args)
{
	write(args...); cout << '\n';
}

void show(__int128 x)
{
	if (x >= 10)
		show(x/10);
	cout << int(x%10);
}

int main(void)
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n;
	ll _A, _B;
	using T = __int128;
	read(n, _A, _B);
	T A(_A), B(_B);
	__int128 mod = (A  * B) / gcd(_A, _B+1);

	vector<pair<T, T>> intervals;
	for (int i(0); i < n; ++i)
	{
		ll _l, _r;
		read(_l, _r);
		T l(_l), r(_r);
		l %= mod, r %= mod;
		if (l > r)
		{
			intervals.emplace_back(l, mod-1);
			intervals.emplace_back(0, r);
		}
		else
			intervals.emplace_back(l, r);
	}
	sort(intervals.begin(), intervals.end());
	T lst(-1);
	T sol(0);
	for (auto [l, r] : intervals)
	{
		sol += max(T(0), r - max(l, lst+1) + 1);
		lst = max(lst, r);
	}
	show(sol);
	cout << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 6 ms 1392 KB Output is correct
3 Correct 7 ms 1392 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 6 ms 1392 KB Output is correct
17 Correct 57 ms 5348 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 402 ms 33396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 570 ms 34972 KB Output is correct
3 Correct 523 ms 33468 KB Output is correct
4 Correct 525 ms 33408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 570 ms 34972 KB Output is correct
3 Correct 523 ms 33468 KB Output is correct
4 Correct 525 ms 33408 KB Output is correct
5 Correct 1 ms 392 KB Output is correct
6 Correct 520 ms 33444 KB Output is correct
7 Correct 581 ms 33488 KB Output is correct
8 Correct 519 ms 33436 KB Output is correct
9 Correct 632 ms 33636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 570 ms 34972 KB Output is correct
3 Correct 523 ms 33468 KB Output is correct
4 Correct 525 ms 33408 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 60 ms 5392 KB Output is correct
7 Correct 55 ms 5348 KB Output is correct
8 Correct 55 ms 5476 KB Output is correct
9 Correct 53 ms 5424 KB Output is correct
10 Correct 56 ms 5480 KB Output is correct
11 Correct 53 ms 5348 KB Output is correct
12 Correct 55 ms 5408 KB Output is correct
13 Correct 68 ms 5348 KB Output is correct
14 Correct 51 ms 5348 KB Output is correct
15 Correct 59 ms 5492 KB Output is correct
16 Correct 59 ms 5476 KB Output is correct
17 Correct 55 ms 5220 KB Output is correct
18 Correct 513 ms 33428 KB Output is correct
19 Correct 512 ms 33524 KB Output is correct
20 Correct 656 ms 33340 KB Output is correct
21 Correct 61 ms 5220 KB Output is correct
22 Correct 58 ms 5220 KB Output is correct
23 Correct 164 ms 17360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 60 ms 5092 KB Output is correct
3 Correct 57 ms 5220 KB Output is correct
4 Correct 633 ms 33340 KB Output is correct
5 Correct 57 ms 5220 KB Output is correct
6 Correct 56 ms 5220 KB Output is correct
7 Correct 55 ms 5220 KB Output is correct
8 Correct 71 ms 5220 KB Output is correct
9 Correct 54 ms 5220 KB Output is correct
10 Correct 54 ms 5220 KB Output is correct
11 Correct 55 ms 5220 KB Output is correct
12 Correct 49 ms 5220 KB Output is correct
13 Correct 54 ms 5220 KB Output is correct
14 Correct 605 ms 33340 KB Output is correct
15 Correct 62 ms 5220 KB Output is correct
16 Correct 510 ms 33340 KB Output is correct
17 Correct 510 ms 33468 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 6 ms 1392 KB Output is correct
3 Correct 7 ms 1392 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 6 ms 1392 KB Output is correct
17 Correct 57 ms 5348 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Incorrect 1 ms 364 KB Output isn't correct
21 Halted 0 ms 0 KB -