Submission #332969

# Submission time Handle Problem Language Result Execution time Memory
332969 2020-12-04T05:17:30 Z leinad2 Strange Device (APIO19_strange_device) C++14
100 / 100
772 ms 149680 KB
#include<bits/stdc++.h>
#define int __int128
using namespace std;
int n, i, j, k, a, b, x, A[1000010][2], ans;
int gcd(int a, int b)
{
    if(b==0)return a;
    return gcd(b, a%b);
}
vector<pair<int, int> >v, V;
main()
{
    for(scanf("%lld %lld %lld", &n, &a, &b);i++<n;)scanf("%lld %lld", &A[i][0], &A[i][1]);
    x=(a*b)/(gcd(a, b+1));
    for(i=0;i++<n;)
    {
        if(A[i][1]-A[i][0]>=x-1)
        {
            v.push_back({0, x-1});
        }
        else
        {
            if(A[i][0]%x<=A[i][1]%x)
            {
                v.push_back({A[i][0]%x, A[i][1]%x});
            }
            else
            {
                v.push_back({0, A[i][1]%x});
                v.push_back({A[i][0]%x, x-1});
            }
        }
    }
    sort(v.begin(), v.end());
    for(i=0;i<v.size();i++)
    {
        if(V.size()==0)V.push_back(v[i]);
        else
        {
            if(V.back().second>=v[i].first)
            {
                if(V.back().second<v[i].second)
                {
                    V.back().second=v[i].second;
                }
            }
            else
            {
                V.push_back(v[i]);
            }
        }
    }
    for(i=0;i<V.size();i++)
    {
        ans+=(V[i].second-V[i].first+1);
    }
    printf("%lld", ans);
}

Compilation message

strange_device.cpp:11:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main()
      |      ^
strange_device.cpp: In function 'int main()':
strange_device.cpp:13:19: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type '__int128*' [-Wformat=]
   13 |     for(scanf("%lld %lld %lld", &n, &a, &b);i++<n;)scanf("%lld %lld", &A[i][0], &A[i][1]);
      |                ~~~^             ~~
      |                   |             |
      |                   |             __int128*
      |                   long long int*
strange_device.cpp:13:24: warning: format '%lld' expects argument of type 'long long int*', but argument 3 has type '__int128*' [-Wformat=]
   13 |     for(scanf("%lld %lld %lld", &n, &a, &b);i++<n;)scanf("%lld %lld", &A[i][0], &A[i][1]);
      |                     ~~~^            ~~
      |                        |            |
      |                        |            __int128*
      |                        long long int*
strange_device.cpp:13:29: warning: format '%lld' expects argument of type 'long long int*', but argument 4 has type '__int128*' [-Wformat=]
   13 |     for(scanf("%lld %lld %lld", &n, &a, &b);i++<n;)scanf("%lld %lld", &A[i][0], &A[i][1]);
      |                          ~~~^           ~~
      |                             |           |
      |                             |           __int128*
      |                             long long int*
strange_device.cpp:13:62: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type '__int128*' [-Wformat=]
   13 |     for(scanf("%lld %lld %lld", &n, &a, &b);i++<n;)scanf("%lld %lld", &A[i][0], &A[i][1]);
      |                                                           ~~~^        ~~~~~~~~
      |                                                              |        |
      |                                                              |        __int128*
      |                                                              long long int*
strange_device.cpp:13:67: warning: format '%lld' expects argument of type 'long long int*', but argument 3 has type '__int128*' [-Wformat=]
   13 |     for(scanf("%lld %lld %lld", &n, &a, &b);i++<n;)scanf("%lld %lld", &A[i][0], &A[i][1]);
      |                                                                ~~~^             ~~~~~~~~
      |                                                                   |             |
      |                                                                   |             __int128*
      |                                                                   long long int*
strange_device.cpp:57:16: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type '__int128' [-Wformat=]
   57 |     printf("%lld", ans);
      |             ~~~^   ~~~
      |                |   |
      |                |   __int128
      |                long long int
strange_device.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 |     for(scanf("%lld %lld %lld", &n, &a, &b);i++<n;)scanf("%lld %lld", &A[i][0], &A[i][1]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:13:57: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 |     for(scanf("%lld %lld %lld", &n, &a, &b);i++<n;)scanf("%lld %lld", &A[i][0], &A[i][1]);
      |                                                    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 6 ms 1784 KB Output is correct
3 Correct 7 ms 1764 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 376 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 1764 KB Output is correct
17 Correct 66 ms 12760 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 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 368 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 461 ms 77276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 631 ms 130576 KB Output is correct
3 Correct 613 ms 149520 KB Output is correct
4 Correct 620 ms 149520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 631 ms 130576 KB Output is correct
3 Correct 613 ms 149520 KB Output is correct
4 Correct 620 ms 149520 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 621 ms 149680 KB Output is correct
7 Correct 625 ms 149648 KB Output is correct
8 Correct 621 ms 149368 KB Output is correct
9 Correct 709 ms 149432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 631 ms 130576 KB Output is correct
3 Correct 613 ms 149520 KB Output is correct
4 Correct 620 ms 149520 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 62 ms 16472 KB Output is correct
7 Correct 70 ms 16472 KB Output is correct
8 Correct 66 ms 16472 KB Output is correct
9 Correct 66 ms 16600 KB Output is correct
10 Correct 62 ms 16472 KB Output is correct
11 Correct 63 ms 16472 KB Output is correct
12 Correct 62 ms 16472 KB Output is correct
13 Correct 66 ms 16472 KB Output is correct
14 Correct 61 ms 16472 KB Output is correct
15 Correct 66 ms 16472 KB Output is correct
16 Correct 66 ms 16472 KB Output is correct
17 Correct 64 ms 16472 KB Output is correct
18 Correct 659 ms 149572 KB Output is correct
19 Correct 629 ms 149332 KB Output is correct
20 Correct 732 ms 149440 KB Output is correct
21 Correct 66 ms 16472 KB Output is correct
22 Correct 62 ms 16472 KB Output is correct
23 Correct 184 ms 40148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 64 ms 12760 KB Output is correct
3 Correct 67 ms 12760 KB Output is correct
4 Correct 733 ms 130460 KB Output is correct
5 Correct 66 ms 16472 KB Output is correct
6 Correct 66 ms 16472 KB Output is correct
7 Correct 69 ms 16472 KB Output is correct
8 Correct 69 ms 16472 KB Output is correct
9 Correct 65 ms 16472 KB Output is correct
10 Correct 66 ms 16472 KB Output is correct
11 Correct 67 ms 16472 KB Output is correct
12 Correct 59 ms 16472 KB Output is correct
13 Correct 68 ms 16472 KB Output is correct
14 Correct 732 ms 149168 KB Output is correct
15 Correct 65 ms 16472 KB Output is correct
16 Correct 631 ms 149212 KB Output is correct
17 Correct 618 ms 149084 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 6 ms 1784 KB Output is correct
3 Correct 7 ms 1764 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 376 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 1764 KB Output is correct
17 Correct 66 ms 12760 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 0 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 368 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 461 ms 77276 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 631 ms 130576 KB Output is correct
31 Correct 613 ms 149520 KB Output is correct
32 Correct 620 ms 149520 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 621 ms 149680 KB Output is correct
35 Correct 625 ms 149648 KB Output is correct
36 Correct 621 ms 149368 KB Output is correct
37 Correct 709 ms 149432 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 62 ms 16472 KB Output is correct
40 Correct 70 ms 16472 KB Output is correct
41 Correct 66 ms 16472 KB Output is correct
42 Correct 66 ms 16600 KB Output is correct
43 Correct 62 ms 16472 KB Output is correct
44 Correct 63 ms 16472 KB Output is correct
45 Correct 62 ms 16472 KB Output is correct
46 Correct 66 ms 16472 KB Output is correct
47 Correct 61 ms 16472 KB Output is correct
48 Correct 66 ms 16472 KB Output is correct
49 Correct 66 ms 16472 KB Output is correct
50 Correct 64 ms 16472 KB Output is correct
51 Correct 659 ms 149572 KB Output is correct
52 Correct 629 ms 149332 KB Output is correct
53 Correct 732 ms 149440 KB Output is correct
54 Correct 66 ms 16472 KB Output is correct
55 Correct 62 ms 16472 KB Output is correct
56 Correct 184 ms 40148 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 64 ms 12760 KB Output is correct
59 Correct 67 ms 12760 KB Output is correct
60 Correct 733 ms 130460 KB Output is correct
61 Correct 66 ms 16472 KB Output is correct
62 Correct 66 ms 16472 KB Output is correct
63 Correct 69 ms 16472 KB Output is correct
64 Correct 69 ms 16472 KB Output is correct
65 Correct 65 ms 16472 KB Output is correct
66 Correct 66 ms 16472 KB Output is correct
67 Correct 67 ms 16472 KB Output is correct
68 Correct 59 ms 16472 KB Output is correct
69 Correct 68 ms 16472 KB Output is correct
70 Correct 732 ms 149168 KB Output is correct
71 Correct 65 ms 16472 KB Output is correct
72 Correct 631 ms 149212 KB Output is correct
73 Correct 618 ms 149084 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 2148 KB Output is correct
80 Correct 753 ms 149248 KB Output is correct
81 Correct 772 ms 148684 KB Output is correct
82 Correct 726 ms 148396 KB Output is correct
83 Correct 733 ms 149432 KB Output is correct
84 Correct 719 ms 149212 KB Output is correct
85 Correct 718 ms 148992 KB Output is correct
86 Correct 183 ms 40116 KB Output is correct
87 Correct 1 ms 364 KB Output is correct