Submission #719498

# Submission time Handle Problem Language Result Execution time Memory
719498 2023-04-06T06:23:56 Z keisuke6 Strange Device (APIO19_strange_device) C++17
100 / 100
1802 ms 116920 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
signed main(){
  int N,A,B;
  cin>>N>>A>>B;
  B++;
  int g = gcd(A,B);
  B--;
  int p = 0;
  if((double)(1.0)*A*B/g >= 4e18) p = 2e18;
  else p = A/g*B;
  map<int,int> m;
  for(int i=0;i<N;i++){
    int l,r;
    cin>>l>>r;
    if(l == r){
      l %= p;
      r %= p;
      m[l]++;
      m[r+1]--;
      continue;
    }
    if(r-l >= p-1){
      m[0]++;
      m[p]--;
      continue;
    }
    l %= p;
    r %= p;
    if(l >= r){
      m[l]++;
      m[p]--;
      m[0]++;
      m[r+1]--;
    }
    else{
      m[l]++;
      m[r+1]--;
    }
  }
  vector<pair<int,int>> S = {};
  for(auto x:m) S.push_back(x);
  sort(S.begin(),S.end());
  int now = S[0].second;
  int ans = 0;
  for(int i=1;i<S.size();i++){
    if(now){
      ans += S[i].first-S[i-1].first;
    }
    now += S[i].second;
  }
  cout<<ans<<endl;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:48:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |   for(int i=1;i<S.size();i++){
      |               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 15 ms 1320 KB Output is correct
3 Correct 16 ms 1312 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 15 ms 1320 KB Output is correct
17 Correct 158 ms 8680 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 867 ms 276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1622 ms 79436 KB Output is correct
3 Correct 1623 ms 79576 KB Output is correct
4 Correct 1690 ms 79476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1622 ms 79436 KB Output is correct
3 Correct 1623 ms 79576 KB Output is correct
4 Correct 1690 ms 79476 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1674 ms 79476 KB Output is correct
7 Correct 1646 ms 79372 KB Output is correct
8 Correct 1653 ms 79576 KB Output is correct
9 Correct 1688 ms 79496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1622 ms 79436 KB Output is correct
3 Correct 1623 ms 79576 KB Output is correct
4 Correct 1690 ms 79476 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 160 ms 8664 KB Output is correct
7 Correct 148 ms 8640 KB Output is correct
8 Correct 159 ms 8628 KB Output is correct
9 Correct 160 ms 8660 KB Output is correct
10 Correct 151 ms 8708 KB Output is correct
11 Correct 149 ms 8664 KB Output is correct
12 Correct 161 ms 8744 KB Output is correct
13 Correct 161 ms 8672 KB Output is correct
14 Correct 150 ms 8712 KB Output is correct
15 Correct 174 ms 8708 KB Output is correct
16 Correct 177 ms 8716 KB Output is correct
17 Correct 157 ms 8696 KB Output is correct
18 Correct 1601 ms 79696 KB Output is correct
19 Correct 1636 ms 79520 KB Output is correct
20 Correct 1648 ms 79444 KB Output is correct
21 Correct 159 ms 8780 KB Output is correct
22 Correct 157 ms 8688 KB Output is correct
23 Correct 429 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 159 ms 8764 KB Output is correct
3 Correct 163 ms 8668 KB Output is correct
4 Correct 1680 ms 79444 KB Output is correct
5 Correct 166 ms 8688 KB Output is correct
6 Correct 168 ms 8672 KB Output is correct
7 Correct 165 ms 8680 KB Output is correct
8 Correct 167 ms 8732 KB Output is correct
9 Correct 159 ms 8720 KB Output is correct
10 Correct 152 ms 8640 KB Output is correct
11 Correct 156 ms 8736 KB Output is correct
12 Correct 161 ms 8648 KB Output is correct
13 Correct 169 ms 8660 KB Output is correct
14 Correct 1685 ms 79652 KB Output is correct
15 Correct 157 ms 8736 KB Output is correct
16 Correct 1583 ms 79496 KB Output is correct
17 Correct 1584 ms 79480 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 15 ms 1320 KB Output is correct
3 Correct 16 ms 1312 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 15 ms 1320 KB Output is correct
17 Correct 158 ms 8680 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 867 ms 276 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1622 ms 79436 KB Output is correct
31 Correct 1623 ms 79576 KB Output is correct
32 Correct 1690 ms 79476 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1674 ms 79476 KB Output is correct
35 Correct 1646 ms 79372 KB Output is correct
36 Correct 1653 ms 79576 KB Output is correct
37 Correct 1688 ms 79496 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 160 ms 8664 KB Output is correct
40 Correct 148 ms 8640 KB Output is correct
41 Correct 159 ms 8628 KB Output is correct
42 Correct 160 ms 8660 KB Output is correct
43 Correct 151 ms 8708 KB Output is correct
44 Correct 149 ms 8664 KB Output is correct
45 Correct 161 ms 8744 KB Output is correct
46 Correct 161 ms 8672 KB Output is correct
47 Correct 150 ms 8712 KB Output is correct
48 Correct 174 ms 8708 KB Output is correct
49 Correct 177 ms 8716 KB Output is correct
50 Correct 157 ms 8696 KB Output is correct
51 Correct 1601 ms 79696 KB Output is correct
52 Correct 1636 ms 79520 KB Output is correct
53 Correct 1648 ms 79444 KB Output is correct
54 Correct 159 ms 8780 KB Output is correct
55 Correct 157 ms 8688 KB Output is correct
56 Correct 429 ms 212 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 159 ms 8764 KB Output is correct
59 Correct 163 ms 8668 KB Output is correct
60 Correct 1680 ms 79444 KB Output is correct
61 Correct 166 ms 8688 KB Output is correct
62 Correct 168 ms 8672 KB Output is correct
63 Correct 165 ms 8680 KB Output is correct
64 Correct 167 ms 8732 KB Output is correct
65 Correct 159 ms 8720 KB Output is correct
66 Correct 152 ms 8640 KB Output is correct
67 Correct 156 ms 8736 KB Output is correct
68 Correct 161 ms 8648 KB Output is correct
69 Correct 169 ms 8660 KB Output is correct
70 Correct 1685 ms 79652 KB Output is correct
71 Correct 157 ms 8736 KB Output is correct
72 Correct 1583 ms 79496 KB Output is correct
73 Correct 1584 ms 79480 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 1 ms 300 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 16 ms 1632 KB Output is correct
80 Correct 1687 ms 116680 KB Output is correct
81 Correct 1695 ms 116648 KB Output is correct
82 Correct 1771 ms 116620 KB Output is correct
83 Correct 1785 ms 116920 KB Output is correct
84 Correct 1802 ms 116840 KB Output is correct
85 Correct 1768 ms 116628 KB Output is correct
86 Correct 451 ms 12812 KB Output is correct
87 Correct 1 ms 212 KB Output is correct