Submission #1068820

# Submission time Handle Problem Language Result Execution time Memory
1068820 2024-08-21T12:22:13 Z alexdd Strange Device (APIO19_strange_device) C++17
100 / 100
1743 ms 115956 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
int gcd(int x, int y)
{
    while(x>0)
    {
        int r = y%x;
        y=x;
        x=r;
    }
    return y;
}
set<pair<__int128,__int128>> s;
void baga(__int128 le, __int128 ri)
{
    if(s.empty())
    {
        s.insert({le,ri});
        return;
    }
    auto it = s.lower_bound({le+1,-1});
    if(it!=s.begin()) it--;
    while(it!=s.end())
    {
        if((*it).first > ri)
            break;
        else if((*it).second < le)
        {
            it++;
        }
        else
        {
            le = min(le, (*it).first);
            ri = max(ri, (*it).second);
            it = s.erase(it);
        }
    }
    s.insert({le,ri});
}
void afis(__int128 x)
{
    vector<int> cif;
    __int128 zece=10;
    while(x>0)
    {
        cif.push_back(x%zece);
        x/=zece;
    }
    reverse(cif.begin(),cif.end());
    for(auto c:cif) cout<<c;
}
signed main()
{
    int n,A,B;
    cin>>n>>A>>B;
    A = A / gcd(A,B+1);
    __int128 le,ri;

    __int128 copA=A,copB=B;
    __int128 prod=copA*copB;

    int cle,cri;
    for(int i=1;i<=n;i++)
    {
        cin>>cle>>cri;
        le=cle;
        ri=cri;
        if(le==ri)
        {
            baga(le%prod,le%prod);
            continue;
        }
        if(le/prod+1 < ri/prod)
        {
            afis(prod);
            return 0;
        }
        le = le%prod;
        ri = ri%prod;
        if(le<ri)
        {
            baga(le,ri);
        }
        else
        {
            baga(le,prod-1);
            baga(0,ri);
        }
    }
    __int128 cnt=0;
    for(auto it:s)
    {
        cnt += it.second-it.first+1;
    }
    afis(cnt);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 11 ms 1208 KB Output is correct
3 Correct 12 ms 1116 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 11 ms 1116 KB Output is correct
17 Correct 148 ms 8020 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
# 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 348 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 681 ms 416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1215 ms 78416 KB Output is correct
3 Correct 1196 ms 78672 KB Output is correct
4 Correct 1345 ms 78492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1215 ms 78416 KB Output is correct
3 Correct 1196 ms 78672 KB Output is correct
4 Correct 1345 ms 78492 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1401 ms 78580 KB Output is correct
7 Correct 1370 ms 78672 KB Output is correct
8 Correct 1277 ms 78468 KB Output is correct
9 Correct 1629 ms 78524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1215 ms 78416 KB Output is correct
3 Correct 1196 ms 78672 KB Output is correct
4 Correct 1345 ms 78492 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 147 ms 8016 KB Output is correct
7 Correct 162 ms 8020 KB Output is correct
8 Correct 109 ms 8020 KB Output is correct
9 Correct 150 ms 8016 KB Output is correct
10 Correct 149 ms 8160 KB Output is correct
11 Correct 178 ms 8020 KB Output is correct
12 Correct 113 ms 8208 KB Output is correct
13 Correct 154 ms 8016 KB Output is correct
14 Correct 180 ms 8020 KB Output is correct
15 Correct 139 ms 8092 KB Output is correct
16 Correct 154 ms 8136 KB Output is correct
17 Correct 178 ms 8156 KB Output is correct
18 Correct 1559 ms 78540 KB Output is correct
19 Correct 1637 ms 78532 KB Output is correct
20 Correct 1551 ms 78644 KB Output is correct
21 Correct 146 ms 8048 KB Output is correct
22 Correct 188 ms 8016 KB Output is correct
23 Correct 302 ms 412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 155 ms 8020 KB Output is correct
3 Correct 123 ms 8092 KB Output is correct
4 Correct 1517 ms 78652 KB Output is correct
5 Correct 168 ms 8280 KB Output is correct
6 Correct 139 ms 8020 KB Output is correct
7 Correct 135 ms 8016 KB Output is correct
8 Correct 134 ms 8020 KB Output is correct
9 Correct 134 ms 8016 KB Output is correct
10 Correct 115 ms 8276 KB Output is correct
11 Correct 185 ms 8020 KB Output is correct
12 Correct 148 ms 8156 KB Output is correct
13 Correct 168 ms 8088 KB Output is correct
14 Correct 1501 ms 78452 KB Output is correct
15 Correct 147 ms 7252 KB Output is correct
16 Correct 1300 ms 78468 KB Output is correct
17 Correct 1433 ms 78568 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 11 ms 1208 KB Output is correct
3 Correct 12 ms 1116 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 11 ms 1116 KB Output is correct
17 Correct 148 ms 8020 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 3 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 681 ms 416 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1215 ms 78416 KB Output is correct
31 Correct 1196 ms 78672 KB Output is correct
32 Correct 1345 ms 78492 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1401 ms 78580 KB Output is correct
35 Correct 1370 ms 78672 KB Output is correct
36 Correct 1277 ms 78468 KB Output is correct
37 Correct 1629 ms 78524 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 147 ms 8016 KB Output is correct
40 Correct 162 ms 8020 KB Output is correct
41 Correct 109 ms 8020 KB Output is correct
42 Correct 150 ms 8016 KB Output is correct
43 Correct 149 ms 8160 KB Output is correct
44 Correct 178 ms 8020 KB Output is correct
45 Correct 113 ms 8208 KB Output is correct
46 Correct 154 ms 8016 KB Output is correct
47 Correct 180 ms 8020 KB Output is correct
48 Correct 139 ms 8092 KB Output is correct
49 Correct 154 ms 8136 KB Output is correct
50 Correct 178 ms 8156 KB Output is correct
51 Correct 1559 ms 78540 KB Output is correct
52 Correct 1637 ms 78532 KB Output is correct
53 Correct 1551 ms 78644 KB Output is correct
54 Correct 146 ms 8048 KB Output is correct
55 Correct 188 ms 8016 KB Output is correct
56 Correct 302 ms 412 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 155 ms 8020 KB Output is correct
59 Correct 123 ms 8092 KB Output is correct
60 Correct 1517 ms 78652 KB Output is correct
61 Correct 168 ms 8280 KB Output is correct
62 Correct 139 ms 8020 KB Output is correct
63 Correct 135 ms 8016 KB Output is correct
64 Correct 134 ms 8020 KB Output is correct
65 Correct 134 ms 8016 KB Output is correct
66 Correct 115 ms 8276 KB Output is correct
67 Correct 185 ms 8020 KB Output is correct
68 Correct 148 ms 8156 KB Output is correct
69 Correct 168 ms 8088 KB Output is correct
70 Correct 1501 ms 78452 KB Output is correct
71 Correct 147 ms 7252 KB Output is correct
72 Correct 1300 ms 78468 KB Output is correct
73 Correct 1433 ms 78568 KB Output is correct
74 Correct 1 ms 348 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 18 ms 1468 KB Output is correct
80 Correct 1456 ms 115684 KB Output is correct
81 Correct 1324 ms 115796 KB Output is correct
82 Correct 1658 ms 115632 KB Output is correct
83 Correct 1743 ms 115736 KB Output is correct
84 Correct 1580 ms 115772 KB Output is correct
85 Correct 1627 ms 115956 KB Output is correct
86 Correct 372 ms 12828 KB Output is correct
87 Correct 1 ms 344 KB Output is correct