Submission #1076481

# Submission time Handle Problem Language Result Execution time Memory
1076481 2024-08-26T14:11:46 Z Pannda Gap (APIO16_gap) C++17
Compilation error
0 ms 0 KB
#include "gap.h"

#include <bits/stdc++.h>
using namespace std;

long long findGap(int type, int n) {
    constexpr long long C = 1e18;
    if (type == 1) {
        vector<long long> a(n);
        int idx_l = 0, idx_r = n - 1;
        long long l = 0, r = C;
        for (int t = 0; t < (n + 1) / 2; t++) {
            MinMax(l, r, &a[idx_l], &a[idx_r]);
            l = a[idx_l] + 1;
            r = a[idx_r] - 1;
            idx_l++;
            idx_r--;
        }
        long long ans = 0;
        for (int i = 0; i + 1 < n; i++) {
            ans = max(ans, a[i + 1] - a[i]);
        }
        return ans;
    } else {
        long long x;
        long long last;
        MinMax(0, C, &x, &last);
        long long ans = 1;

        if (N >= 100) {
            for (int d = 1; d <= 10; d++) {
                long long mn, mx;
                MinMax(x, x + d, mn, mx);
                if (mx != x) {
                    break;
                }
                ans++;
            }
        }

        while (last - x > ans) {
            // with x, find some d such that [x, x + d] is only x, and [x + d + 1, x + d + 1 + d] is none empty and is (mn, mx)
            // update ans with mn - x, and set new x to mx
            // jump x until [x + ans] is only x
            while (last - x > ans) {
                // assert( [x, x + ans] is only x)
                long long s = x + ans + 1;
                assert(s <= C);
                long long mn, mx;
                MinMax(s, s + ans, &mn, &mx);
                if (mn == -1) {
                    ans = ans + ans + 1;
                } else {
                    ans = mn - x;
                    x = mx;
                    break;
                }
            }
            while (last - x > ans) {
                long long mn, mx;
                MinMax(x, x + ans, &mn, &mx);
                if (mx == x) {
                    break;
                } else {
                    x = mx;
                }
            }
        }
        return ans;
    }
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:30:13: error: 'N' was not declared in this scope
   30 |         if (N >= 100) {
      |             ^
gap.cpp:33:34: error: invalid conversion from 'long long int' to 'long long int*' [-fpermissive]
   33 |                 MinMax(x, x + d, mn, mx);
      |                                  ^~
      |                                  |
      |                                  long long int
In file included from gap.cpp:1:
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:33:38: error: invalid conversion from 'long long int' to 'long long int*' [-fpermissive]
   33 |                 MinMax(x, x + d, mn, mx);
      |                                      ^~
      |                                      |
      |                                      long long int
In file included from gap.cpp:1:
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*);
      |                                               ^~~~~~~~~~