Submission #943886

#TimeUsernameProblemLanguageResultExecution timeMemory
943886Boycl07Gap (APIO16_gap)C++17
Compilation error
0 ms0 KiB
#include "gap.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 1; (i) <= (n); ++i) #define forn(i, l, r) for(int i = (l); i <= (r); ++i) #define ford(i, r, l) for(int i = (r); i >= (l); --i) #define FOR(i, n) for(int i = 0; i < (n); ++i) #define FORD(i, n) for(int i = ((n) - 1); i >= 0; --i) #define fi first #define se second #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define endl "\n" #define task "firework" #define sz(a) int(a.size()) #define C(x, y) make_pair(x, y) #define all(a) (a).begin(), (a).end() #define bit(i, mask) (mask >> i & 1) template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; } template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; } inline int readInt() {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();int n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;} inline ll readLong() {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();ll n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;} inline string readString() {char c;while(c=getchar(),c==' '||c=='\n'||c=='\t');string s({c});while(c=getchar(),c!=EOF&&c!=' '&&c!='\n'&&c!='\t')s+=c;return s;} static int subtask_num, N; static long long A[100001]; static long long call_count; void MinMax(long long, long long, long long*, long long*); int findGap(int T, int N) { vector<ll> a(N + 2); if(T == 1) { int l = 1, r = N; ll lb = 0, rb = 1e18; while(l <= r) { ll x, y; MinMax(lb, rb, &x, &y); a[l] = x; ++l; a[r] = y; --r; lb = x + 1; rb = y - 1; } ll res = 0; rep(i, N - 1) maximize(res, a[i + 1] - a[i]); return res; } // ll x, y; // MinMax(0, 1e18, &x, &y); // a[1] = x, a[N] = y; // ll res = 0; // ll Min_step = (a[N] - a[1] - 1) / (N - 1) + 1; // if(N == 2) return a[N] - a[1]; // for(ll i = a[1], pre = a[1]; i <= a[N]; i += Min_step + 1) // { // MinMax(i, i + Min_step, &x, &y); // if(x != -1) maximize(res, x - pre), pre = y; // } // return res; } #ifndef LOCAL void MinMax(long long s, long long t, long long *mn, long long *mx) { int lo = 1, hi = N, left = N+1, right = 0; assert(s <= t && mn != NULL && mx != NULL); while (lo <= hi){ int mid = (lo+hi)>>1; if (A[mid] >= s) hi = mid - 1, left = mid; else lo = mid + 1; } lo = 1, hi = N; while (lo <= hi){ int mid = (lo+hi)>>1; if (A[mid] <= t) lo = mid + 1, right = mid; else hi = mid - 1; } if (left > right) *mn = *mx = -1; else{ *mn = A[left]; *mx = A[right]; } if (subtask_num == 1) call_count++; else if (subtask_num == 2) call_count += right-left+2; } int main() { FILE *in = stdin, *out = stdout; assert(2 == fscanf(in, "%d%d", &subtask_num, &N)); assert(1 <= subtask_num && subtask_num <= 2); assert(2 <= N && N <= 100000); for (int i=1;i<=N;i++) assert(1 == fscanf(in, "%lld", A+i)); for (int i=1;i<N;i++) assert(A[i] < A[i+1]); fprintf(out, "%lld\n", findGap(subtask_num, N)); fprintf(out, "%lld\n", call_count); } #endif // LOCAL

Compilation message (stderr)

gap.cpp: In function 'int main()':
gap.cpp:106:19: warning: format '%lld' expects argument of type 'long long int', but argument 3 has type 'int' [-Wformat=]
  106 |  fprintf(out, "%lld\n", findGap(subtask_num, N));
      |                ~~~^     ~~~~~~~~~~~~~~~~~~~~~~~
      |                   |            |
      |                   |            int
      |                   long long int
      |                %d
gap.cpp: In function 'int findGap(int, int)':
gap.cpp:40:23: warning: control reaches end of non-void function [-Wreturn-type]
   40 |     vector<ll> a(N + 2);
      |                       ^
/usr/bin/ld: /tmp/ccFJ51qO.o: in function `MinMax(long long, long long, long long*, long long*)':
grader.cpp:(.text+0x0): multiple definition of `MinMax(long long, long long, long long*, long long*)'; /tmp/ccwPEt8N.o:gap.cpp:(.text+0x0): first defined here
/usr/bin/ld: /tmp/ccFJ51qO.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccwPEt8N.o:gap.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status