Submission #283282

# Submission time Handle Problem Language Result Execution time Memory
283282 2020-08-25T13:30:37 Z groeneprof Strange Device (APIO19_strange_device) C++14
0 / 100
1 ms 384 KB
#include <bits/stdc++.h>
#define int long long
#define P(a) do{if(debug) cout<<a<<endl;} while(false)
#define H(a) P(#a<<": "<<a)
#define FR(i,a,b) for(int i = (a); i<(b); i++)
#define F(i,n) FR(i,0,n)

const int debug = 1;

using namespace std;
int n, A, B;
int p;

int ggd(int a, int b){
	if(a<b) swap(a,b);
	while(b!=0){
		a = a%b;
		swap(a,b);
	}
	return a;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>A>>B;
	p = (A/ggd(A,B+1));
	if(((int)sqrt(p))*((int)sqrt(B))>1e9){
		p = 2e18;
	}
	p *= B;
	vector<pair<int,int> > segments;
	F(i,n){
		int l,r;
		cin>>l>>r;
		if(l-r+1>=p){
			cout<<p<<endl;
		}
		l%=p;
		r%=p;
		if(r >= l){
			segments.push_back({l,1});
			segments.push_back({r+1,-1});
		}
		else{
			segments.push_back({0,1});
			segments.push_back({r+1,-1});
			segments.push_back({l,1});
			segments.push_back({p,-1});
		}
	}
	sort(segments.begin(),segments.end());
	int cnt = segments[0].second;
	int ans = 0;
	FR(i,1,segments.size()){
		if(cnt>0){
			ans += segments[i].first-segments[i-1].first;
		}
		cnt += segments[i].second;
	}
	cout<<ans<<endl;
	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:5:37: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define FR(i,a,b) for(int i = (a); i<(b); i++)
      |                                     ^
strange_device.cpp:55:2: note: in expansion of macro 'FR'
   55 |  FR(i,1,segments.size()){
      |  ^~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -