Submission #250229

# Submission time Handle Problem Language Result Execution time Memory
250229 2020-07-17T08:59:38 Z errorgorn Strange Device (APIO19_strange_device) C++14
100 / 100
637 ms 61500 KB
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
typedef pair<long long,long long> ii;

vector<ii> compress_ranges(vector<ii> ranges){
    sort(ranges.begin(),ranges.end());
    vector<ii> r;
    r.push_back(ranges[0]);
    for (int x=1;x<ranges.size();x++){
        if (r.back().second>=ranges[x].first){
           r.back().second=max(r.back().second,ranges[x].second);
        }
        else{
            r.push_back(ranges[x]);
        }
    }
    return r;
}


int n;
long long a,b;
vector<ii> v;
int main(){
    scanf("%d%lld%lld",&n,&a,&b);
    
    long long mod=(a/__gcd(a,b+1)>2000000000000000000/b)?2000000000000000000:a/__gcd(a,b+1)*b;
    
    long long l,r;
    for (int x=0;x<n;x++){
        scanf("%lld%lld",&l,&r);
        if (r-l+1>=mod) v.push_back(ii(0,mod-1));
        else{
            l%=mod,r%=mod;
            if (l<=r) v.push_back(ii(l,r));
            else v.push_back(ii(l,mod-1)),v.push_back(ii(0,r));
        }
    }
    
    v=compress_ranges(v);
    
    long long ans=0;
    for (int x=0;x<v.size();x++){
        ans+=v[x].second-v[x].first+1;
    }
    
    printf("%lld\n",ans);
}

Compilation message

strange_device.cpp: In function 'std::vector<std::pair<long long int, long long int> > compress_ranges(std::vector<std::pair<long long int, long long int> >)':
strange_device.cpp:12:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int x=1;x<ranges.size();x++){
                  ~^~~~~~~~~~~~~~
strange_device.cpp: In function 'int main()':
strange_device.cpp:46:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int x=0;x<v.size();x++){
                  ~^~~~~~~~~
strange_device.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%lld%lld",&n,&a,&b);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld",&l,&r);
         ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 6 ms 1404 KB Output is correct
3 Correct 6 ms 1404 KB Output is correct
4 Correct 0 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 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 6 ms 1404 KB Output is correct
17 Correct 61 ms 8932 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 416 ms 34504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 537 ms 58408 KB Output is correct
3 Correct 518 ms 59656 KB Output is correct
4 Correct 522 ms 59408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 537 ms 58408 KB Output is correct
3 Correct 518 ms 59656 KB Output is correct
4 Correct 522 ms 59408 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 504 ms 59452 KB Output is correct
7 Correct 527 ms 59452 KB Output is correct
8 Correct 546 ms 59556 KB Output is correct
9 Correct 559 ms 59580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 537 ms 58408 KB Output is correct
3 Correct 518 ms 59656 KB Output is correct
4 Correct 522 ms 59408 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 69 ms 7816 KB Output is correct
7 Correct 77 ms 8164 KB Output is correct
8 Correct 52 ms 8264 KB Output is correct
9 Correct 70 ms 8328 KB Output is correct
10 Correct 54 ms 8312 KB Output is correct
11 Correct 61 ms 8292 KB Output is correct
12 Correct 55 ms 8292 KB Output is correct
13 Correct 60 ms 8304 KB Output is correct
14 Correct 54 ms 8216 KB Output is correct
15 Correct 61 ms 8292 KB Output is correct
16 Correct 56 ms 8680 KB Output is correct
17 Correct 58 ms 8676 KB Output is correct
18 Correct 536 ms 59068 KB Output is correct
19 Correct 509 ms 59620 KB Output is correct
20 Correct 589 ms 59496 KB Output is correct
21 Correct 58 ms 8808 KB Output is correct
22 Correct 50 ms 8808 KB Output is correct
23 Correct 196 ms 14288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 57 ms 8804 KB Output is correct
3 Correct 58 ms 8420 KB Output is correct
4 Correct 571 ms 61500 KB Output is correct
5 Correct 57 ms 8420 KB Output is correct
6 Correct 55 ms 8420 KB Output is correct
7 Correct 55 ms 8388 KB Output is correct
8 Correct 59 ms 8424 KB Output is correct
9 Correct 53 ms 8420 KB Output is correct
10 Correct 56 ms 8420 KB Output is correct
11 Correct 71 ms 8424 KB Output is correct
12 Correct 57 ms 8420 KB Output is correct
13 Correct 78 ms 8420 KB Output is correct
14 Correct 637 ms 61500 KB Output is correct
15 Correct 60 ms 9064 KB Output is correct
16 Correct 556 ms 59676 KB Output is correct
17 Correct 528 ms 59736 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 6 ms 1404 KB Output is correct
3 Correct 6 ms 1404 KB Output is correct
4 Correct 0 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 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 6 ms 1404 KB Output is correct
17 Correct 61 ms 8932 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
22 Correct 0 ms 256 KB Output is correct
23 Correct 0 ms 256 KB Output is correct
24 Correct 0 ms 256 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 416 ms 34504 KB Output is correct
29 Correct 0 ms 256 KB Output is correct
30 Correct 537 ms 58408 KB Output is correct
31 Correct 518 ms 59656 KB Output is correct
32 Correct 522 ms 59408 KB Output is correct
33 Correct 0 ms 256 KB Output is correct
34 Correct 504 ms 59452 KB Output is correct
35 Correct 527 ms 59452 KB Output is correct
36 Correct 546 ms 59556 KB Output is correct
37 Correct 559 ms 59580 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 69 ms 7816 KB Output is correct
40 Correct 77 ms 8164 KB Output is correct
41 Correct 52 ms 8264 KB Output is correct
42 Correct 70 ms 8328 KB Output is correct
43 Correct 54 ms 8312 KB Output is correct
44 Correct 61 ms 8292 KB Output is correct
45 Correct 55 ms 8292 KB Output is correct
46 Correct 60 ms 8304 KB Output is correct
47 Correct 54 ms 8216 KB Output is correct
48 Correct 61 ms 8292 KB Output is correct
49 Correct 56 ms 8680 KB Output is correct
50 Correct 58 ms 8676 KB Output is correct
51 Correct 536 ms 59068 KB Output is correct
52 Correct 509 ms 59620 KB Output is correct
53 Correct 589 ms 59496 KB Output is correct
54 Correct 58 ms 8808 KB Output is correct
55 Correct 50 ms 8808 KB Output is correct
56 Correct 196 ms 14288 KB Output is correct
57 Correct 0 ms 256 KB Output is correct
58 Correct 57 ms 8804 KB Output is correct
59 Correct 58 ms 8420 KB Output is correct
60 Correct 571 ms 61500 KB Output is correct
61 Correct 57 ms 8420 KB Output is correct
62 Correct 55 ms 8420 KB Output is correct
63 Correct 55 ms 8388 KB Output is correct
64 Correct 59 ms 8424 KB Output is correct
65 Correct 53 ms 8420 KB Output is correct
66 Correct 56 ms 8420 KB Output is correct
67 Correct 71 ms 8424 KB Output is correct
68 Correct 57 ms 8420 KB Output is correct
69 Correct 78 ms 8420 KB Output is correct
70 Correct 637 ms 61500 KB Output is correct
71 Correct 60 ms 9064 KB Output is correct
72 Correct 556 ms 59676 KB Output is correct
73 Correct 528 ms 59736 KB Output is correct
74 Correct 0 ms 256 KB Output is correct
75 Correct 0 ms 256 KB Output is correct
76 Correct 0 ms 256 KB Output is correct
77 Correct 0 ms 256 KB Output is correct
78 Correct 0 ms 256 KB Output is correct
79 Correct 6 ms 1404 KB Output is correct
80 Correct 572 ms 58292 KB Output is correct
81 Correct 584 ms 58300 KB Output is correct
82 Correct 541 ms 58300 KB Output is correct
83 Correct 545 ms 58236 KB Output is correct
84 Correct 552 ms 58172 KB Output is correct
85 Correct 556 ms 58280 KB Output is correct
86 Correct 213 ms 13044 KB Output is correct
87 Correct 1 ms 384 KB Output is correct