Submission #1044891

# Submission time Handle Problem Language Result Execution time Memory
1044891 2024-08-05T14:20:53 Z vjudge1 Strange Device (APIO19_strange_device) C++17
5 / 100
960 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(mid<x) {
			if(node->right == nullptr){
				node->right = new Node(node->lazy ? (r-mid):0, node->lazy);
			}
			update(node->right, mid+1, r, x, y);
		}
		else if(mid>=y) {
			if(node->left == nullptr){
				node->left = new Node(node->lazy ? (mid-l+1):0, node->lazy);
			}
			update(node->left, l, mid, x, y);
		}
		else{
			if(node->left == nullptr){
				node->left = new Node(node->lazy ? (mid-l+1):0, node->lazy);
			}
			if(node->right == nullptr){
				node->right = new Node(node->lazy ? (r-mid):0, node->lazy);
			}
			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;
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 20 ms 7152 KB Output is correct
3 Correct 23 ms 8796 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 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 2 ms 1884 KB Output is correct
3 Correct 2 ms 1884 KB Output is correct
4 Correct 4 ms 1884 KB Output is correct
5 Correct 678 ms 16088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 960 ms 156992 KB Output is correct
3 Runtime error 756 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 Correct 960 ms 156992 KB Output is correct
3 Runtime error 756 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 Correct 960 ms 156992 KB Output is correct
3 Runtime error 756 ms 524288 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 213 ms 123812 KB Output is correct
3 Correct 425 ms 294364 KB Output is correct
4 Runtime error 601 ms 524288 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 20 ms 7152 KB Output is correct
3 Correct 23 ms 8796 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -