제출 #1174527

#제출 시각아이디문제언어결과실행 시간메모리
1174527tkm_algorithms이상한 기계 (APIO19_strange_device)C++20
0 / 100
5096 ms589824 KiB
/**
*    In the name of Allah
*    We are nothing and you're everything
*    author: najmuddin
**/
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
#define int ll
//const char nl = '\n';
const int N = 1e7;

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n, a, b;
	cin >> n >> a >> b;
	
	if (b == 1) {
		set<pair<int, int>> st, st2;
		for (int i = 0; i < n; ++i) {
			int l, r; cin >> l >> r;
			if (sz(st) == 0)st.insert({l, r}), st2.insert({r, l});
			else {
				auto it = st.lower_bound({l, 0});
				int nl = l, nr = r;
				while (it != st.end() && it->first <= r) {
					nl = min(nl, it->first);
					nr = max(nr, it->second);
					st2.erase({it->second, it->first});
					st.erase(it);
					it = st.lower_bound({l, 0});
				}
				
				st.insert({nl, nr});
				st2.insert({nr, nl});
				
				nl = l, nr = r;
				it = st2.lower_bound({l, 0});
				while (it != st2.end() && it->first >= l && it->first <= r) {
					nl = min(nl, it->second);
					nr = max(nr, it->first);
					st.erase({nl, nr});
					st2.erase(it);
					it = st2.lower_bound({l, 0});
				}
				st2.insert({nr, nl});
				st.insert({nl, nr});
			}
		}
		int ans = 0;
		
		for (auto i: st) {
			//cout << i.first << " " << i.second << endl;
			ans += i.second-i.first+1;
		}	
		cout << ans;
		return 0;
	}
	
	set<pair<int, int>> st;
	for (int i = 0; i < n; ++i) {
		int l, r; cin >> l >> r;
		
		for (int j = l; j <= r; ++j)st.insert({(j+j/b)%a, j%b});
	}
	cout << sz(st);
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...