Submission #260698

# Submission time Handle Problem Language Result Execution time Memory
260698 2020-08-10T18:22:16 Z tko919 Strange Device (APIO19_strange_device) C++17
100 / 100
3034 ms 155364 KB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

typedef pair<ll,ll> P;

int main(){
   ll n,a,b; cin>>n>>a>>b;
   ll g=a/gcd(a,b+1);
   if(b>INF/g)g=INF; else g*=b;
   vector<P> rng; vector<ll> vs={0,g};
   rep(i,0,n){
      ll lb,rb; cin>>lb>>rb; rb++;
      if(rb-lb>g){
         cout<<g<<endl;
         return 0;
      }
      lb%=g; rb%=g;
      vs.push_back(lb);
      vs.push_back(rb);
      if(lb<rb){
         rng.push_back({lb,1});
         rng.push_back({rb,-1});
      }
      else{
         rng.push_back({0,1});
         rng.push_back({rb,-1});
         rng.push_back({lb,1});
         rng.push_back({g,-1});
      }
   }
   sort(ALL(vs)); vs.erase(unique(ALL(vs)),vs.end());
   map<ll,int> rev;
   rep(i,0,vs.size())rev[vs[i]]=i;
   int m=vs.size();
   vector<ll> rui(m+10,0);
   rep(i,0,rng.size())rui[rev[rng[i].first]]+=rng[i].second;
   rep(i,0,m)rui[i+1]+=rui[i];
   ll res=0;
   rep(i,0,m){
      if(rui[i])res+=vs[i+1]-vs[i];
   }
   cout<<res<<endl;
   return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 28 ms 1912 KB Output is correct
3 Correct 27 ms 1904 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 380 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 29 ms 1912 KB Output is correct
17 Correct 290 ms 16016 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 1649 ms 72752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 2956 ms 155072 KB Output is correct
3 Correct 3034 ms 155248 KB Output is correct
4 Correct 2971 ms 155216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 2956 ms 155072 KB Output is correct
3 Correct 3034 ms 155248 KB Output is correct
4 Correct 2971 ms 155216 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 2948 ms 155280 KB Output is correct
7 Correct 2932 ms 155124 KB Output is correct
8 Correct 2893 ms 155168 KB Output is correct
9 Correct 3010 ms 155268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 2956 ms 155072 KB Output is correct
3 Correct 3034 ms 155248 KB Output is correct
4 Correct 2971 ms 155216 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 285 ms 15948 KB Output is correct
7 Correct 280 ms 15816 KB Output is correct
8 Correct 272 ms 16072 KB Output is correct
9 Correct 303 ms 15856 KB Output is correct
10 Correct 295 ms 15952 KB Output is correct
11 Correct 284 ms 15824 KB Output is correct
12 Correct 275 ms 15816 KB Output is correct
13 Correct 289 ms 15820 KB Output is correct
14 Correct 280 ms 15848 KB Output is correct
15 Correct 307 ms 16096 KB Output is correct
16 Correct 294 ms 15964 KB Output is correct
17 Correct 286 ms 15824 KB Output is correct
18 Correct 2883 ms 155136 KB Output is correct
19 Correct 2935 ms 155200 KB Output is correct
20 Correct 2985 ms 155064 KB Output is correct
21 Correct 285 ms 15944 KB Output is correct
22 Correct 278 ms 15828 KB Output is correct
23 Correct 769 ms 31036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 285 ms 15884 KB Output is correct
3 Correct 284 ms 15816 KB Output is correct
4 Correct 2952 ms 155108 KB Output is correct
5 Correct 286 ms 15972 KB Output is correct
6 Correct 286 ms 15816 KB Output is correct
7 Correct 285 ms 15952 KB Output is correct
8 Correct 284 ms 15824 KB Output is correct
9 Correct 285 ms 15820 KB Output is correct
10 Correct 286 ms 15820 KB Output is correct
11 Correct 287 ms 15824 KB Output is correct
12 Correct 277 ms 16076 KB Output is correct
13 Correct 282 ms 15848 KB Output is correct
14 Correct 2991 ms 154892 KB Output is correct
15 Correct 287 ms 15844 KB Output is correct
16 Correct 2949 ms 155064 KB Output is correct
17 Correct 2939 ms 155364 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 28 ms 1912 KB Output is correct
3 Correct 27 ms 1904 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 380 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 29 ms 1912 KB Output is correct
17 Correct 290 ms 16016 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 0 ms 256 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 1 ms 256 KB Output is correct
25 Correct 4 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 1649 ms 72752 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 2956 ms 155072 KB Output is correct
31 Correct 3034 ms 155248 KB Output is correct
32 Correct 2971 ms 155216 KB Output is correct
33 Correct 1 ms 256 KB Output is correct
34 Correct 2948 ms 155280 KB Output is correct
35 Correct 2932 ms 155124 KB Output is correct
36 Correct 2893 ms 155168 KB Output is correct
37 Correct 3010 ms 155268 KB Output is correct
38 Correct 0 ms 256 KB Output is correct
39 Correct 285 ms 15948 KB Output is correct
40 Correct 280 ms 15816 KB Output is correct
41 Correct 272 ms 16072 KB Output is correct
42 Correct 303 ms 15856 KB Output is correct
43 Correct 295 ms 15952 KB Output is correct
44 Correct 284 ms 15824 KB Output is correct
45 Correct 275 ms 15816 KB Output is correct
46 Correct 289 ms 15820 KB Output is correct
47 Correct 280 ms 15848 KB Output is correct
48 Correct 307 ms 16096 KB Output is correct
49 Correct 294 ms 15964 KB Output is correct
50 Correct 286 ms 15824 KB Output is correct
51 Correct 2883 ms 155136 KB Output is correct
52 Correct 2935 ms 155200 KB Output is correct
53 Correct 2985 ms 155064 KB Output is correct
54 Correct 285 ms 15944 KB Output is correct
55 Correct 278 ms 15828 KB Output is correct
56 Correct 769 ms 31036 KB Output is correct
57 Correct 1 ms 256 KB Output is correct
58 Correct 285 ms 15884 KB Output is correct
59 Correct 284 ms 15816 KB Output is correct
60 Correct 2952 ms 155108 KB Output is correct
61 Correct 286 ms 15972 KB Output is correct
62 Correct 286 ms 15816 KB Output is correct
63 Correct 285 ms 15952 KB Output is correct
64 Correct 284 ms 15824 KB Output is correct
65 Correct 285 ms 15820 KB Output is correct
66 Correct 286 ms 15820 KB Output is correct
67 Correct 287 ms 15824 KB Output is correct
68 Correct 277 ms 16076 KB Output is correct
69 Correct 282 ms 15848 KB Output is correct
70 Correct 2991 ms 154892 KB Output is correct
71 Correct 287 ms 15844 KB Output is correct
72 Correct 2949 ms 155064 KB Output is correct
73 Correct 2939 ms 155364 KB Output is correct
74 Correct 0 ms 256 KB Output is correct
75 Correct 0 ms 256 KB Output is correct
76 Correct 1 ms 384 KB Output is correct
77 Correct 0 ms 256 KB Output is correct
78 Correct 1 ms 384 KB Output is correct
79 Correct 27 ms 1904 KB Output is correct
80 Correct 3005 ms 155144 KB Output is correct
81 Correct 3007 ms 154932 KB Output is correct
82 Correct 3029 ms 155216 KB Output is correct
83 Correct 3018 ms 154848 KB Output is correct
84 Correct 3029 ms 154932 KB Output is correct
85 Correct 2999 ms 155016 KB Output is correct
86 Correct 761 ms 30908 KB Output is correct
87 Correct 1 ms 256 KB Output is correct