답안 #1044655

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1044655 2024-08-05T12:04:29 Z vjudge1 이상한 기계 (APIO19_strange_device) C++17
5 / 100
363 ms 524288 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 * 2;

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;
	__int128__ g = gcd(a, b + 1);
	__int128__ mult = a * (b + 1);
	if(mult / g > C) {
		int sum = 0;
		for(int i = 0; i < n; i++) {
			int l, r;
			cin >> l >> r;
			sum += r - l + 1;
		}
		cout << sum;
		return 0;
	}
	int tekrar = mult / g / (b + 1) * b;
	t.init(tekrar);
	for(int i = 0; i < n; i++) {
		int l, r;
		cin >> l >> r;
		if(r - l + 1 >= tekrar) {
			cout << tekrar;
			return 0;
		}
		int ll = l % tekrar, rr = r % tekrar;
		if(ll <= rr) {
			t.set(ll, rr);
			// cout << ll << " " << rr << "\n";
		}
		else {
			// cout << 0 << " " << rr << "\n";
			t.set(0, rr);
			// cout << ll << " " << tekrar - 1 << "\n\n";
			t.set(ll, tekrar - 1);
		}
	}
	cout << t.t[0].sum;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 6 ms 5332 KB Output is correct
3 Correct 8 ms 6096 KB Output is correct
4 Correct 0 ms 348 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 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 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 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 9 ms 6100 KB Output is correct
17 Correct 37 ms 9132 KB Output is correct
18 Incorrect 1 ms 348 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 1496 KB Output is correct
3 Correct 1 ms 1500 KB Output is correct
4 Correct 1 ms 1500 KB Output is correct
5 Correct 355 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 363 ms 72780 KB Output is correct
3 Runtime error 350 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 363 ms 72780 KB Output is correct
3 Runtime error 350 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 363 ms 72780 KB Output is correct
3 Runtime error 350 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 73 ms 67788 KB Output is correct
3 Correct 109 ms 132400 KB Output is correct
4 Runtime error 332 ms 524288 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 6 ms 5332 KB Output is correct
3 Correct 8 ms 6096 KB Output is correct
4 Correct 0 ms 348 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 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 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 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 9 ms 6100 KB Output is correct
17 Correct 37 ms 9132 KB Output is correct
18 Incorrect 1 ms 348 KB Output isn't correct
19 Halted 0 ms 0 KB -