Submission #335112

# Submission time Handle Problem Language Result Execution time Memory
335112 2020-12-11T07:26:32 Z CSQ31 Strange Device (APIO19_strange_device) C++14
65 / 100
1518 ms 17072 KB
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (int)(a.size())
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll A,ll B) {if(!B)return A;return gcd(B,A%B);}
int main()
{
	ll n,a,b;
	cin>>n>>a>>b;
	ll v = INF/b;
	ll C;
	v/=gcd(a,b+1);
	if(a > v)C= INF+1;
	else C = (a/gcd(a,b+1))*b;
   // cout<<C<<'\n';
	vector<PII>s;
	for(int i=0;i<n;i++){
		ll l,r;
		cin>>l>>r;
		l%=C;
		r%=C;
		if(r >= l){
			s.pb({l,r});
		}else{
			s.pb({l,C-1});
			s.pb({0,r});
		}
	}
	sort(all(s));
	ll ans = 0;
	ll lf = 0;
	ll rg = -1;
	for(int i=0;i<sz(s);i++){
		//cout<<s[i].fi<<" "<<s[i].se<<'\n';
		if(s[i].fi > rg){
			ans+=rg-lf+1;
			lf = s[i].fi;
			rg = s[i].se;
			if(i == sz(s)-1)ans+=rg-lf+1;
		}else{
			rg = max(rg,s[i].se);
			if(i == sz(s)-1)ans+=rg-lf+1;
		}
		//cout<<ans<<'\n';
	}
	cout<<ans<<'\n';
	
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 15 ms 748 KB Output is correct
3 Correct 15 ms 748 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 15 ms 748 KB Output is correct
17 Correct 177 ms 2528 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1079 ms 16988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1456 ms 16968 KB Output is correct
3 Correct 1461 ms 16840 KB Output is correct
4 Correct 1439 ms 16840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1456 ms 16968 KB Output is correct
3 Correct 1461 ms 16840 KB Output is correct
4 Correct 1439 ms 16840 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1458 ms 17020 KB Output is correct
7 Correct 1447 ms 17072 KB Output is correct
8 Correct 1468 ms 16840 KB Output is correct
9 Correct 1492 ms 16992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1456 ms 16968 KB Output is correct
3 Correct 1461 ms 16840 KB Output is correct
4 Correct 1439 ms 16840 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 145 ms 2528 KB Output is correct
7 Correct 146 ms 2528 KB Output is correct
8 Correct 145 ms 2528 KB Output is correct
9 Correct 144 ms 2528 KB Output is correct
10 Correct 143 ms 2528 KB Output is correct
11 Correct 147 ms 2528 KB Output is correct
12 Correct 143 ms 2548 KB Output is correct
13 Correct 146 ms 2656 KB Output is correct
14 Correct 144 ms 2528 KB Output is correct
15 Correct 150 ms 2528 KB Output is correct
16 Correct 149 ms 2528 KB Output is correct
17 Correct 146 ms 2528 KB Output is correct
18 Correct 1457 ms 16968 KB Output is correct
19 Correct 1442 ms 16840 KB Output is correct
20 Correct 1501 ms 16964 KB Output is correct
21 Correct 148 ms 2528 KB Output is correct
22 Correct 141 ms 2584 KB Output is correct
23 Correct 482 ms 8660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 151 ms 2528 KB Output is correct
3 Correct 151 ms 2528 KB Output is correct
4 Correct 1518 ms 16968 KB Output is correct
5 Correct 146 ms 2528 KB Output is correct
6 Correct 146 ms 2528 KB Output is correct
7 Correct 146 ms 2528 KB Output is correct
8 Correct 149 ms 2676 KB Output is correct
9 Correct 146 ms 2656 KB Output is correct
10 Correct 147 ms 2440 KB Output is correct
11 Correct 148 ms 2520 KB Output is correct
12 Correct 142 ms 2528 KB Output is correct
13 Correct 150 ms 2528 KB Output is correct
14 Correct 1504 ms 16840 KB Output is correct
15 Correct 150 ms 2528 KB Output is correct
16 Correct 1449 ms 17004 KB Output is correct
17 Correct 1447 ms 17036 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 15 ms 748 KB Output is correct
3 Correct 15 ms 748 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 15 ms 748 KB Output is correct
17 Correct 177 ms 2528 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Incorrect 1 ms 364 KB Output isn't correct
21 Halted 0 ms 0 KB -