Submission #1059821

# Submission time Handle Problem Language Result Execution time Memory
1059821 2024-08-15T08:30:33 Z dpsaveslives Strange Device (APIO19_strange_device) C++17
35 / 100
467 ms 51924 KB
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
using namespace std;
const int MAXN = 4e6+10;
ll vals[MAXN];
pair<ll,ll> ranges[MAXN];
ll pref[MAXN];
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int N; ll A,B; cin >> N >> A >> B;
    ll C = A/gcd(A,B+1)*B;
    int cnt = 0;
    for(int i = 0;i<N;++i){
        ll l,r; cin >> l >> r;
        if(r-l+1 >= C){
            cout << C << "\n";
            return 0;
        }
        l %= C; r %= C;
        if(l <= r){
            ranges[++cnt] = make_pair(l,r);
        }
        else{
            ranges[++cnt] = make_pair(0ll,r);
            ranges[++cnt] = make_pair(l,C-1);
        }
    }
    int m = 0;
    for(int i = 1;i<=cnt;++i){
        vals[++m] = ranges[i].f;
        vals[++m] = ranges[i].s+1;
    }
    sort(vals+1,vals+m+1);
    for(int i = 1;i<=cnt;++i){
        int ind = lower_bound(vals+1,vals+m+1,ranges[i].f)-vals;
        int ind2 = lower_bound(vals+1,vals+m+1,ranges[i].s+1)-vals;
        ++pref[ind]; --pref[ind2];
    }
    ll ans = 0ll;
    for(int i = 1;i<=m;++i){
        pref[i] += pref[i-1];
        if(pref[i]){
            ans += vals[i+1]-vals[i];
        }
    }
    cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 ms 4564 KB Output is correct
3 Correct 4 ms 4572 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 4 ms 4700 KB Output is correct
17 Correct 41 ms 8648 KB Output is correct
18 Incorrect 0 ms 348 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 4444 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 1 ms 344 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 206 ms 50880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 379 ms 51916 KB Output is correct
3 Correct 401 ms 51796 KB Output is correct
4 Correct 367 ms 51796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 379 ms 51916 KB Output is correct
3 Correct 401 ms 51796 KB Output is correct
4 Correct 367 ms 51796 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 383 ms 51908 KB Output is correct
7 Correct 372 ms 50772 KB Output is correct
8 Correct 377 ms 51912 KB Output is correct
9 Correct 467 ms 51792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 379 ms 51916 KB Output is correct
3 Correct 401 ms 51796 KB Output is correct
4 Correct 367 ms 51796 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 35 ms 8664 KB Output is correct
7 Correct 38 ms 8784 KB Output is correct
8 Correct 33 ms 8660 KB Output is correct
9 Correct 36 ms 8644 KB Output is correct
10 Correct 34 ms 8656 KB Output is correct
11 Correct 37 ms 8788 KB Output is correct
12 Correct 42 ms 8664 KB Output is correct
13 Correct 41 ms 8664 KB Output is correct
14 Correct 34 ms 8792 KB Output is correct
15 Correct 42 ms 8656 KB Output is correct
16 Correct 43 ms 8788 KB Output is correct
17 Correct 36 ms 8644 KB Output is correct
18 Correct 387 ms 50888 KB Output is correct
19 Correct 355 ms 51924 KB Output is correct
20 Correct 446 ms 51796 KB Output is correct
21 Correct 43 ms 8788 KB Output is correct
22 Correct 33 ms 8796 KB Output is correct
23 Correct 83 ms 20932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 41 ms 8644 KB Output is correct
3 Correct 45 ms 8648 KB Output is correct
4 Correct 435 ms 51796 KB Output is correct
5 Correct 41 ms 8784 KB Output is correct
6 Correct 40 ms 8788 KB Output is correct
7 Correct 45 ms 8652 KB Output is correct
8 Correct 42 ms 8784 KB Output is correct
9 Correct 40 ms 8788 KB Output is correct
10 Correct 42 ms 8656 KB Output is correct
11 Correct 43 ms 8784 KB Output is correct
12 Correct 38 ms 8784 KB Output is correct
13 Correct 44 ms 8788 KB Output is correct
14 Correct 421 ms 51796 KB Output is correct
15 Correct 43 ms 8784 KB Output is correct
16 Correct 355 ms 51792 KB Output is correct
17 Correct 372 ms 51920 KB Output is correct
18 Incorrect 0 ms 348 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 ms 4564 KB Output is correct
3 Correct 4 ms 4572 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 0 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 4 ms 4700 KB Output is correct
17 Correct 41 ms 8648 KB Output is correct
18 Incorrect 0 ms 348 KB Output isn't correct
19 Halted 0 ms 0 KB -