Submission #1044627

# Submission time Handle Problem Language Result Execution time Memory
1044627 2024-08-05T11:49:31 Z Onur_Ilgaz Strange Device (APIO19_strange_device) C++17
0 / 100
369 ms 66292 KB
#include <bits/stdc++.h>
#define fast cin.tie(0)->sync_with_stdio(0);
#define int long long
#define inf ((int)1e18)
using namespace std;
const int C = inf;

struct segtree {
	int n;
	struct node {
		int sum, l, r;
		bool set;
		node(): sum(0), l(0), r(0), set(false) {}
	};
	vector <node> t;
	int newnode() {
		t.push_back(node());
		return t.size() - 1;
	}
	void init(int size) {
		n = size;
		newnode();
	}
	void set(int l, int r) {
		return update(0, 0, n - 1, l, r);
	}
	void update(int v, int l, int r, int ul, int ur) {
		if(l >= ul and r <= ur) {
			t[v].sum = (r - l + 1);
			t[v].set = 1;
			return;
		}
		if(t[v].set) return;
		if(!t[v].l) {
			t[v].l = newnode();
			t[v].r = newnode();
		}
		int m = (l + r) / 2;
		if(ul <= m) update(t[v].l, l, m, ul, ur);
		if(ur > m) update(t[v].r, m + 1, r, ul, ur);
		t[v].sum = t[t[v].l].sum + t[t[v].r].sum;
	}
}t;

int32_t main(){
	fast
	int n, a, b;
	cin >> n >> a >> b;
	int tekrar = gcd(a, b + 1);
	__int128__ mult = a * (b + 1);
	if(mult / tekrar > inf) {
		int sum = 0;
		for(int i = 0; i < n; i++) {
			int l, r;
			cin >> l >> r;
			sum += r - l + 1;
		}
		cout << sum << "\n";
		return 0;
	}
	tekrar = mult / tekrar;
	t.init(tekrar);
	for(int i = 0; i < n; i++) {
		int l, r;
		cin >> l >> r;
		if(r - l + 1 >= tekrar) {
			cout << tekrar << "\n";
			return 0;
		}
		int ll = l % tekrar, rr = r % tekrar;
		if(ll <= rr) {
			t.set(ll, rr);
		}
		else {
			t.set(0, rr);
			t.set(ll, tekrar - 1);
		}
	}
	cout << t.t[0].sum;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 6 ms 5332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 1500 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 369 ms 66292 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 369 ms 66292 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 369 ms 66292 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 69 ms 66288 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 6 ms 5332 KB Output isn't correct
3 Halted 0 ms 0 KB -