Submission #547706

# Submission time Handle Problem Language Result Execution time Memory
547706 2022-04-11T14:02:55 Z hihihaha Strange Device (APIO19_strange_device) C++17
100 / 100
1472 ms 68888 KB
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
int v2(ll n)
{
    int i=-1;
    while (n!=0)
    {
        n=n/2;
        i++;
    }
    return i;
}
int n,i,j,status=0,idx;
pair<ll,ll> in[10000001];
pair<ll,ll> out[10000001];
ll a,b,tmp,l,r,cnt;
int main()
{
    cin>>n>>a>>b;
    tmp=a/(__gcd(a,b+1));


    i=0;
    while(i<n)
    {
        cin >> in[i].fi >> in[i].se;
        i++;
    }



    if (v2(tmp)+v2(b)>61)
    {
        i=0;
        cnt=0;
        while(i<n)
        {
            cnt=cnt+(in[i].se-in[i].fi+1);
            i++;
        }
        cout << cnt;
    }




    else
    {
        tmp=tmp*b;
        //cout << tmp<<endl;
        i=0;
        j=0;
        while (i<n)
        {
            if(in[i].fi/tmp == in[i].se/tmp)
            {
                out[i+j].fi=in[i].fi%tmp;
                out[i+j].se=in[i].se%tmp;
            }
            else if ((in[i].fi/tmp) +1 == in[i].se/tmp)
            {
                out[i+j].fi=in[i].fi%tmp;
                out[i+j].se=tmp-1;
                j++;
                out[i+j].fi=0;
                out[i+j].se=in[i].se%tmp;
            }
            else
            {
                status=1;
            }
            i++;
        }




        if (status==1)
        {
            cout << tmp;
        }
        else
        {
            idx=i+j;
            //cout << idx<<endl;
            //i=0;
            //while (i<idx)
            //{
            //    cout << out[i].fi <<" "<< out[i].se << endl;
            //    i++;
            //}
            sort (out+0,out+idx);
            l=out[0].fi;
            r=out[0].se;
            cnt=r-l+1;
            i=1;
            while (i<idx)
            {
                if (out[i].fi>r)
                {
                    l=out[i].fi;
                    r=out[i].se;
                    cnt=cnt+r-l+1;
                }
                else
                {
                    if(out[i].se<=r)
                    {

                    }
                    else
                    {
                        cnt=cnt+out[i].se-r;
                        r=out[i].se;
                    }
                }
                i++;
            }
            cout << cnt;
        }

    }


}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 17 ms 960 KB Output is correct
3 Correct 15 ms 1076 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 352 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 17 ms 892 KB Output is correct
17 Correct 189 ms 7044 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 2 ms 356 KB Output is correct
5 Correct 1029 ms 37456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1451 ms 31892 KB Output is correct
3 Correct 1403 ms 39156 KB Output is correct
4 Correct 1460 ms 39156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1451 ms 31892 KB Output is correct
3 Correct 1403 ms 39156 KB Output is correct
4 Correct 1460 ms 39156 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1383 ms 39124 KB Output is correct
7 Correct 1412 ms 39116 KB Output is correct
8 Correct 1421 ms 39220 KB Output is correct
9 Correct 1402 ms 39080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1451 ms 31892 KB Output is correct
3 Correct 1403 ms 39156 KB Output is correct
4 Correct 1460 ms 39156 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 162 ms 7100 KB Output is correct
7 Correct 139 ms 7100 KB Output is correct
8 Correct 140 ms 7116 KB Output is correct
9 Correct 150 ms 7144 KB Output is correct
10 Correct 144 ms 7140 KB Output is correct
11 Correct 139 ms 7020 KB Output is correct
12 Correct 141 ms 7076 KB Output is correct
13 Correct 150 ms 7088 KB Output is correct
14 Correct 135 ms 7140 KB Output is correct
15 Correct 143 ms 7104 KB Output is correct
16 Correct 148 ms 7144 KB Output is correct
17 Correct 142 ms 7156 KB Output is correct
18 Correct 1466 ms 40744 KB Output is correct
19 Correct 1371 ms 40664 KB Output is correct
20 Correct 1439 ms 40676 KB Output is correct
21 Correct 145 ms 7072 KB Output is correct
22 Correct 145 ms 7148 KB Output is correct
23 Correct 456 ms 23492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 149 ms 3744 KB Output is correct
3 Correct 139 ms 7092 KB Output is correct
4 Correct 1472 ms 51544 KB Output is correct
5 Correct 144 ms 7116 KB Output is correct
6 Correct 146 ms 7128 KB Output is correct
7 Correct 145 ms 7024 KB Output is correct
8 Correct 158 ms 7120 KB Output is correct
9 Correct 149 ms 7108 KB Output is correct
10 Correct 139 ms 7056 KB Output is correct
11 Correct 145 ms 7128 KB Output is correct
12 Correct 148 ms 7224 KB Output is correct
13 Correct 141 ms 7064 KB Output is correct
14 Correct 1439 ms 51428 KB Output is correct
15 Correct 149 ms 7100 KB Output is correct
16 Correct 1384 ms 51520 KB Output is correct
17 Correct 1387 ms 51384 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 17 ms 960 KB Output is correct
3 Correct 15 ms 1076 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 352 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 17 ms 892 KB Output is correct
17 Correct 189 ms 7044 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 308 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 2 ms 356 KB Output is correct
28 Correct 1029 ms 37456 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1451 ms 31892 KB Output is correct
31 Correct 1403 ms 39156 KB Output is correct
32 Correct 1460 ms 39156 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1383 ms 39124 KB Output is correct
35 Correct 1412 ms 39116 KB Output is correct
36 Correct 1421 ms 39220 KB Output is correct
37 Correct 1402 ms 39080 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 162 ms 7100 KB Output is correct
40 Correct 139 ms 7100 KB Output is correct
41 Correct 140 ms 7116 KB Output is correct
42 Correct 150 ms 7144 KB Output is correct
43 Correct 144 ms 7140 KB Output is correct
44 Correct 139 ms 7020 KB Output is correct
45 Correct 141 ms 7076 KB Output is correct
46 Correct 150 ms 7088 KB Output is correct
47 Correct 135 ms 7140 KB Output is correct
48 Correct 143 ms 7104 KB Output is correct
49 Correct 148 ms 7144 KB Output is correct
50 Correct 142 ms 7156 KB Output is correct
51 Correct 1466 ms 40744 KB Output is correct
52 Correct 1371 ms 40664 KB Output is correct
53 Correct 1439 ms 40676 KB Output is correct
54 Correct 145 ms 7072 KB Output is correct
55 Correct 145 ms 7148 KB Output is correct
56 Correct 456 ms 23492 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 149 ms 3744 KB Output is correct
59 Correct 139 ms 7092 KB Output is correct
60 Correct 1472 ms 51544 KB Output is correct
61 Correct 144 ms 7116 KB Output is correct
62 Correct 146 ms 7128 KB Output is correct
63 Correct 145 ms 7024 KB Output is correct
64 Correct 158 ms 7120 KB Output is correct
65 Correct 149 ms 7108 KB Output is correct
66 Correct 139 ms 7056 KB Output is correct
67 Correct 145 ms 7128 KB Output is correct
68 Correct 148 ms 7224 KB Output is correct
69 Correct 141 ms 7064 KB Output is correct
70 Correct 1439 ms 51428 KB Output is correct
71 Correct 149 ms 7100 KB Output is correct
72 Correct 1384 ms 51520 KB Output is correct
73 Correct 1387 ms 51384 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
75 Correct 0 ms 308 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 14 ms 932 KB Output is correct
80 Correct 1457 ms 68672 KB Output is correct
81 Correct 1464 ms 68852 KB Output is correct
82 Correct 1371 ms 68888 KB Output is correct
83 Correct 1398 ms 68736 KB Output is correct
84 Correct 1467 ms 68696 KB Output is correct
85 Correct 1435 ms 68700 KB Output is correct
86 Correct 502 ms 23452 KB Output is correct
87 Correct 1 ms 212 KB Output is correct