Submission #260168

# Submission time Handle Problem Language Result Execution time Memory
260168 2020-08-09T12:48:59 Z pure_mem Strange Device (APIO19_strange_device) C++14
10 / 100
1008 ms 119544 KB
#include <bits/stdc++.h>

#define ll long long
#define X first
#define Y second
#define MP make_pair
 
using namespace std;
 
const int N = 1e5 + 12;
const ll INF = 1e18;

ll gcd(ll x, ll y){ return (y == 0 ? x: gcd(y, x % y));}

int n;
ll A, B;
multiset<ll> st;
vector< pair< pair<ll, ll>, ll > > g;

int main () {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
 
    cin >> n >> A >> B;
    ll period = gcd(A, B + 1);
    bool exc = 0;
    if(((INF + A - 1) / A + B - 1) / B < period){
    	exc = 1;
    }
    else{
    	period *= A * B;
    }
    ll res = 0;
    for(int i = 1;i <= n;i++){
    	ll l, r;
    	cin >> l >> r;
    	if(exc){
    		res += r - l + 1;
    		continue;
    	}
    	if(l + period - 1 <= r){
    		cout << period;
    		return 0;	
    	}
    	else{
    		l %= period, r %= period;
    		if(l <= r){
    			g.push_back(MP(MP(l, -1), r));
    			g.push_back(MP(MP(r, 1), l));
    		}
    		else{
    			g.push_back(MP(MP(l, -1), period - 1));
    			g.push_back(MP(MP(period - 1, 1), l));

    			g.push_back(MP(MP(0, -1), r));
    			g.push_back(MP(MP(r, 1), 0));
    		}
    	}
    }
    if(exc)
    	return cout << res, 0;
    sort(g.begin(), g.end());
    for(pair< pair<ll, ll>, ll> v: g){
    	if(v.X.Y < 0){
    		res += v.Y - v.X.X + 1;
    		if(!st.empty()){
    			ll z = *st.begin();
    			z *= -1;
    			res -= min(v.Y, z) - v.X.X + 1;
    		}
    		st.insert(-v.Y);
    	}
    	else{
    		st.erase(st.find(-v.X.X));
    	}
    }
    cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 9 ms 1660 KB Output is correct
3 Correct 10 ms 1660 KB Output is correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 895 ms 119544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 808 ms 50220 KB Output is correct
3 Incorrect 727 ms 84660 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 808 ms 50220 KB Output is correct
3 Incorrect 727 ms 84660 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 808 ms 50220 KB Output is correct
3 Incorrect 727 ms 84660 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 86 ms 9316 KB Output is correct
3 Correct 86 ms 9320 KB Output is correct
4 Correct 1008 ms 84596 KB Output is correct
5 Correct 86 ms 9320 KB Output is correct
6 Correct 91 ms 9324 KB Output is correct
7 Correct 83 ms 9316 KB Output is correct
8 Correct 89 ms 9316 KB Output is correct
9 Correct 83 ms 9320 KB Output is correct
10 Correct 97 ms 9328 KB Output is correct
11 Correct 85 ms 9316 KB Output is correct
12 Correct 76 ms 9316 KB Output is correct
13 Correct 88 ms 9320 KB Output is correct
14 Correct 957 ms 84724 KB Output is correct
15 Incorrect 94 ms 9264 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 9 ms 1660 KB Output is correct
3 Correct 10 ms 1660 KB Output is correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -