Submission #641081

# Submission time Handle Problem Language Result Execution time Memory
641081 2022-09-16T00:47:23 Z ymm Strange Device (APIO19_strange_device) C++17
10 / 100
5000 ms 524288 KB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

set<pll> s;
set<ll> t;

void add(ll l, ll r)
{
	Loop (i,l,r)
		t.insert(i);
	return;
	auto it = s.lower_bound(pll{l, -1});
	if (it != s.begin()) {
		--it;
		if (it->second >= l) {
			l = it->first;
			s.erase(it++);
		} else {
			++it;
		}
	}
	while (it != s.end() && r >= it->first) {
		r = max(r, it->second);
		s.erase(it++);
	}
	s.insert({l, r});
}

int main()
{
	ll n, A, B;
	cin >> n >> A >> B;
	__int128 p = (__int128)A * B / __gcd(A, B+1);
	if (p < LONG_LONG_MAX)
		p = p * B / __gcd((ll)p, B);
	Loop (i,0,n) {
		ll l, r;
		cin >> l >> r;
		if (r - l + 1 >= p) {
			l = 0;
			r = p;
		} else {
			l %= p;
			r %= p;
			++r;
		}
		if (l < r) {
			add(l, r);
		} else {
			add(l, p);
			add(0, r);
		}
	}
	ll ans = 0;
	for (auto [x, y] : s)
		ans += y - x;
	ans = t.size();
	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 41 ms 9252 KB Output is correct
3 Correct 62 ms 13768 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 0 ms 292 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 30 ms 5236 KB Output is correct
16 Correct 30 ms 5452 KB Output is correct
17 Correct 147 ms 8656 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 4140 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 104 ms 24180 KB Output is correct
3 Correct 87 ms 24172 KB Output is correct
4 Correct 82 ms 23016 KB Output is correct
5 Execution timed out 5055 ms 46868 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 296 KB Output is correct
2 Correct 1403 ms 47332 KB Output is correct
3 Runtime error 2112 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 296 KB Output is correct
2 Correct 1403 ms 47332 KB Output is correct
3 Runtime error 2112 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 296 KB Output is correct
2 Correct 1403 ms 47332 KB Output is correct
3 Runtime error 2112 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 2122 ms 524288 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 41 ms 9252 KB Output is correct
3 Correct 62 ms 13768 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 0 ms 292 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 30 ms 5236 KB Output is correct
16 Correct 30 ms 5452 KB Output is correct
17 Correct 147 ms 8656 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Runtime error 4140 ms 524288 KB Execution killed with signal 9
21 Halted 0 ms 0 KB -