Submission #142677

# Submission time Handle Problem Language Result Execution time Memory
142677 2019-08-10T12:33:59 Z Bodo171 Strange Device (APIO19_strange_device) C++14
100 / 100
1547 ms 64784 KB
#include <iostream>
#include <set>
#include <fstream>
using namespace std;
const long long lim=(long long)(1LL*1e18)+1;
long long n,i,j,l,r,A,B,L,R;
long long ans;
bool brk;
struct pct
{
    long long x,y;
}nl;
bool operator <(pct unu,pct doi)
{
    if(unu.x==doi.x) return unu.y<doi.y;
    return unu.x<doi.x;
}
bool operator !=(pct unu,pct doi)
{
    return (unu.x!=doi.x||unu.y!=doi.y);
}
set <pct> s;
set <pct>::iterator it,it1;
long long gcd(long long x,long long y)
{
    if((!x)||(!y)) return (x+y);
    return gcd(y,x%y);
}
void baga(long long st,long long dr)
{
    it=s.lower_bound({st,0});
    while(it!=s.end()&&(*it).x<=dr)
    {
        dr=max(dr,(*it).y);
        it1=it;it1++;s.erase(it);
        it=it1;
    }
    it=s.lower_bound({st,0});
    if(it!=s.begin())
    {
        it--;
        if((*it).y>=st)
        {
            st=min(st,(*it).x);
            dr=max(dr,(*it).y);
            s.erase(it);
        }
    }
    s.insert({st,dr});
}
int main()
{
    //freopen("data.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin>>n>>A>>B;
    long long t=gcd(A,B+1);
    A/=t;
    long long per;
    if(lim/A<=B) per=1LL*lim;
    else per=1LL*A*B;
    for(i=1;i<=n;i++)
    {
        cin>>l>>r;
        if(l/per==r/per)
        {
            baga(l%per,r%per);
        }
        else
        {
            if(l/per+1<r/per)
                baga(0,per-1);
            baga(l%per,per-1);
            baga(0,r%per);
        }
    }
    for(it=s.begin();it!=s.end();it++)
        ans+=1LL*((*it).y-(*it).x+1);
    cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 11 ms 888 KB Output is correct
3 Correct 12 ms 1272 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 12 ms 1272 KB Output is correct
17 Correct 122 ms 7596 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 0 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 476 ms 1784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 1284 ms 62936 KB Output is correct
3 Correct 1339 ms 62984 KB Output is correct
4 Correct 1469 ms 63208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 1284 ms 62936 KB Output is correct
3 Correct 1339 ms 62984 KB Output is correct
4 Correct 1469 ms 63208 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 1350 ms 63104 KB Output is correct
7 Correct 1348 ms 63120 KB Output is correct
8 Correct 1363 ms 62988 KB Output is correct
9 Correct 1540 ms 63004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 1284 ms 62936 KB Output is correct
3 Correct 1339 ms 62984 KB Output is correct
4 Correct 1469 ms 63208 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 118 ms 6640 KB Output is correct
7 Correct 110 ms 6868 KB Output is correct
8 Correct 112 ms 6864 KB Output is correct
9 Correct 129 ms 6804 KB Output is correct
10 Correct 111 ms 6776 KB Output is correct
11 Correct 111 ms 6752 KB Output is correct
12 Correct 114 ms 6888 KB Output is correct
13 Correct 126 ms 6812 KB Output is correct
14 Correct 107 ms 6748 KB Output is correct
15 Correct 133 ms 6780 KB Output is correct
16 Correct 126 ms 6656 KB Output is correct
17 Correct 121 ms 7860 KB Output is correct
18 Correct 1273 ms 64256 KB Output is correct
19 Correct 1366 ms 64356 KB Output is correct
20 Correct 1429 ms 64592 KB Output is correct
21 Correct 111 ms 7928 KB Output is correct
22 Correct 125 ms 8084 KB Output is correct
23 Correct 200 ms 1784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 131 ms 7252 KB Output is correct
3 Correct 128 ms 7276 KB Output is correct
4 Correct 1412 ms 63504 KB Output is correct
5 Correct 129 ms 6896 KB Output is correct
6 Correct 130 ms 6844 KB Output is correct
7 Correct 131 ms 7208 KB Output is correct
8 Correct 128 ms 7176 KB Output is correct
9 Correct 126 ms 7180 KB Output is correct
10 Correct 111 ms 7156 KB Output is correct
11 Correct 115 ms 7228 KB Output is correct
12 Correct 117 ms 7288 KB Output is correct
13 Correct 127 ms 7160 KB Output is correct
14 Correct 1515 ms 63988 KB Output is correct
15 Correct 104 ms 6404 KB Output is correct
16 Correct 1255 ms 64668 KB Output is correct
17 Correct 1265 ms 64708 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 11 ms 888 KB Output is correct
3 Correct 12 ms 1272 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 12 ms 1272 KB Output is correct
17 Correct 122 ms 7596 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 0 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 476 ms 1784 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 1284 ms 62936 KB Output is correct
31 Correct 1339 ms 62984 KB Output is correct
32 Correct 1469 ms 63208 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 1350 ms 63104 KB Output is correct
35 Correct 1348 ms 63120 KB Output is correct
36 Correct 1363 ms 62988 KB Output is correct
37 Correct 1540 ms 63004 KB Output is correct
38 Correct 2 ms 256 KB Output is correct
39 Correct 118 ms 6640 KB Output is correct
40 Correct 110 ms 6868 KB Output is correct
41 Correct 112 ms 6864 KB Output is correct
42 Correct 129 ms 6804 KB Output is correct
43 Correct 111 ms 6776 KB Output is correct
44 Correct 111 ms 6752 KB Output is correct
45 Correct 114 ms 6888 KB Output is correct
46 Correct 126 ms 6812 KB Output is correct
47 Correct 107 ms 6748 KB Output is correct
48 Correct 133 ms 6780 KB Output is correct
49 Correct 126 ms 6656 KB Output is correct
50 Correct 121 ms 7860 KB Output is correct
51 Correct 1273 ms 64256 KB Output is correct
52 Correct 1366 ms 64356 KB Output is correct
53 Correct 1429 ms 64592 KB Output is correct
54 Correct 111 ms 7928 KB Output is correct
55 Correct 125 ms 8084 KB Output is correct
56 Correct 200 ms 1784 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 131 ms 7252 KB Output is correct
59 Correct 128 ms 7276 KB Output is correct
60 Correct 1412 ms 63504 KB Output is correct
61 Correct 129 ms 6896 KB Output is correct
62 Correct 130 ms 6844 KB Output is correct
63 Correct 131 ms 7208 KB Output is correct
64 Correct 128 ms 7176 KB Output is correct
65 Correct 126 ms 7180 KB Output is correct
66 Correct 111 ms 7156 KB Output is correct
67 Correct 115 ms 7228 KB Output is correct
68 Correct 117 ms 7288 KB Output is correct
69 Correct 127 ms 7160 KB Output is correct
70 Correct 1515 ms 63988 KB Output is correct
71 Correct 104 ms 6404 KB Output is correct
72 Correct 1255 ms 64668 KB Output is correct
73 Correct 1265 ms 64708 KB Output is correct
74 Correct 2 ms 376 KB Output is correct
75 Correct 2 ms 376 KB Output is correct
76 Correct 2 ms 376 KB Output is correct
77 Correct 2 ms 376 KB Output is correct
78 Correct 2 ms 376 KB Output is correct
79 Correct 11 ms 1272 KB Output is correct
80 Correct 1474 ms 64632 KB Output is correct
81 Correct 1399 ms 64692 KB Output is correct
82 Correct 1539 ms 64784 KB Output is correct
83 Correct 1505 ms 64720 KB Output is correct
84 Correct 1547 ms 64660 KB Output is correct
85 Correct 1422 ms 64636 KB Output is correct
86 Correct 204 ms 3688 KB Output is correct
87 Correct 3 ms 376 KB Output is correct