Submission #983292

# Submission time Handle Problem Language Result Execution time Memory
983292 2024-05-15T09:59:00 Z vjudge1 Strange Device (APIO19_strange_device) C++17
100 / 100
354 ms 54288 KB
#include <bits/stdc++.h>

using namespace std;

#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define se second
#define fi first
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"


const int N = 5e5 + 9 , mod = 1e9 + 7;
ll a[N] , b[N] , dp[N] , c[N] , d[N];


void solve()
{
    ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
    ll a , b;
    cin>>n;
    cin>>a>>b;
    set<pair<int,int>>st;
    s = a / __gcd(b + 1, a);
    y = 1e18 / __gcd(b + 1, a);
    if(s >= y){
        s = 0;
        for(i = 1; i <= n; i++){
            cin>>x>>y;
            s += (y - x) + 1;
        }
        cout<<s<<"\n";
    return;
    }
    ll ans = 0;
    vector<pair<ll,ll>>v;
    s = s * b;
    for(i = 1; i <= n; i++){
        cin>>l>>r;
        if(l / s == r / s){
            v.pb({l % s , r % s});
        }else {
            if(l / s + 1 == r / s){
                v.pb({l % s , s - 1});
                v.pb({0 , r % s});
            }else {
                cout<<s<<"\n";
                return;
            }
        }
    }
    mx--;
    sort(all(v));
    for(i = 0; i < v.size(); i++){
        if(v[i].first <= mx)
            ans += max(0ll , v[i].se - mx);
        else
            ans += v[i].se - v[i].fi + 1;
        mx = max(mx , v[i].second);
    }
    cout<<ans<<"\n";
}

int main(){
    TL;

    int t = 1;
//   cin>>t;
    while(t--)
     {
        solve();
     }
}
// Author : حسن

Compilation message

strange_device.cpp: In function 'void solve()':
strange_device.cpp:62:18: 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]
   62 |     for(i = 0; i < v.size(); i++){
      |                ~~^~~~~~~~~~
strange_device.cpp:27:12: warning: unused variable 'q' [-Wunused-variable]
   27 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
      |            ^
strange_device.cpp:27:20: warning: unused variable 'j' [-Wunused-variable]
   27 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
      |                    ^
strange_device.cpp:27:46: warning: unused variable 'f' [-Wunused-variable]
   27 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
      |                                              ^
strange_device.cpp:27:50: warning: unused variable 'k' [-Wunused-variable]
   27 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
      |                                                  ^
strange_device.cpp:27:54: warning: unused variable 'm' [-Wunused-variable]
   27 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
      |                                                      ^
strange_device.cpp:27:67: warning: unused variable 'mn' [-Wunused-variable]
   27 |     ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
      |                                                                   ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 3 ms 736 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 33 ms 2520 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 199 ms 17844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 289 ms 18100 KB Output is correct
3 Correct 304 ms 53228 KB Output is correct
4 Correct 291 ms 53972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 289 ms 18100 KB Output is correct
3 Correct 304 ms 53228 KB Output is correct
4 Correct 291 ms 53972 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 308 ms 53344 KB Output is correct
7 Correct 308 ms 53436 KB Output is correct
8 Correct 306 ms 53500 KB Output is correct
9 Correct 337 ms 53332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 289 ms 18100 KB Output is correct
3 Correct 304 ms 53228 KB Output is correct
4 Correct 291 ms 53972 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 42 ms 5828 KB Output is correct
7 Correct 32 ms 5888 KB Output is correct
8 Correct 30 ms 5884 KB Output is correct
9 Correct 30 ms 5832 KB Output is correct
10 Correct 29 ms 5836 KB Output is correct
11 Correct 31 ms 5828 KB Output is correct
12 Correct 29 ms 5832 KB Output is correct
13 Correct 32 ms 5844 KB Output is correct
14 Correct 30 ms 5644 KB Output is correct
15 Correct 33 ms 5836 KB Output is correct
16 Correct 32 ms 5844 KB Output is correct
17 Correct 29 ms 5880 KB Output is correct
18 Correct 307 ms 53320 KB Output is correct
19 Correct 300 ms 53476 KB Output is correct
20 Correct 344 ms 53424 KB Output is correct
21 Correct 33 ms 5760 KB Output is correct
22 Correct 29 ms 5840 KB Output is correct
23 Correct 96 ms 20032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 31 ms 2584 KB Output is correct
3 Correct 32 ms 5836 KB Output is correct
4 Correct 349 ms 53448 KB Output is correct
5 Correct 31 ms 5832 KB Output is correct
6 Correct 32 ms 5832 KB Output is correct
7 Correct 31 ms 5836 KB Output is correct
8 Correct 33 ms 5836 KB Output is correct
9 Correct 31 ms 5828 KB Output is correct
10 Correct 32 ms 5844 KB Output is correct
11 Correct 34 ms 5832 KB Output is correct
12 Correct 28 ms 5836 KB Output is correct
13 Correct 40 ms 5840 KB Output is correct
14 Correct 324 ms 53256 KB Output is correct
15 Correct 32 ms 5832 KB Output is correct
16 Correct 304 ms 54288 KB Output is correct
17 Correct 297 ms 53268 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 3 ms 736 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 33 ms 2520 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 199 ms 17844 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 289 ms 18100 KB Output is correct
31 Correct 304 ms 53228 KB Output is correct
32 Correct 291 ms 53972 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 308 ms 53344 KB Output is correct
35 Correct 308 ms 53436 KB Output is correct
36 Correct 306 ms 53500 KB Output is correct
37 Correct 337 ms 53332 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 42 ms 5828 KB Output is correct
40 Correct 32 ms 5888 KB Output is correct
41 Correct 30 ms 5884 KB Output is correct
42 Correct 30 ms 5832 KB Output is correct
43 Correct 29 ms 5836 KB Output is correct
44 Correct 31 ms 5828 KB Output is correct
45 Correct 29 ms 5832 KB Output is correct
46 Correct 32 ms 5844 KB Output is correct
47 Correct 30 ms 5644 KB Output is correct
48 Correct 33 ms 5836 KB Output is correct
49 Correct 32 ms 5844 KB Output is correct
50 Correct 29 ms 5880 KB Output is correct
51 Correct 307 ms 53320 KB Output is correct
52 Correct 300 ms 53476 KB Output is correct
53 Correct 344 ms 53424 KB Output is correct
54 Correct 33 ms 5760 KB Output is correct
55 Correct 29 ms 5840 KB Output is correct
56 Correct 96 ms 20032 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 31 ms 2584 KB Output is correct
59 Correct 32 ms 5836 KB Output is correct
60 Correct 349 ms 53448 KB Output is correct
61 Correct 31 ms 5832 KB Output is correct
62 Correct 32 ms 5832 KB Output is correct
63 Correct 31 ms 5836 KB Output is correct
64 Correct 33 ms 5836 KB Output is correct
65 Correct 31 ms 5828 KB Output is correct
66 Correct 32 ms 5844 KB Output is correct
67 Correct 34 ms 5832 KB Output is correct
68 Correct 28 ms 5836 KB Output is correct
69 Correct 40 ms 5840 KB Output is correct
70 Correct 324 ms 53256 KB Output is correct
71 Correct 32 ms 5832 KB Output is correct
72 Correct 304 ms 54288 KB Output is correct
73 Correct 297 ms 53268 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 1 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 3 ms 1112 KB Output is correct
80 Correct 342 ms 53164 KB Output is correct
81 Correct 354 ms 54060 KB Output is correct
82 Correct 354 ms 53404 KB Output is correct
83 Correct 334 ms 53168 KB Output is correct
84 Correct 327 ms 53684 KB Output is correct
85 Correct 317 ms 53292 KB Output is correct
86 Correct 104 ms 19636 KB Output is correct
87 Correct 0 ms 344 KB Output is correct