답안 #983012

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
983012 2024-05-15T06:58:32 Z angella 이상한 기계 (APIO19_strange_device) C++17
100 / 100
430 ms 69940 KB
/*
    IN THE NAME OF GOD
*/
#include <bits/stdc++.h>

// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;

#define F                                      first
#define S                                      second
#define Mp                                     make_pair
#define pb                                     push_back
#define pf                                     push_front
#define size(x)                                ((ll)x.size())
#define all(x)                                 (x).begin(),(x).end()
#define kill(x)		                           cout << x << '\n', exit(0);
#define fuck(x)                                cout << "(" << #x << " , " << x << ")" << endl
#define endl                                   '\n'

const int N = 1e6+23, lg = 18;
ll Mod = 1e9+7; //998244353;

inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
    ll ans = 1;
    a=MOD(a, mod);
    while (b) {
        if (b & 1) ans = MOD(ans*a, mod);
        b >>= 1;
        a = MOD(a*a, mod);
    }
    return ans;
}

ll n, a, b, ans, l[N], r[N];
int main () {
	ios_base::sync_with_stdio(false), cin.tie(0);

    cin>>n>>a>>b;
    for(int i=1; i<=n; i++) {
        cin>>l[i]>>r[i]; ans += (r[i]-l[i]+1);
    }
    ll s = a/__gcd(a,b+1);
    if(__lg(s) + __lg(b) >= 60) kill(ans);

    vector<pll> vec;
    for(int i=1; i<=n; i++) {
        if(r[i]-l[i]+1 >= s*b) kill(s*b);
        l[i] = MOD(l[i], s*b);
        r[i] = MOD(r[i], s*b);
        if(r[i] >= l[i]) vec.pb({l[i], r[i]});
        else {
            vec.pb({0, r[i]}); vec.pb({l[i], s*b-1});
        }
    }

    sort(all(vec));
    ans = 0; ll mx = -1;
    for(auto it : vec) {
        if(it.F > mx) {
            ans += (it.S-it.F+1); mx = it.S;
        } else {
            ans += max(0ll, it.S - mx);
            mx = max(mx, it.S);
        }
    }

    cout<<ans<<endl;
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 3 ms 856 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 34 ms 4056 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 223 ms 42384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 327 ms 44764 KB Output is correct
3 Correct 316 ms 69644 KB Output is correct
4 Correct 355 ms 69572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 327 ms 44764 KB Output is correct
3 Correct 316 ms 69644 KB Output is correct
4 Correct 355 ms 69572 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 354 ms 69940 KB Output is correct
7 Correct 330 ms 69616 KB Output is correct
8 Correct 342 ms 69764 KB Output is correct
9 Correct 360 ms 69556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 327 ms 44764 KB Output is correct
3 Correct 316 ms 69644 KB Output is correct
4 Correct 355 ms 69572 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 31 ms 7800 KB Output is correct
7 Correct 35 ms 9332 KB Output is correct
8 Correct 30 ms 9244 KB Output is correct
9 Correct 36 ms 7884 KB Output is correct
10 Correct 35 ms 7692 KB Output is correct
11 Correct 33 ms 7960 KB Output is correct
12 Correct 31 ms 7888 KB Output is correct
13 Correct 33 ms 7896 KB Output is correct
14 Correct 42 ms 7888 KB Output is correct
15 Correct 35 ms 7888 KB Output is correct
16 Correct 35 ms 7924 KB Output is correct
17 Correct 34 ms 7872 KB Output is correct
18 Correct 328 ms 69600 KB Output is correct
19 Correct 345 ms 69856 KB Output is correct
20 Correct 354 ms 69568 KB Output is correct
21 Correct 38 ms 7984 KB Output is correct
22 Correct 29 ms 8116 KB Output is correct
23 Correct 95 ms 26588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 33 ms 4056 KB Output is correct
3 Correct 41 ms 4060 KB Output is correct
4 Correct 397 ms 58336 KB Output is correct
5 Correct 34 ms 9424 KB Output is correct
6 Correct 35 ms 7888 KB Output is correct
7 Correct 35 ms 7728 KB Output is correct
8 Correct 41 ms 8180 KB Output is correct
9 Correct 37 ms 7896 KB Output is correct
10 Correct 49 ms 7884 KB Output is correct
11 Correct 36 ms 9180 KB Output is correct
12 Correct 31 ms 7784 KB Output is correct
13 Correct 35 ms 7764 KB Output is correct
14 Correct 387 ms 69564 KB Output is correct
15 Correct 49 ms 7892 KB Output is correct
16 Correct 324 ms 69612 KB Output is correct
17 Correct 345 ms 69668 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 3 ms 856 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 34 ms 4056 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 223 ms 42384 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 327 ms 44764 KB Output is correct
31 Correct 316 ms 69644 KB Output is correct
32 Correct 355 ms 69572 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 354 ms 69940 KB Output is correct
35 Correct 330 ms 69616 KB Output is correct
36 Correct 342 ms 69764 KB Output is correct
37 Correct 360 ms 69556 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 31 ms 7800 KB Output is correct
40 Correct 35 ms 9332 KB Output is correct
41 Correct 30 ms 9244 KB Output is correct
42 Correct 36 ms 7884 KB Output is correct
43 Correct 35 ms 7692 KB Output is correct
44 Correct 33 ms 7960 KB Output is correct
45 Correct 31 ms 7888 KB Output is correct
46 Correct 33 ms 7896 KB Output is correct
47 Correct 42 ms 7888 KB Output is correct
48 Correct 35 ms 7888 KB Output is correct
49 Correct 35 ms 7924 KB Output is correct
50 Correct 34 ms 7872 KB Output is correct
51 Correct 328 ms 69600 KB Output is correct
52 Correct 345 ms 69856 KB Output is correct
53 Correct 354 ms 69568 KB Output is correct
54 Correct 38 ms 7984 KB Output is correct
55 Correct 29 ms 8116 KB Output is correct
56 Correct 95 ms 26588 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 33 ms 4056 KB Output is correct
59 Correct 41 ms 4060 KB Output is correct
60 Correct 397 ms 58336 KB Output is correct
61 Correct 34 ms 9424 KB Output is correct
62 Correct 35 ms 7888 KB Output is correct
63 Correct 35 ms 7728 KB Output is correct
64 Correct 41 ms 8180 KB Output is correct
65 Correct 37 ms 7896 KB Output is correct
66 Correct 49 ms 7884 KB Output is correct
67 Correct 36 ms 9180 KB Output is correct
68 Correct 31 ms 7784 KB Output is correct
69 Correct 35 ms 7764 KB Output is correct
70 Correct 387 ms 69564 KB Output is correct
71 Correct 49 ms 7892 KB Output is correct
72 Correct 324 ms 69612 KB Output is correct
73 Correct 345 ms 69668 KB Output is correct
74 Correct 0 ms 344 KB Output is correct
75 Correct 1 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 1 ms 348 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 3 ms 1372 KB Output is correct
80 Correct 379 ms 69696 KB Output is correct
81 Correct 392 ms 69596 KB Output is correct
82 Correct 383 ms 69688 KB Output is correct
83 Correct 370 ms 69572 KB Output is correct
84 Correct 430 ms 69752 KB Output is correct
85 Correct 368 ms 69896 KB Output is correct
86 Correct 104 ms 26572 KB Output is correct
87 Correct 1 ms 344 KB Output is correct