Submission #1100588

# Submission time Handle Problem Language Result Execution time Memory
1100588 2024-10-14T09:29:54 Z vjudge1 Strange Device (APIO19_strange_device) C++17
100 / 100
1030 ms 163024 KB
// Bolatulu
#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define kanagattandirilmagandiktarinizdan ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ins insert
#define F first
#define S second
#define fx cout << fixed << setprecision(6);
#define md (tl+tr)/2
#define TL v+v, tl,md
#define TR v+v+1, md+1,tr
#define Tl t[v].l, tl,md
#define Tr t[v].r, md+1,tr
#define yes cout << "Yes\n"
#define no cout << "No\n"
#define all(x) (x).begin(), (x).end()
#define int ull
#define cnk(n,k) mod(mod(f[(n)]*binpow(f[(n)-(k)],M-2))*binpow(f[(k)],M-2))
#define cnkf(n,k) mod(mod(f[(n)]*inv[(n)-(k)])*inv[(k)])

using namespace std;

typedef complex<double> cd;

struct mine{int l;int r;int i;};
struct edge{int u;int v;int w;};
struct tree{int l;int r;int val;};

bool cmp(edge a,edge b) {
    return a.w>b.w;
}

mt19937 RR((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
 
int random(int l, int r){
  return uniform_int_distribution<int>(l, r)(RR);
}

int M=998244353;

int mod1(int a,int b=M) {
    if (a<0)
        a=b+a%b;
    return a % b;
}

int binpow(int a,int n,int m=M) {
    a=mod1(a,m);
    if (!n)
        return 1;
    if (n&1)
        return (a * binpow(a,n-1))%m;
    int x = binpow(a,n>>1);
    return (x*x)%m; 
}

const double pi = acos(-1);
const cd I = sqrt(cd(-1));
const int INF=1e18+7;
const int N=1e6+7;
const int root = 5;
const int root_1 = 4404020;
const int root_pw = 1 << 20;
int mod=7340033;

int n,A,B,l[N],r[N],m;
set <int> s;
map <int,int> add,del;

void addf(int l,int r) {
    s.insert(l);
    add[l]++;
    s.insert(r+1);
    add[r+1]--;
}

void solve() {
    cin >> n >> A >> B;
    db d=A*B/__gcd(A,B+1);
    // cout << d << ' ';
    if (INF>=d)
        m=d;
    else
        m=INF;
    for (int i=1;i<=n;i++) {
        cin >> l[i] >> r[i];
        if (r[i]-l[i]+1>=m) {
            cout << m;
            return;
        }
        int posl=(l[i])%m;
        int posr=(r[i])%m;
        if (posl<=posr)
            addf(posl,posr);
        else {
            addf(posl,m-1);
            addf(0,posr);
        }
    }
    int cnt=0,ans=0,last=0;
    for (auto now : s) {
        if (cnt>0)
            ans+=(now-last);
        cnt+=add[now];
        last=now;
    }
    cout << ans;
}   

signed main() {
    /*
    freopen("sequence.in", "r", stdin);
    freopen("sequence.out", "w", stdout);
    */
    // fx
    kanagattandirilmagandiktarinizdan
    int test = 1, count = 1;
    // cin >> test;
    while (test--) {
        // cout << "Case " << count << ":\n";
        solve();
        if (test) {
            cout << '\n';
            count++;
        }
    }
    return 0;
}

// ctrl + shift + p make stress isis__Good isis__Generator

// g++ -std=c++17 (path) -o run
// .\run
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 7 ms 3696 KB Output is correct
3 Correct 7 ms 3740 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2480 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 6 ms 3628 KB Output is correct
17 Correct 74 ms 17736 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2388 KB Output is correct
4 Correct 1 ms 2388 KB Output is correct
5 Correct 1 ms 2388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2552 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 184 ms 41476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 761 ms 125548 KB Output is correct
3 Correct 825 ms 163024 KB Output is correct
4 Correct 900 ms 162700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 761 ms 125548 KB Output is correct
3 Correct 825 ms 163024 KB Output is correct
4 Correct 900 ms 162700 KB Output is correct
5 Correct 1 ms 2388 KB Output is correct
6 Correct 766 ms 162892 KB Output is correct
7 Correct 816 ms 162780 KB Output is correct
8 Correct 825 ms 162784 KB Output is correct
9 Correct 979 ms 162924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 761 ms 125548 KB Output is correct
3 Correct 825 ms 163024 KB Output is correct
4 Correct 900 ms 162700 KB Output is correct
5 Correct 1 ms 2388 KB Output is correct
6 Correct 64 ms 21276 KB Output is correct
7 Correct 65 ms 21324 KB Output is correct
8 Correct 66 ms 21324 KB Output is correct
9 Correct 72 ms 21396 KB Output is correct
10 Correct 66 ms 21324 KB Output is correct
11 Correct 64 ms 21332 KB Output is correct
12 Correct 73 ms 21388 KB Output is correct
13 Correct 77 ms 21324 KB Output is correct
14 Correct 67 ms 21332 KB Output is correct
15 Correct 85 ms 21320 KB Output is correct
16 Correct 81 ms 21324 KB Output is correct
17 Correct 71 ms 21324 KB Output is correct
18 Correct 783 ms 162724 KB Output is correct
19 Correct 814 ms 162712 KB Output is correct
20 Correct 892 ms 162892 KB Output is correct
21 Correct 60 ms 21324 KB Output is correct
22 Correct 64 ms 21324 KB Output is correct
23 Correct 77 ms 23388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2556 KB Output is correct
2 Correct 85 ms 21320 KB Output is correct
3 Correct 82 ms 21296 KB Output is correct
4 Correct 972 ms 162700 KB Output is correct
5 Correct 80 ms 21324 KB Output is correct
6 Correct 93 ms 21380 KB Output is correct
7 Correct 83 ms 21324 KB Output is correct
8 Correct 83 ms 21416 KB Output is correct
9 Correct 85 ms 21324 KB Output is correct
10 Correct 68 ms 21328 KB Output is correct
11 Correct 69 ms 21580 KB Output is correct
12 Correct 76 ms 21324 KB Output is correct
13 Correct 82 ms 21324 KB Output is correct
14 Correct 961 ms 162680 KB Output is correct
15 Correct 65 ms 21324 KB Output is correct
16 Correct 803 ms 162688 KB Output is correct
17 Correct 763 ms 162804 KB Output is correct
18 Correct 1 ms 2388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 7 ms 3696 KB Output is correct
3 Correct 7 ms 3740 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2480 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 6 ms 3628 KB Output is correct
17 Correct 74 ms 17736 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2388 KB Output is correct
22 Correct 1 ms 2388 KB Output is correct
23 Correct 1 ms 2388 KB Output is correct
24 Correct 1 ms 2552 KB Output is correct
25 Correct 2 ms 2640 KB Output is correct
26 Correct 2 ms 2640 KB Output is correct
27 Correct 2 ms 2640 KB Output is correct
28 Correct 184 ms 41476 KB Output is correct
29 Correct 1 ms 2384 KB Output is correct
30 Correct 761 ms 125548 KB Output is correct
31 Correct 825 ms 163024 KB Output is correct
32 Correct 900 ms 162700 KB Output is correct
33 Correct 1 ms 2388 KB Output is correct
34 Correct 766 ms 162892 KB Output is correct
35 Correct 816 ms 162780 KB Output is correct
36 Correct 825 ms 162784 KB Output is correct
37 Correct 979 ms 162924 KB Output is correct
38 Correct 1 ms 2388 KB Output is correct
39 Correct 64 ms 21276 KB Output is correct
40 Correct 65 ms 21324 KB Output is correct
41 Correct 66 ms 21324 KB Output is correct
42 Correct 72 ms 21396 KB Output is correct
43 Correct 66 ms 21324 KB Output is correct
44 Correct 64 ms 21332 KB Output is correct
45 Correct 73 ms 21388 KB Output is correct
46 Correct 77 ms 21324 KB Output is correct
47 Correct 67 ms 21332 KB Output is correct
48 Correct 85 ms 21320 KB Output is correct
49 Correct 81 ms 21324 KB Output is correct
50 Correct 71 ms 21324 KB Output is correct
51 Correct 783 ms 162724 KB Output is correct
52 Correct 814 ms 162712 KB Output is correct
53 Correct 892 ms 162892 KB Output is correct
54 Correct 60 ms 21324 KB Output is correct
55 Correct 64 ms 21324 KB Output is correct
56 Correct 77 ms 23388 KB Output is correct
57 Correct 1 ms 2556 KB Output is correct
58 Correct 85 ms 21320 KB Output is correct
59 Correct 82 ms 21296 KB Output is correct
60 Correct 972 ms 162700 KB Output is correct
61 Correct 80 ms 21324 KB Output is correct
62 Correct 93 ms 21380 KB Output is correct
63 Correct 83 ms 21324 KB Output is correct
64 Correct 83 ms 21416 KB Output is correct
65 Correct 85 ms 21324 KB Output is correct
66 Correct 68 ms 21328 KB Output is correct
67 Correct 69 ms 21580 KB Output is correct
68 Correct 76 ms 21324 KB Output is correct
69 Correct 82 ms 21324 KB Output is correct
70 Correct 961 ms 162680 KB Output is correct
71 Correct 65 ms 21324 KB Output is correct
72 Correct 803 ms 162688 KB Output is correct
73 Correct 763 ms 162804 KB Output is correct
74 Correct 1 ms 2388 KB Output is correct
75 Correct 1 ms 2388 KB Output is correct
76 Correct 1 ms 2388 KB Output is correct
77 Correct 1 ms 2388 KB Output is correct
78 Correct 1 ms 2388 KB Output is correct
79 Correct 7 ms 3988 KB Output is correct
80 Correct 877 ms 162684 KB Output is correct
81 Correct 854 ms 162756 KB Output is correct
82 Correct 961 ms 162920 KB Output is correct
83 Correct 1030 ms 162884 KB Output is correct
84 Correct 1026 ms 162844 KB Output is correct
85 Correct 921 ms 162936 KB Output is correct
86 Correct 84 ms 23372 KB Output is correct
87 Correct 1 ms 2388 KB Output is correct