답안 #977070

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
977070 2024-05-07T11:03:06 Z dubabuba 이상한 기계 (APIO19_strange_device) C++14
5 / 100
1068 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
typedef pair<int, int> pii;
#define ff first
#define ss second
#define MP make_pair
 
int gcd(int a, int b) {
	if(a == 0) return b;
	if(b == 0) return a;
	return gcd(b % a, a);
}
 
struct tree {
	bool lazy;
	int tl, tr;
	tree *lc, *rc;
	int sum;
 
	tree(int l, int r) {
		tl = l, tr = r;
		lazy = sum = 0;
		lc = rc = NULL;
	}
 
	void birth() {
		if(tl == tr) return;
		if(lc != NULL) return;
		lc = new tree(tl, (tl + tr) / 2);
		rc = new tree((tl + tr) / 2 + 1, tr);
	}
 
	void upt(int l, int r) {
		if(lazy) return;
		if(tl == l && r == tr) {
			sum = r - l + 1;
			lazy = 1;
			return;
		}
 
		birth();
 
		int tm = (tl + tr) / 2;
		if(r <= tm) lc->upt(l, r);
		else if(tm < l) rc->upt(l, r);
		else {
			lc->upt(l, tm);
			rc->upt(tm + 1, r);
		}
 
		sum = lc->sum + rc->sum;
		// if(lc->lazy && rc->lazy)
		// 	lazy = 1;
	}
};
 
signed main() {
	int a, b, n, t;
	cin >> n >> a >> b;
	int d = gcd(a, b + 1);

	double sda = 1.0  * a / d * b;
	if(sda <= 1e18) t = a / d * b;
	else t = a / d * b;

	tree *root = new tree(0, t - 1);
 
	// cout << "sda = " << t << endl;
 
	int l, r; bool gay = false;
	for(int i = 0; i < n; i++) {
		cin >> l >> r;
		if(r - l + 1 >= t) {
			gay = 1;
			continue;
		}
 
		l %= t;
		r %= t;
 
		if(l <= r) root->upt(l, r);
		else {
			root->upt(l, t - 1);
			root->upt(0, r);
		}
	}
 
	cout << ((gay) ? t : root->sum) << endl;
	return 0;
}

Compilation message

strange_device.cpp: In constructor 'tree::tree(long long int, long long int)':
strange_device.cpp:24:14: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   24 |   lazy = sum = 0;
      |          ~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 14 ms 5360 KB Output is correct
3 Correct 15 ms 6604 KB Output is correct
4 Correct 1 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 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 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 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 13 ms 4700 KB Output is correct
17 Correct 111 ms 13320 KB Output is correct
18 Incorrect 0 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 344 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 600 KB Output is correct
2 Correct 3 ms 1628 KB Output is correct
3 Correct 2 ms 1628 KB Output is correct
4 Correct 3 ms 1628 KB Output is correct
5 Correct 752 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1068 ms 125888 KB Output is correct
3 Runtime error 790 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1068 ms 125888 KB Output is correct
3 Runtime error 790 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1068 ms 125888 KB Output is correct
3 Runtime error 790 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 170 ms 83536 KB Output is correct
3 Correct 253 ms 197460 KB Output is correct
4 Runtime error 638 ms 524288 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 14 ms 5360 KB Output is correct
3 Correct 15 ms 6604 KB Output is correct
4 Correct 1 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 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 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 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 13 ms 4700 KB Output is correct
17 Correct 111 ms 13320 KB Output is correct
18 Incorrect 0 ms 348 KB Output isn't correct
19 Halted 0 ms 0 KB -