# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
345496 | 2021-01-07T13:34:25 Z | Kerim | Strange Device (APIO19_strange_device) | C++17 | 768 ms | 26628 KB |
#include "bits/stdc++.h" #define MAXN 100009 #define INF 1000000007 #define mp(x,y) make_pair(x,y) #define all(v) v.begin(),v.end() #define pb(x) push_back(x) #define wr cout<<"----------------"<<endl; #define ppb() pop_back() #define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++) #define ff first #define ss second #define my_little_dodge 46 #define debug(x) cerr<< #x <<" = "<< x<<endl; using namespace std; typedef long long ll; typedef pair<ll,ll> PII; template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} const ll B=1e18+1; int main(){ // freopen("file.in","r",stdin); int n; scanf("%d",&n); ll a,b; scanf("%lld%lld",&a,&b); ll mod=a/__gcd(a,b+1); if(mod<=B/b) mod*=b; else mod=B; vector<PII>v; for(int i=1;i<=n;i++){ ll l,r; scanf("%lld%lld",&l,&r); if(r-l+1>=mod){ printf("%lld\n",mod); return 0; } l%=mod;r%=mod; if(l<=r) v.pb(mp(l,r)); else{ v.pb(mp(l,mod-1)); v.pb(mp(0,r)); } } sort(all(v)); PII as=mp(-1,-1); ll ans=0; tr(it,v){ if(as.ss<it->ff){ if(~as.ff) ans+=as.ss-as.ff+1; as=*it; } else umax(as.ss,it->ss); } printf("%lld\n",ans+as.ss-as.ff+1); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 8 ms | 1004 KB | Output is correct |
3 | Correct | 6 ms | 1132 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 372 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 8 ms | 1132 KB | Output is correct |
17 | Correct | 58 ms | 5724 KB | Output is correct |
18 | Correct | 1 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 407 ms | 23136 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 567 ms | 16964 KB | Output is correct |
3 | Correct | 506 ms | 17352 KB | Output is correct |
4 | Correct | 497 ms | 17480 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 567 ms | 16964 KB | Output is correct |
3 | Correct | 506 ms | 17352 KB | Output is correct |
4 | Correct | 497 ms | 17480 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 545 ms | 17352 KB | Output is correct |
7 | Correct | 503 ms | 26468 KB | Output is correct |
8 | Correct | 502 ms | 26440 KB | Output is correct |
9 | Correct | 584 ms | 26360 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 567 ms | 16964 KB | Output is correct |
3 | Correct | 506 ms | 17352 KB | Output is correct |
4 | Correct | 497 ms | 17480 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 50 ms | 3040 KB | Output is correct |
7 | Correct | 69 ms | 5724 KB | Output is correct |
8 | Correct | 59 ms | 5724 KB | Output is correct |
9 | Correct | 76 ms | 5720 KB | Output is correct |
10 | Correct | 73 ms | 5872 KB | Output is correct |
11 | Correct | 54 ms | 5724 KB | Output is correct |
12 | Correct | 51 ms | 5724 KB | Output is correct |
13 | Correct | 65 ms | 5724 KB | Output is correct |
14 | Correct | 74 ms | 5768 KB | Output is correct |
15 | Correct | 55 ms | 5724 KB | Output is correct |
16 | Correct | 54 ms | 5724 KB | Output is correct |
17 | Correct | 50 ms | 5724 KB | Output is correct |
18 | Correct | 520 ms | 26440 KB | Output is correct |
19 | Correct | 535 ms | 26440 KB | Output is correct |
20 | Correct | 645 ms | 26628 KB | Output is correct |
21 | Correct | 54 ms | 5724 KB | Output is correct |
22 | Correct | 69 ms | 5724 KB | Output is correct |
23 | Correct | 159 ms | 18516 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 75 ms | 5724 KB | Output is correct |
3 | Correct | 64 ms | 5744 KB | Output is correct |
4 | Correct | 768 ms | 26404 KB | Output is correct |
5 | Correct | 54 ms | 5724 KB | Output is correct |
6 | Correct | 53 ms | 5724 KB | Output is correct |
7 | Correct | 52 ms | 5724 KB | Output is correct |
8 | Correct | 76 ms | 5724 KB | Output is correct |
9 | Correct | 56 ms | 5720 KB | Output is correct |
10 | Correct | 77 ms | 5724 KB | Output is correct |
11 | Correct | 74 ms | 5724 KB | Output is correct |
12 | Correct | 48 ms | 5724 KB | Output is correct |
13 | Correct | 67 ms | 5880 KB | Output is correct |
14 | Correct | 589 ms | 26592 KB | Output is correct |
15 | Correct | 52 ms | 5724 KB | Output is correct |
16 | Correct | 539 ms | 26440 KB | Output is correct |
17 | Correct | 537 ms | 26568 KB | Output is correct |
18 | Correct | 1 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 8 ms | 1004 KB | Output is correct |
3 | Correct | 6 ms | 1132 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 372 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 8 ms | 1132 KB | Output is correct |
17 | Correct | 58 ms | 5724 KB | Output is correct |
18 | Correct | 1 ms | 384 KB | Output is correct |
19 | Correct | 1 ms | 384 KB | Output is correct |
20 | Correct | 1 ms | 364 KB | Output is correct |
21 | Correct | 1 ms | 364 KB | Output is correct |
22 | Correct | 1 ms | 364 KB | Output is correct |
23 | Correct | 1 ms | 364 KB | Output is correct |
24 | Correct | 1 ms | 364 KB | Output is correct |
25 | Correct | 1 ms | 364 KB | Output is correct |
26 | Correct | 1 ms | 364 KB | Output is correct |
27 | Correct | 1 ms | 364 KB | Output is correct |
28 | Correct | 407 ms | 23136 KB | Output is correct |
29 | Correct | 1 ms | 364 KB | Output is correct |
30 | Correct | 567 ms | 16964 KB | Output is correct |
31 | Correct | 506 ms | 17352 KB | Output is correct |
32 | Correct | 497 ms | 17480 KB | Output is correct |
33 | Correct | 1 ms | 364 KB | Output is correct |
34 | Correct | 545 ms | 17352 KB | Output is correct |
35 | Correct | 503 ms | 26468 KB | Output is correct |
36 | Correct | 502 ms | 26440 KB | Output is correct |
37 | Correct | 584 ms | 26360 KB | Output is correct |
38 | Correct | 1 ms | 364 KB | Output is correct |
39 | Correct | 50 ms | 3040 KB | Output is correct |
40 | Correct | 69 ms | 5724 KB | Output is correct |
41 | Correct | 59 ms | 5724 KB | Output is correct |
42 | Correct | 76 ms | 5720 KB | Output is correct |
43 | Correct | 73 ms | 5872 KB | Output is correct |
44 | Correct | 54 ms | 5724 KB | Output is correct |
45 | Correct | 51 ms | 5724 KB | Output is correct |
46 | Correct | 65 ms | 5724 KB | Output is correct |
47 | Correct | 74 ms | 5768 KB | Output is correct |
48 | Correct | 55 ms | 5724 KB | Output is correct |
49 | Correct | 54 ms | 5724 KB | Output is correct |
50 | Correct | 50 ms | 5724 KB | Output is correct |
51 | Correct | 520 ms | 26440 KB | Output is correct |
52 | Correct | 535 ms | 26440 KB | Output is correct |
53 | Correct | 645 ms | 26628 KB | Output is correct |
54 | Correct | 54 ms | 5724 KB | Output is correct |
55 | Correct | 69 ms | 5724 KB | Output is correct |
56 | Correct | 159 ms | 18516 KB | Output is correct |
57 | Correct | 1 ms | 364 KB | Output is correct |
58 | Correct | 75 ms | 5724 KB | Output is correct |
59 | Correct | 64 ms | 5744 KB | Output is correct |
60 | Correct | 768 ms | 26404 KB | Output is correct |
61 | Correct | 54 ms | 5724 KB | Output is correct |
62 | Correct | 53 ms | 5724 KB | Output is correct |
63 | Correct | 52 ms | 5724 KB | Output is correct |
64 | Correct | 76 ms | 5724 KB | Output is correct |
65 | Correct | 56 ms | 5720 KB | Output is correct |
66 | Correct | 77 ms | 5724 KB | Output is correct |
67 | Correct | 74 ms | 5724 KB | Output is correct |
68 | Correct | 48 ms | 5724 KB | Output is correct |
69 | Correct | 67 ms | 5880 KB | Output is correct |
70 | Correct | 589 ms | 26592 KB | Output is correct |
71 | Correct | 52 ms | 5724 KB | Output is correct |
72 | Correct | 539 ms | 26440 KB | Output is correct |
73 | Correct | 537 ms | 26568 KB | Output is correct |
74 | Correct | 1 ms | 364 KB | Output is correct |
75 | Correct | 1 ms | 364 KB | Output is correct |
76 | Correct | 1 ms | 364 KB | Output is correct |
77 | Correct | 1 ms | 364 KB | Output is correct |
78 | Correct | 1 ms | 364 KB | Output is correct |
79 | Correct | 6 ms | 1132 KB | Output is correct |
80 | Correct | 567 ms | 26440 KB | Output is correct |
81 | Correct | 614 ms | 26484 KB | Output is correct |
82 | Correct | 537 ms | 26440 KB | Output is correct |
83 | Correct | 559 ms | 26440 KB | Output is correct |
84 | Correct | 548 ms | 26400 KB | Output is correct |
85 | Correct | 528 ms | 26440 KB | Output is correct |
86 | Correct | 156 ms | 18516 KB | Output is correct |
87 | Correct | 1 ms | 512 KB | Output is correct |