Submission #335115

# Submission time Handle Problem Language Result Execution time Memory
335115 2020-12-11T07:38:10 Z CSQ31 Strange Device (APIO19_strange_device) C++14
65 / 100
1524 ms 17172 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 C = a/gcd(a,b+1) > INF/b?INF+1:(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 16 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 384 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 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 0 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 157 ms 2624 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Incorrect 0 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 1062 ms 16968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1465 ms 16844 KB Output is correct
3 Correct 1452 ms 16840 KB Output is correct
4 Correct 1433 ms 17172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1465 ms 16844 KB Output is correct
3 Correct 1452 ms 16840 KB Output is correct
4 Correct 1433 ms 17172 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1452 ms 17004 KB Output is correct
7 Correct 1474 ms 17128 KB Output is correct
8 Correct 1450 ms 17140 KB Output is correct
9 Correct 1496 ms 16968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1465 ms 16844 KB Output is correct
3 Correct 1452 ms 16840 KB Output is correct
4 Correct 1433 ms 17172 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 145 ms 2528 KB Output is correct
7 Correct 148 ms 2528 KB Output is correct
8 Correct 144 ms 2528 KB Output is correct
9 Correct 144 ms 2528 KB Output is correct
10 Correct 147 ms 2528 KB Output is correct
11 Correct 145 ms 2528 KB Output is correct
12 Correct 143 ms 2528 KB Output is correct
13 Correct 146 ms 2472 KB Output is correct
14 Correct 144 ms 2528 KB Output is correct
15 Correct 148 ms 2556 KB Output is correct
16 Correct 146 ms 2528 KB Output is correct
17 Correct 147 ms 2528 KB Output is correct
18 Correct 1457 ms 16840 KB Output is correct
19 Correct 1438 ms 16880 KB Output is correct
20 Correct 1503 ms 17008 KB Output is correct
21 Correct 149 ms 2528 KB Output is correct
22 Correct 143 ms 2528 KB Output is correct
23 Correct 477 ms 8700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 148 ms 2528 KB Output is correct
3 Correct 149 ms 2528 KB Output is correct
4 Correct 1524 ms 16840 KB Output is correct
5 Correct 150 ms 2528 KB Output is correct
6 Correct 145 ms 2528 KB Output is correct
7 Correct 149 ms 2528 KB Output is correct
8 Correct 149 ms 2528 KB Output is correct
9 Correct 147 ms 2584 KB Output is correct
10 Correct 147 ms 2528 KB Output is correct
11 Correct 147 ms 2528 KB Output is correct
12 Correct 143 ms 2556 KB Output is correct
13 Correct 146 ms 2528 KB Output is correct
14 Correct 1496 ms 17008 KB Output is correct
15 Correct 148 ms 2568 KB Output is correct
16 Correct 1454 ms 16968 KB Output is correct
17 Correct 1444 ms 16968 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 16 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 384 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 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 512 KB Output is correct
14 Correct 0 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 157 ms 2624 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Incorrect 0 ms 364 KB Output isn't correct
21 Halted 0 ms 0 KB -