답안 #1044852

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1044852 2024-08-05T14:11:12 Z vjudge1 이상한 기계 (APIO19_strange_device) C++17
5 / 100
957 ms 524288 KB
#include <bits/stdc++.h>
using std::cin, std::cout, std::vector, std::set, std::endl, std::string, std::map,std::pair;

#ifdef LOCAL
#define file freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#else
#define file ;;
#endif

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

template <typename T>
using Tree = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#include <random>

#define int long long

class psegt{
public:
	class Node{
	public:
		long long val = 0;
		bool lazy = 0;
		Node* left = nullptr;
		Node* right = nullptr;
		Node(){}
		Node(long long val, int lazy): val(val),lazy(lazy){}
		long long get(){
			if(left!=nullptr && right!=nullptr) return val = right->val+left->val;
			if(left!=nullptr) return val = left->val;
			if(right!=nullptr) return val = right->val;
			return val;
		}
	};

	int len;

	psegt(int len): len(len){}

	Node root;

	void update(Node* node, int l, int r, int x, int y){
		if(node->val == r-l+1) return;
		if(l>=x && r<=y){
			node->val = r-l+1;
			node->lazy = 1;
		}
		int mid = (l+r)/2;
		if(node->left == nullptr){
			node->left = new Node(node->lazy ? (mid-l+1):0, node->lazy);
			node->right = new Node(node->lazy ? (r-mid):0, node->lazy);
			node->lazy = 0;
		}
		if(mid<x) update(node->right, mid+1, r, x, y);
		else if(mid>=y) update(node->left, l, mid, x, y);
		else{
			update(node->left, l, mid, x, y);
			update(node->right, mid+1, r, x, y);
		}
		node->get();
	}


	void update(int l, int r){
		update(&root, 0, len, l, r);
	}



};

signed main(){
	file;
	long long n,A,B;
	cin >> n >> A >> B;
	vector<long long> l(n),r(n);
	set<pair<long long,long long>> s;
	long long k = B;
	if(B%A!=A-1){
		if(A>std::numeric_limits<long long>::max()/k){
			int ans = n;
			for(int i=0;i<n;i++){
				cin >> l[i] >> r[i];
				ans += r[i]-l[i];
			}
			cout << ans << endl;
			return 0;
		}
		k*=A;
	}
	psegt pst(k-1);
	for(int i=0;i<n;i++){
		cin >> l[i] >> r[i];
		l[i]%=k;
		r[i]%=k;
		if(r[i]<l[i]){
			pst.update(l[i],k-1);
			pst.update(0,r[i]);
		}
		else
			pst.update(l[i],r[i]);
	}
	cout << pst.root.val << endl;
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 13 ms 7744 KB Output is correct
3 Correct 33 ms 9340 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 2140 KB Output is correct
3 Correct 2 ms 2140 KB Output is correct
4 Correct 2 ms 1884 KB Output is correct
5 Correct 572 ms 16084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 957 ms 203940 KB Output is correct
3 Runtime error 520 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 957 ms 203940 KB Output is correct
3 Runtime error 520 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 957 ms 203940 KB Output is correct
3 Runtime error 520 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 187 ms 126204 KB Output is correct
3 Correct 314 ms 296724 KB Output is correct
4 Runtime error 522 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 13 ms 7744 KB Output is correct
3 Correct 33 ms 9340 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -