Submission #753473

# Submission time Handle Problem Language Result Execution time Memory
753473 2023-06-05T09:40:24 Z karrigan Strange Device (APIO19_strange_device) C++14
100 / 100
1348 ms 172824 KB
#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
using pii=pair<int,int>;
using pli=pair<long long,int>;
using pil=pair<int,long long>;
using pll=pair<long long,long long>;
const int maxn=1e6+9;
pll a[maxn];
vector<pll>b[maxn];
struct cus{
long long l,r;
bool operator < (const cus &p)const {
if (r==p.r)return l<p.l;
return r<p.r;
}
};
int bit[maxn*2];
signed main(){
    srand(time(0));
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("usaco.INP","r",stdin);
    //freopen("usaco.OUT","w",stdout);
    int n;
    long long x,y;
    cin>>n>>x>>y;
    for1(i,1,n){
    cin>>a[i].fi>>a[i].se;
    }
    long long d1=a[n].se/y;
    long long t=x/gcd(x,y+1);
    if (d1<t){
        long long ans=0;
        for1(i,1,n){
        ans+=(a[i].se-a[i].fi+1);
        }
        cout<<ans;
        return 0;
    }
    long long z=t*y;
    for1(i,1,n){
    long long d=(a[i].fi)/z;
    a[i].fi-=z*d;
    a[i].se-=z*d;
    long long t1=a[i].fi/z,t2=a[i].se/z;
    if (t1+1<t2){
        b[i].pb({0,z-1});
        continue;
    }
    if (t1==t2){
        b[i].pb({a[i].fi%z,a[i].se%z});
        continue;
    }
    pll l1={a[i].fi,z-1};
    pll l2={0,a[i].se%z};
    b[i].pb(l1);
    b[i].pb(l2);
    }
    vector<long long>cord;
    for1(i,1,n){
    for (auto v:b[i]){
        cord.pb(v.fi);
        cord.pb(v.se+1);
    }
    }
    sort(all(cord));
    vector<long long>::iterator it=unique(all(cord));
    cord.resize(distance(cord.begin(),it));
    map<long long,int>newcord;
    for1(i,0,sz(cord)-1){
    newcord[cord[i]]=i;
    }
    for1(i,1,n){
    for (auto &v:b[i]){
        v.fi=newcord[v.fi];
        bit[v.fi]++;
        bit[newcord[v.se+1]]--;
    }
    }
    for1(i,1,sz(cord)-1){
    bit[i]+=bit[i-1];
    }
    long long ans=0;
    for1(i,0,sz(cord)-2){
    if (bit[i]){
        ans+=cord[i+1]-cord[i];
    }
    }
    for1(i,sz(cord)-1,sz(cord)-1){
    if (bit[i]){
        ans++;
    }
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23764 KB Output is correct
2 Correct 19 ms 25424 KB Output is correct
3 Correct 28 ms 25484 KB Output is correct
4 Correct 12 ms 23748 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 12 ms 23740 KB Output is correct
7 Correct 12 ms 23848 KB Output is correct
8 Correct 12 ms 23728 KB Output is correct
9 Correct 12 ms 23820 KB Output is correct
10 Correct 14 ms 23764 KB Output is correct
11 Correct 12 ms 23812 KB Output is correct
12 Correct 13 ms 23824 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 12 ms 23764 KB Output is correct
15 Correct 12 ms 23764 KB Output is correct
16 Correct 31 ms 25424 KB Output is correct
17 Correct 116 ms 40416 KB Output is correct
18 Correct 13 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23784 KB Output is correct
2 Correct 12 ms 23748 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23792 KB Output is correct
5 Correct 13 ms 23824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23764 KB Output is correct
2 Correct 13 ms 23944 KB Output is correct
3 Correct 13 ms 23948 KB Output is correct
4 Correct 14 ms 23924 KB Output is correct
5 Correct 404 ms 87972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23696 KB Output is correct
2 Correct 1130 ms 154248 KB Output is correct
3 Correct 1136 ms 154404 KB Output is correct
4 Correct 1161 ms 172664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23696 KB Output is correct
2 Correct 1130 ms 154248 KB Output is correct
3 Correct 1136 ms 154404 KB Output is correct
4 Correct 1161 ms 172664 KB Output is correct
5 Correct 17 ms 23764 KB Output is correct
6 Correct 1152 ms 172600 KB Output is correct
7 Correct 1116 ms 172656 KB Output is correct
8 Correct 1178 ms 172668 KB Output is correct
9 Correct 1236 ms 172716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23696 KB Output is correct
2 Correct 1130 ms 154248 KB Output is correct
3 Correct 1136 ms 154404 KB Output is correct
4 Correct 1161 ms 172664 KB Output is correct
5 Correct 17 ms 23764 KB Output is correct
6 Correct 145 ms 40408 KB Output is correct
7 Correct 137 ms 40424 KB Output is correct
8 Correct 123 ms 40464 KB Output is correct
9 Correct 112 ms 40328 KB Output is correct
10 Correct 124 ms 40448 KB Output is correct
11 Correct 118 ms 40444 KB Output is correct
12 Correct 119 ms 40340 KB Output is correct
13 Correct 117 ms 40412 KB Output is correct
14 Correct 111 ms 40392 KB Output is correct
15 Correct 124 ms 40392 KB Output is correct
16 Correct 143 ms 40376 KB Output is correct
17 Correct 113 ms 40368 KB Output is correct
18 Correct 1231 ms 172712 KB Output is correct
19 Correct 1184 ms 172612 KB Output is correct
20 Correct 1348 ms 172576 KB Output is correct
21 Correct 123 ms 40440 KB Output is correct
22 Correct 119 ms 40360 KB Output is correct
23 Correct 202 ms 60748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 148 ms 40352 KB Output is correct
3 Correct 130 ms 40384 KB Output is correct
4 Correct 1347 ms 158004 KB Output is correct
5 Correct 116 ms 40432 KB Output is correct
6 Correct 139 ms 40396 KB Output is correct
7 Correct 142 ms 40336 KB Output is correct
8 Correct 118 ms 40444 KB Output is correct
9 Correct 124 ms 40408 KB Output is correct
10 Correct 133 ms 40460 KB Output is correct
11 Correct 121 ms 40348 KB Output is correct
12 Correct 123 ms 40452 KB Output is correct
13 Correct 124 ms 40376 KB Output is correct
14 Correct 1215 ms 157996 KB Output is correct
15 Correct 141 ms 40384 KB Output is correct
16 Correct 1042 ms 172608 KB Output is correct
17 Correct 1020 ms 172824 KB Output is correct
18 Correct 18 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23764 KB Output is correct
2 Correct 19 ms 25424 KB Output is correct
3 Correct 28 ms 25484 KB Output is correct
4 Correct 12 ms 23748 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 12 ms 23740 KB Output is correct
7 Correct 12 ms 23848 KB Output is correct
8 Correct 12 ms 23728 KB Output is correct
9 Correct 12 ms 23820 KB Output is correct
10 Correct 14 ms 23764 KB Output is correct
11 Correct 12 ms 23812 KB Output is correct
12 Correct 13 ms 23824 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 12 ms 23764 KB Output is correct
15 Correct 12 ms 23764 KB Output is correct
16 Correct 31 ms 25424 KB Output is correct
17 Correct 116 ms 40416 KB Output is correct
18 Correct 13 ms 23764 KB Output is correct
19 Correct 12 ms 23784 KB Output is correct
20 Correct 12 ms 23748 KB Output is correct
21 Correct 12 ms 23764 KB Output is correct
22 Correct 12 ms 23792 KB Output is correct
23 Correct 13 ms 23824 KB Output is correct
24 Correct 14 ms 23764 KB Output is correct
25 Correct 13 ms 23944 KB Output is correct
26 Correct 13 ms 23948 KB Output is correct
27 Correct 14 ms 23924 KB Output is correct
28 Correct 404 ms 87972 KB Output is correct
29 Correct 13 ms 23696 KB Output is correct
30 Correct 1130 ms 154248 KB Output is correct
31 Correct 1136 ms 154404 KB Output is correct
32 Correct 1161 ms 172664 KB Output is correct
33 Correct 17 ms 23764 KB Output is correct
34 Correct 1152 ms 172600 KB Output is correct
35 Correct 1116 ms 172656 KB Output is correct
36 Correct 1178 ms 172668 KB Output is correct
37 Correct 1236 ms 172716 KB Output is correct
38 Correct 17 ms 23764 KB Output is correct
39 Correct 145 ms 40408 KB Output is correct
40 Correct 137 ms 40424 KB Output is correct
41 Correct 123 ms 40464 KB Output is correct
42 Correct 112 ms 40328 KB Output is correct
43 Correct 124 ms 40448 KB Output is correct
44 Correct 118 ms 40444 KB Output is correct
45 Correct 119 ms 40340 KB Output is correct
46 Correct 117 ms 40412 KB Output is correct
47 Correct 111 ms 40392 KB Output is correct
48 Correct 124 ms 40392 KB Output is correct
49 Correct 143 ms 40376 KB Output is correct
50 Correct 113 ms 40368 KB Output is correct
51 Correct 1231 ms 172712 KB Output is correct
52 Correct 1184 ms 172612 KB Output is correct
53 Correct 1348 ms 172576 KB Output is correct
54 Correct 123 ms 40440 KB Output is correct
55 Correct 119 ms 40360 KB Output is correct
56 Correct 202 ms 60748 KB Output is correct
57 Correct 13 ms 23764 KB Output is correct
58 Correct 148 ms 40352 KB Output is correct
59 Correct 130 ms 40384 KB Output is correct
60 Correct 1347 ms 158004 KB Output is correct
61 Correct 116 ms 40432 KB Output is correct
62 Correct 139 ms 40396 KB Output is correct
63 Correct 142 ms 40336 KB Output is correct
64 Correct 118 ms 40444 KB Output is correct
65 Correct 124 ms 40408 KB Output is correct
66 Correct 133 ms 40460 KB Output is correct
67 Correct 121 ms 40348 KB Output is correct
68 Correct 123 ms 40452 KB Output is correct
69 Correct 124 ms 40376 KB Output is correct
70 Correct 1215 ms 157996 KB Output is correct
71 Correct 141 ms 40384 KB Output is correct
72 Correct 1042 ms 172608 KB Output is correct
73 Correct 1020 ms 172824 KB Output is correct
74 Correct 18 ms 23764 KB Output is correct
75 Correct 16 ms 23808 KB Output is correct
76 Correct 14 ms 23808 KB Output is correct
77 Correct 13 ms 23764 KB Output is correct
78 Correct 12 ms 23816 KB Output is correct
79 Correct 21 ms 25424 KB Output is correct
80 Correct 1149 ms 172736 KB Output is correct
81 Correct 1140 ms 172600 KB Output is correct
82 Correct 1093 ms 172660 KB Output is correct
83 Correct 1196 ms 172604 KB Output is correct
84 Correct 1304 ms 172760 KB Output is correct
85 Correct 1279 ms 172608 KB Output is correct
86 Correct 175 ms 60708 KB Output is correct
87 Correct 16 ms 23764 KB Output is correct