답안 #1059816

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1059816 2024-08-15T08:26:30 Z dpsaveslives 이상한 기계 (APIO19_strange_device) C++17
35 / 100
472 ms 51920 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];
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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 ms 4568 KB Output is correct
3 Correct 4 ms 4700 KB Output is correct
4 Correct 0 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 0 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 0 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 4 ms 4564 KB Output is correct
17 Correct 43 ms 8788 KB Output is correct
18 Incorrect 0 ms 344 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 4440 KB Output is correct
5 Correct 202 ms 50896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 374 ms 51904 KB Output is correct
3 Correct 412 ms 51920 KB Output is correct
4 Correct 373 ms 51912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 374 ms 51904 KB Output is correct
3 Correct 412 ms 51920 KB Output is correct
4 Correct 373 ms 51912 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 401 ms 51920 KB Output is correct
7 Correct 378 ms 51912 KB Output is correct
8 Correct 405 ms 51796 KB Output is correct
9 Correct 472 ms 51024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 374 ms 51904 KB Output is correct
3 Correct 412 ms 51920 KB Output is correct
4 Correct 373 ms 51912 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 59 ms 8660 KB Output is correct
7 Correct 39 ms 8792 KB Output is correct
8 Correct 35 ms 8788 KB Output is correct
9 Correct 38 ms 8792 KB Output is correct
10 Correct 34 ms 8796 KB Output is correct
11 Correct 41 ms 8788 KB Output is correct
12 Correct 65 ms 8788 KB Output is correct
13 Correct 41 ms 8784 KB Output is correct
14 Correct 35 ms 8788 KB Output is correct
15 Correct 76 ms 8788 KB Output is correct
16 Correct 43 ms 8644 KB Output is correct
17 Correct 39 ms 8788 KB Output is correct
18 Correct 412 ms 51908 KB Output is correct
19 Correct 384 ms 51796 KB Output is correct
20 Correct 448 ms 51908 KB Output is correct
21 Correct 46 ms 8652 KB Output is correct
22 Correct 36 ms 8784 KB Output is correct
23 Correct 90 ms 20940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 42 ms 8648 KB Output is correct
3 Correct 42 ms 8784 KB Output is correct
4 Correct 454 ms 51900 KB Output is correct
5 Correct 45 ms 8832 KB Output is correct
6 Correct 43 ms 8648 KB Output is correct
7 Correct 41 ms 8788 KB Output is correct
8 Correct 42 ms 8788 KB Output is correct
9 Correct 42 ms 8796 KB Output is correct
10 Correct 74 ms 8788 KB Output is correct
11 Correct 42 ms 8828 KB Output is correct
12 Correct 46 ms 8636 KB Output is correct
13 Correct 44 ms 8644 KB Output is correct
14 Correct 437 ms 51912 KB Output is correct
15 Correct 60 ms 8644 KB Output is correct
16 Correct 393 ms 51908 KB Output is correct
17 Correct 408 ms 51912 KB Output is correct
18 Incorrect 0 ms 348 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 ms 4568 KB Output is correct
3 Correct 4 ms 4700 KB Output is correct
4 Correct 0 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 0 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 0 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 4 ms 4564 KB Output is correct
17 Correct 43 ms 8788 KB Output is correct
18 Incorrect 0 ms 344 KB Output isn't correct
19 Halted 0 ms 0 KB -