Submission #967145

# Submission time Handle Problem Language Result Execution time Memory
967145 2024-04-21T10:33:47 Z Nhoksocqt1 Gap (APIO16_gap) C++17
Compilation error
0 ms 0 KB
#ifndef Nhoksocqt1
    #include "gap.h"
#endif // Nhoksocqt1
#include<bits/stdc++.h>
using namespace std;

#define inf 0x3f3f3f3f
#define sz(x) int((x).size())
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;

template<class X, class Y>
	inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);}
template<class X, class Y>
	inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

const int MAXN = 100005;

ll a[MAXN];
int nArr;

#ifdef Nhoksocqt1

ll _A[MAXN], M;

void MinMax(ll s, ll t, ll &a, ll &b) {
    int l(1), r(nArr), optL(nArr + 1), optR(-1);
    while(l <= r) {
        int mid = (l + r) >> 1;
        if(_A[mid] >= s) {
            optL = mid;
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }

    l = 1, r = nArr;
    while(l <= r) {
        int mid = (l + r) >> 1;
        if(_A[mid] <= t) {
            optR = mid;
            l = mid + 1;
        } else {
            r = mid - 1;
        }
    }

    M += optR - optL + 2;
    if(optL > optR) {
        a = b = -1;
    } else {
        a = _A[optL], b = _A[optR];
    }
}

#endif // Nhoksocqt1

ll findGap(int T, int N) {
    nArr = N;
    MinMax(0, ll(1e18), a[1], a[nArr]);

    if(T == 1) {
        for (int i = 2; i <= (nArr + 1) / 2; ++i)
            MinMax(a[i - 1] + 1, a[nArr - i + 2] - 1, a[i], a[nArr - i + 1]);

        ll res(0);
        for (int i = 1; i < nArr; ++i)
            res = max(res, a[i + 1] - a[i]);

        return res;
    }

    ll answer = 1, lst = a[1];
    bool check = 1;
    while(check) {
        check = 0;
        ll pos(lst);
        for (int i = 0; i < 60; ++i) {
            ll s, t;
            MinMax(pos + 1, pos + (1LL << i), s, t);
            if(s != -1) {
                answer = max(answer, s - lst);
                lst = t;
                check = 1;
                break;
            }
        }
    }

    return answer;
}

#ifdef Nhoksocqt1

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    #define TASK "GAP"
    if(fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }

    int T, N;
    cin >> T >> N;
    for (int i = 1; i <= N; ++i) {
        cin >> _A[i];
        //_A[i] = _A[i - 1] + Random(1, 1e9); cout << _A[i] << " \n"[i == N];
    }

    M = 0;
    cout << "ANSWER: " << findGap(T, N) << '\n';
    cout << "COST ASK: " << M << '\n';
    return 0;
}

#endif // Nhoksocqt1

Compilation message

gap.cpp: In function 'll findGap(int, int)':
gap.cpp:68:28: error: invalid conversion from 'll' {aka 'long long int'} to 'long long int*' [-fpermissive]
   68 |     MinMax(0, ll(1e18), a[1], a[nArr]);
      |                         ~~~^
      |                            |
      |                            ll {aka long long int}
In file included from gap.cpp:2:
gap.h:1:35: note:   initializing argument 3 of 'void MinMax(long long int, long long int, long long int*, long long int*)'
    1 | void MinMax(long long, long long, long long*, long long*);
      |                                   ^~~~~~~~~~
gap.cpp:68:37: error: invalid conversion from 'll' {aka 'long long int'} to 'long long int*' [-fpermissive]
   68 |     MinMax(0, ll(1e18), a[1], a[nArr]);
      |                               ~~~~~~^
      |                                     |
      |                                     ll {aka long long int}
In file included from gap.cpp:2:
gap.h:1:47: note:   initializing argument 4 of 'void MinMax(long long int, long long int, long long int*, long long int*)'
    1 | void MinMax(long long, long long, long long*, long long*);
      |                                               ^~~~~~~~~~
gap.cpp:72:58: error: invalid conversion from 'll' {aka 'long long int'} to 'long long int*' [-fpermissive]
   72 |             MinMax(a[i - 1] + 1, a[nArr - i + 2] - 1, a[i], a[nArr - i + 1]);
      |                                                       ~~~^
      |                                                          |
      |                                                          ll {aka long long int}
In file included from gap.cpp:2:
gap.h:1:35: note:   initializing argument 3 of 'void MinMax(long long int, long long int, long long int*, long long int*)'
    1 | void MinMax(long long, long long, long long*, long long*);
      |                                   ^~~~~~~~~~
gap.cpp:72:75: error: invalid conversion from 'll' {aka 'long long int'} to 'long long int*' [-fpermissive]
   72 |             MinMax(a[i - 1] + 1, a[nArr - i + 2] - 1, a[i], a[nArr - i + 1]);
      |                                                             ~~~~~~~~~~~~~~^
      |                                                                           |
      |                                                                           ll {aka long long int}
In file included from gap.cpp:2:
gap.h:1:47: note:   initializing argument 4 of 'void MinMax(long long int, long long int, long long int*, long long int*)'
    1 | void MinMax(long long, long long, long long*, long long*);
      |                                               ^~~~~~~~~~
gap.cpp:88:47: error: invalid conversion from 'll' {aka 'long long int'} to 'long long int*' [-fpermissive]
   88 |             MinMax(pos + 1, pos + (1LL << i), s, t);
      |                                               ^
      |                                               |
      |                                               ll {aka long long int}
In file included from gap.cpp:2:
gap.h:1:35: note:   initializing argument 3 of 'void MinMax(long long int, long long int, long long int*, long long int*)'
    1 | void MinMax(long long, long long, long long*, long long*);
      |                                   ^~~~~~~~~~
gap.cpp:88:50: error: invalid conversion from 'll' {aka 'long long int'} to 'long long int*' [-fpermissive]
   88 |             MinMax(pos + 1, pos + (1LL << i), s, t);
      |                                                  ^
      |                                                  |
      |                                                  ll {aka long long int}
In file included from gap.cpp:2:
gap.h:1:47: note:   initializing argument 4 of 'void MinMax(long long int, long long int, long long int*, long long int*)'
    1 | void MinMax(long long, long long, long long*, long long*);
      |                                               ^~~~~~~~~~