CSES - Aalto Competitive Programming 2024 - wk4 - Mon - Results
Submission details
Task:Moon landing
Sender:AleksandrPolitov
Submission time:2024-09-23 16:38:40 +0300
Language:C++ (C++20)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.01 sdetails
#10ACCEPTED0.00 sdetails
#11ACCEPTED0.00 sdetails
#12ACCEPTED0.00 sdetails
#13ACCEPTED0.00 sdetails
#14ACCEPTED0.00 sdetails
#15ACCEPTED0.00 sdetails
#16ACCEPTED0.00 sdetails
#17ACCEPTED0.00 sdetails
#18ACCEPTED0.00 sdetails
#19ACCEPTED0.00 sdetails
#20ACCEPTED0.00 sdetails
#21ACCEPTED0.00 sdetails
#22ACCEPTED0.00 sdetails
#23ACCEPTED0.00 sdetails
#24ACCEPTED0.00 sdetails
#25ACCEPTED0.00 sdetails
#26ACCEPTED0.00 sdetails
#27ACCEPTED0.00 sdetails
#28ACCEPTED0.00 sdetails
#29ACCEPTED0.00 sdetails
#30ACCEPTED0.00 sdetails
#31ACCEPTED0.00 sdetails
#32ACCEPTED0.00 sdetails
#33ACCEPTED0.00 sdetails
#34ACCEPTED0.00 sdetails
#35ACCEPTED0.00 sdetails
#36ACCEPTED0.00 sdetails
#37ACCEPTED0.00 sdetails
#38ACCEPTED0.00 sdetails
#39ACCEPTED0.00 sdetails
#40ACCEPTED0.00 sdetails
#41ACCEPTED0.00 sdetails
#42ACCEPTED0.00 sdetails
#43ACCEPTED0.00 sdetails
#44ACCEPTED0.00 sdetails
#45ACCEPTED0.00 sdetails
#46ACCEPTED0.00 sdetails
#47ACCEPTED0.01 sdetails
#48ACCEPTED0.00 sdetails
#49ACCEPTED0.00 sdetails
#50ACCEPTED0.00 sdetails
#51ACCEPTED0.00 sdetails
#52ACCEPTED0.00 sdetails
#53ACCEPTED0.01 sdetails
#54ACCEPTED0.01 sdetails
#55ACCEPTED0.01 sdetails
#56ACCEPTED0.05 sdetails
#57ACCEPTED0.05 sdetails
#58ACCEPTED0.05 sdetails
#59ACCEPTED0.05 sdetails
#60ACCEPTED0.05 sdetails
#61ACCEPTED0.05 sdetails
#62ACCEPTED0.05 sdetails
#63ACCEPTED0.05 sdetails
#64ACCEPTED0.03 sdetails

Compiler report

input/code.cpp: In function 'int solve()':
input/code.cpp:165:13: warning: unused variable 'mn' [-Wunused-variable]
  165 |         int mn=minq.query(i, lo), mx=maxq.query(i, lo);
      |             ^~
input/code.cpp:165:35: warning: unused variable 'mx' [-Wunused-variable]
  165 |         int mn=minq.query(i, lo), mx=maxq.query(i, lo);
      |                                   ^~

Code

#ifdef ONPC
    #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

#define char unsigned char
#define rep(i, a, b) for(int i=a; i< (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back

#define LSOne(S) ((S) & -(S))

using namespace std;
// mt19937 rnd(239);
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

typedef long long C;
typedef complex<C> P;
#define X real()
#define Y imag()

template<class T>
istream& operator>> (istream& is, complex<T>& p) {
    T value;
    is >> value;
    p.real(value);
    is >> value;
    p.imag(value);
    return is;
}

typedef long long ll;
typedef long double ld;

using pi = pair<ll, ll>;
using vi = vector<ll>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef DEBUG
#define dbg(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
#define dbg(x...)
#endif

template<typename S, typename T = S> void chmin(S &s, T t) {s = s < t ? s : t;}
template<typename S, typename T = S> void chmax(S &s, T t) {s = s > t ? s : t;}

const int INF = 1e9; // 10^9 = 1B is < 2^31-1
const ll LLINF = 4e18; // 4*10^18 is < 2^63-1
const double EPS = 1e-9;
const ll MOD = 1e9+7;

struct rmaxq {
    vector<vector<int>> st;
    int n;

    rmaxq() {}
    rmaxq(vector<int> &v) {
        n = v.size();
        st = vector<vector<int>>(18, vector<int>(n));
        for (int j = 0; j < n; ++j) st[0][j] = v[j];
        for (int i = 0; (1 << i) <= n; ++i) {
            for (int j = 0; j + (1 << (i+1)) <= n; ++j) {
                st[i+1][j] = max(st[i][j], st[i][j + (1 << i)]);
            }
        }
    }
    
    int query(int l, int r) {
        if (l > r) return -1;
        int j = l == r ? 0 : 31 - __builtin_clz(r - l);
        return max(st[j][l], st[j][r - (1 << j) + 1]);
    }
};

struct rminq {
    vector<vector<int>> st;
    int n;

    rminq() {}
    rminq(vector<int> &v) {
        n = v.size();
        st = vector<vector<int>>(18, vector<int>(n));
        for (int j = 0; j < n; ++j) st[0][j] = v[j];
        for (int i = 0; (1 << i) <= n; ++i) {
            for (int j = 0; j + (1 << (i+1)) <= n; ++j) {
                st[i+1][j] = min(st[i][j], st[i][j + (1 << i)]);
            }
        }
    }
    
    int query(int l, int r) {
        if (l > r) return -1;
        int j = l == r ? 0 : 31 - __builtin_clz(r - l);
        return min(st[j][l], st[j][r - (1 << j) + 1]);
    }
};


int solve() {
    int n, x; std::cin >> n >> x;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        std::cin >> v[i];
    }

    rminq minq(v);
    rmaxq maxq(v);

    //std::cout << minq.query(0, 2) << std::endl;
    
    pair<int,int> res={1, 1};

    for (int i = 0; i < n; i++) {
        int lo=i, hi=n-1;
        //std::cout << lo << " " << hi << std::endl;
        while(lo<hi) {
            int mid=(lo+hi+1)/2;
            int mn=minq.query(i, mid), mx=maxq.query(i, mid);
            if(mx-mn<=x) {
                lo=mid;
            } else {
                hi=mid-1;
            }
        }

        int mn=minq.query(i, lo), mx=maxq.query(i, lo);
        //std::cout << i << ": " << lo  << std::endl;
        //std::cout << mn << " " << mx << std::endl;
        
        if(lo-i+1>=res.se) {
            res.se=lo-i+1;
            res.fi=i+1;
        }
    }

    std::cout << res.fi << " " << res.se << std::endl;

    //__print(res); std::cout  << std::endl;

    
    return 0;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int TET = 1;
    //cin >> TET;
    for (int i = 1; i <= TET; i++) {
        #ifdef ONPC
            cout << "TEST CASE#" << i << endl;
        #endif
        
        if (solve()) {
            break;
        }

        #ifdef ONPC
            cout << "__________________________" << endl;
        #endif
    }
    #ifdef ONPC
        cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
    #endif
}

Test details

Test 1

Verdict: ACCEPTED

input
1 1

correct output
1 1

user output
1 1

Test 2

Verdict: ACCEPTED

input
2 10
0 2 

correct output
1 2

user output
1 2

Test 3

Verdict: ACCEPTED

input
2 4
7 7 

correct output
1 2

user output
1 2

Test 4

Verdict: ACCEPTED

input
3 8
5 10 5 

correct output
1 3

user output
1 3

Test 5

Verdict: ACCEPTED

input
3 10
3 6 7 

correct output
1 3

user output
1 3

Test 6

Verdict: ACCEPTED

input
3 0
6 9 5 

correct output
1 1

user output
3 1

Test 7

Verdict: ACCEPTED

input
4 3
8 5 1 10 

correct output
1 2

user output
1 2

Test 8

Verdict: ACCEPTED

input
4 9
6 3 8 7 

correct output
1 4

user output
1 4

Test 9

Verdict: ACCEPTED

input
4 10
1 9 6 8 

correct output
1 4

user output
1 4

Test 10

Verdict: ACCEPTED

input
5 6
6 7 9 6 9 

correct output
1 5

user output
1 5

Test 11

Verdict: ACCEPTED

input
5 4
10 7 10 0 1 

correct output
1 3

user output
1 3

Test 12

Verdict: ACCEPTED

input
5 4
2 0 10 6 10 

correct output
3 3

user output
3 3

Test 13

Verdict: ACCEPTED

input
5 6
0 7 9 3 1 

correct output
2 3

user output
2 3

Test 14

Verdict: ACCEPTED

input
5 10
9 6 1 10 9 

correct output
1 5

user output
1 5

Test 15

Verdict: ACCEPTED

input
5 2
0 9 9 2 4 

correct output
2 2

user output
4 2

Test 16

Verdict: ACCEPTED

input
5 9
10 3 2 9 0 

correct output
1 4

user output
2 4

Test 17

Verdict: ACCEPTED

input
5 0
2 8 3 4 10 

correct output
1 1

user output
5 1

Test 18

Verdict: ACCEPTED

input
5 9
0 10 2 9 4 

correct output
2 4

user output
2 4

Test 19

Verdict: ACCEPTED

input
5 0
4 5 5 5 0 

correct output
2 3

user output
2 3

Test 20

Verdict: ACCEPTED

input
10 6
6 7 9 6 9 5 9 4 6 7 

correct output
1 10

user output
1 10

Test 21

Verdict: ACCEPTED

input
10 4
10 7 10 0 1 3 10 1 2 1 

correct output
1 3

user output
8 3

Test 22

Verdict: ACCEPTED

input
10 4
2 0 10 6 10 4 5 4 3 3 

correct output
6 5

user output
6 5

Test 23

Verdict: ACCEPTED

input
10 6
0 7 9 3 1 5 6 9 4 9 

correct output
6 5

user output
6 5

Test 24

Verdict: ACCEPTED

input
10 10
9 6 1 10 9 7 6 7 6 2 

correct output
1 10

user output
1 10

Test 25

Verdict: ACCEPTED

input
10 2
0 9 9 2 4 10 10 5 0 6 

correct output
2 2

user output
6 2

Test 26

Verdict: ACCEPTED

input
10 9
10 3 2 9 0 0 4 1 10 6 

correct output
2 7

user output
2 7

Test 27

Verdict: ACCEPTED

input
10 0
2 8 3 4 10 7 5 10 3 5 

correct output
1 1

user output
10 1

Test 28

Verdict: ACCEPTED

input
10 9
0 10 2 9 4 5 8 2 4 0 

correct output
2 8

user output
3 8

Test 29

Verdict: ACCEPTED

input
10 0
4 5 5 5 0 1 3 1 0 2 

correct output
2 3

user output
2 3

Test 30

Verdict: ACCEPTED

input
100 589284011
636562059 767928733 906523440 ...

correct output
1 12

user output
1 12

Test 31

Verdict: ACCEPTED

input
100 447773961
773442531 122815 137572578 324...

correct output
2 10

user output
2 10

Test 32

Verdict: ACCEPTED

input
100 468145962
198730371 27838075 590195589 4...

correct output
60 11

user output
60 11

Test 33

Verdict: ACCEPTED

input
100 591414746
75940262 760367934 901888416 3...

correct output
34 14

user output
34 14

Test 34

Verdict: ACCEPTED

input
100 967034923
587586157 185430193 918715994 ...

correct output
37 64

user output
37 64

Test 35

Verdict: ACCEPTED

input
100 238363352
59249203 934941691 892631471 2...

correct output
34 5

user output
34 5

Test 36

Verdict: ACCEPTED

input
100 958701282
356460600 224848373 881788058 ...

correct output
1 100

user output
1 100

Test 37

Verdict: ACCEPTED

input
100 81935403
244103473 837431430 342493821 ...

correct output
21 3

user output
96 3

Test 38

Verdict: ACCEPTED

input
100 937837680
11934037 257096282 933290529 4...

correct output
29 54

user output
29 54

Test 39

Verdict: ACCEPTED

input
100 11139167
391337047 538883743 535937149 ...

correct output
2 3

user output
2 3

Test 40

Verdict: ACCEPTED

input
200 589284011
636562059 767928733 906523440 ...

correct output
99 15

user output
99 15

Test 41

Verdict: ACCEPTED

input
200 447773961
773442531 122815 137572578 324...

correct output
2 10

user output
2 10

Test 42

Verdict: ACCEPTED

input
200 468145962
198730371 27838075 590195589 4...

correct output
60 11

user output
60 11

Test 43

Verdict: ACCEPTED

input
200 591414746
75940262 760367934 901888416 3...

correct output
104 24

user output
104 24

Test 44

Verdict: ACCEPTED

input
200 967034923
587586157 185430193 918715994 ...

correct output
37 111

user output
37 111

Test 45

Verdict: ACCEPTED

input
200 238363352
59249203 934941691 892631471 2...

correct output
34 5

user output
34 5

Test 46

Verdict: ACCEPTED

input
200 958701282
356460600 224848373 881788058 ...

correct output
1 138

user output
1 138

Test 47

Verdict: ACCEPTED

input
200 81935403
244103473 837431430 342493821 ...

correct output
21 3

user output
198 3

Test 48

Verdict: ACCEPTED

input
200 937837680
11934037 257096282 933290529 4...

correct output
84 66

user output
84 66

Test 49

Verdict: ACCEPTED

input
200 11139167
391337047 538883743 535937149 ...

correct output
2 3

user output
2 3

Test 50

Verdict: ACCEPTED

input
1000 589284011
636562059 767928733 906523440 ...

correct output
99 15

user output
99 15

Test 51

Verdict: ACCEPTED

input
1000 447773961
773442531 122815 137572578 324...

correct output
2 10

user output
712 10

Test 52

Verdict: ACCEPTED

input
1000 468145962
198730371 27838075 590195589 4...

correct output
60 11

user output
744 11

Test 53

Verdict: ACCEPTED

input
10000 591414746
75940262 760367934 901888416 3...

correct output
104 24

user output
104 24

Test 54

Verdict: ACCEPTED

input
10000 967034923
587586157 185430193 918715994 ...

correct output
3660 279

user output
3660 279

Test 55

Verdict: ACCEPTED

input
10000 238363352
59249203 934941691 892631471 2...

correct output
325 9

user output
325 9

Test 56

Verdict: ACCEPTED

input
100000 958701282
356460600 224848373 881788058 ...

correct output
66493 302

user output
66493 302

Test 57

Verdict: ACCEPTED

input
100000 81935403
244103473 837431430 342493821 ...

correct output
28066 7

user output
28066 7

Test 58

Verdict: ACCEPTED

input
100000 937837680
11934037 257096282 933290529 4...

correct output
91851 177

user output
91851 177

Test 59

Verdict: ACCEPTED

input
100000 11139167
391337047 538883743 535937149 ...

correct output
84138 4

user output
84138 4

Test 60

Verdict: ACCEPTED

input
100000 239756970
350744379 561742366 59793553 5...

correct output
94284 12

user output
94284 12

Test 61

Verdict: ACCEPTED

input
100000 316394139
195182396 569713187 906489185 ...

correct output
12844 13

user output
12844 13

Test 62

Verdict: ACCEPTED

input
100000 698334026
81615940 542726430 464528081 9...

correct output
28811 40

user output
28811 40

Test 63

Verdict: ACCEPTED

input
100000 104725911
462211739 817385661 443179352 ...

correct output
46788 9

user output
46788 9

Test 64

Verdict: ACCEPTED

input
100000 20
13 15 11 10 13 16 17 18 15 18 ...

correct output
1 100000

user output
1 100000