Submission #977025

# Submission time Handle Problem Language Result Execution time Memory
977025 2024-05-07T10:32:34 Z dubabuba Strange Device (APIO19_strange_device) C++14
0 / 100
1081 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;
		// cout << tl << ' ' << tr << ": " << l << ' ' << r << endl;
		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;
	cin >> n >> a >> b;
	int t = a / gcd(a, b + 1) * 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;
      |          ~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 17 ms 5468 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 1 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 3 ms 1884 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1081 ms 125756 KB Output is correct
3 Runtime error 773 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1081 ms 125756 KB Output is correct
3 Runtime error 773 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1081 ms 125756 KB Output is correct
3 Runtime error 773 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 168 ms 84884 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 17 ms 5468 KB Output isn't correct
3 Halted 0 ms 0 KB -