Submission #564434

# Submission time Handle Problem Language Result Execution time Memory
564434 2022-05-19T08:16:31 Z shahriarkhan Strange Device (APIO19_strange_device) C++14
100 / 100
530 ms 40928 KB
#include<bits/stdc++.h>
using namespace std ;

int main()
{
    long long n , A , B ;
    scanf("%lld%lld%lld",&n,&A,&B) ;
    long long l[n+2] , r[n+2] , diff = (A/__gcd(A,B+1))*B , ans = 0 , cur_l = 0 , cur_r = -1 ;
    vector<pair<long long,long long> > v ;
    for(int i = 1 ; i <= n ; ++i)
    {
        scanf("%lld%lld",&l[i],&r[i]) ;
        if((r[i]-l[i]+1)/diff) v.push_back({0,diff-1}) ;
        else
        {
            l[i] %= diff , r[i] %= diff ;
            if(r[i]>=l[i]) v.push_back({l[i],r[i]}) ;
            else v.push_back({l[i],diff-1}) , v.push_back({0,r[i]}) ;
        }
    }
    sort(v.begin(),v.end()) ;
    for(pair<long long , long long> p : v)
    {
        if(p.first>cur_r)
        {
            ans += (cur_r-cur_l+1) ;
            cur_l = p.first , cur_r = p.second ;
        }
        else
        {
            cur_r = max(cur_r,p.second) ;
        }
    }
    ans += (cur_r-cur_l+1) ;
    printf("%lld\n",ans) ;
    return 0 ;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:7:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |     scanf("%lld%lld%lld",&n,&A,&B) ;
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         scanf("%lld%lld",&l[i],&r[i]) ;
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 8 ms 1188 KB Output is correct
3 Correct 6 ms 1196 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 260 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 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 1108 KB Output is correct
17 Correct 49 ms 7148 KB Output is correct
18 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 1 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 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 370 ms 37068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 451 ms 40928 KB Output is correct
3 Correct 432 ms 35904 KB Output is correct
4 Correct 454 ms 33652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 451 ms 40928 KB Output is correct
3 Correct 432 ms 35904 KB Output is correct
4 Correct 454 ms 33652 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 424 ms 33736 KB Output is correct
7 Correct 469 ms 34228 KB Output is correct
8 Correct 446 ms 34096 KB Output is correct
9 Correct 463 ms 32528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 451 ms 40928 KB Output is correct
3 Correct 432 ms 35904 KB Output is correct
4 Correct 454 ms 33652 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 45 ms 7228 KB Output is correct
7 Correct 47 ms 7156 KB Output is correct
8 Correct 44 ms 7236 KB Output is correct
9 Correct 47 ms 7224 KB Output is correct
10 Correct 48 ms 7252 KB Output is correct
11 Correct 45 ms 7232 KB Output is correct
12 Correct 45 ms 7164 KB Output is correct
13 Correct 48 ms 7212 KB Output is correct
14 Correct 60 ms 7224 KB Output is correct
15 Correct 50 ms 7156 KB Output is correct
16 Correct 52 ms 7132 KB Output is correct
17 Correct 45 ms 7248 KB Output is correct
18 Correct 451 ms 33152 KB Output is correct
19 Correct 458 ms 39632 KB Output is correct
20 Correct 530 ms 40164 KB Output is correct
21 Correct 60 ms 7148 KB Output is correct
22 Correct 44 ms 7188 KB Output is correct
23 Correct 145 ms 23216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 65 ms 7128 KB Output is correct
3 Correct 49 ms 7140 KB Output is correct
4 Correct 479 ms 33072 KB Output is correct
5 Correct 49 ms 7236 KB Output is correct
6 Correct 53 ms 7164 KB Output is correct
7 Correct 45 ms 7184 KB Output is correct
8 Correct 48 ms 7268 KB Output is correct
9 Correct 45 ms 7224 KB Output is correct
10 Correct 48 ms 7172 KB Output is correct
11 Correct 51 ms 7240 KB Output is correct
12 Correct 47 ms 7148 KB Output is correct
13 Correct 46 ms 7136 KB Output is correct
14 Correct 496 ms 39156 KB Output is correct
15 Correct 50 ms 7228 KB Output is correct
16 Correct 442 ms 39860 KB Output is correct
17 Correct 448 ms 39148 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 8 ms 1188 KB Output is correct
3 Correct 6 ms 1196 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 260 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 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 1108 KB Output is correct
17 Correct 49 ms 7148 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 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 1 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 370 ms 37068 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 451 ms 40928 KB Output is correct
31 Correct 432 ms 35904 KB Output is correct
32 Correct 454 ms 33652 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 424 ms 33736 KB Output is correct
35 Correct 469 ms 34228 KB Output is correct
36 Correct 446 ms 34096 KB Output is correct
37 Correct 463 ms 32528 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 45 ms 7228 KB Output is correct
40 Correct 47 ms 7156 KB Output is correct
41 Correct 44 ms 7236 KB Output is correct
42 Correct 47 ms 7224 KB Output is correct
43 Correct 48 ms 7252 KB Output is correct
44 Correct 45 ms 7232 KB Output is correct
45 Correct 45 ms 7164 KB Output is correct
46 Correct 48 ms 7212 KB Output is correct
47 Correct 60 ms 7224 KB Output is correct
48 Correct 50 ms 7156 KB Output is correct
49 Correct 52 ms 7132 KB Output is correct
50 Correct 45 ms 7248 KB Output is correct
51 Correct 451 ms 33152 KB Output is correct
52 Correct 458 ms 39632 KB Output is correct
53 Correct 530 ms 40164 KB Output is correct
54 Correct 60 ms 7148 KB Output is correct
55 Correct 44 ms 7188 KB Output is correct
56 Correct 145 ms 23216 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 65 ms 7128 KB Output is correct
59 Correct 49 ms 7140 KB Output is correct
60 Correct 479 ms 33072 KB Output is correct
61 Correct 49 ms 7236 KB Output is correct
62 Correct 53 ms 7164 KB Output is correct
63 Correct 45 ms 7184 KB Output is correct
64 Correct 48 ms 7268 KB Output is correct
65 Correct 45 ms 7224 KB Output is correct
66 Correct 48 ms 7172 KB Output is correct
67 Correct 51 ms 7240 KB Output is correct
68 Correct 47 ms 7148 KB Output is correct
69 Correct 46 ms 7136 KB Output is correct
70 Correct 496 ms 39156 KB Output is correct
71 Correct 50 ms 7228 KB Output is correct
72 Correct 442 ms 39860 KB Output is correct
73 Correct 448 ms 39148 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 1 ms 300 KB Output is correct
79 Correct 5 ms 1184 KB Output is correct
80 Correct 506 ms 33660 KB Output is correct
81 Correct 515 ms 33488 KB Output is correct
82 Correct 482 ms 33592 KB Output is correct
83 Correct 476 ms 33168 KB Output is correct
84 Correct 452 ms 33156 KB Output is correct
85 Correct 457 ms 33188 KB Output is correct
86 Correct 151 ms 23540 KB Output is correct
87 Correct 0 ms 300 KB Output is correct