Submission #243609

#TimeUsernameProblemLanguageResultExecution timeMemory
243609uacoder123Gap (APIO16_gap)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define FOR(i,a,b) for (auto i = (a); i <= (b); ++i) #define NFOR(i,a,b) for(auto i = (a); i >= (b); --i) #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) #define mp(i,a) make_pair(i,a) #define pb(a) push_back(a) #define bit(x,b) (x&(1LL<<b)) typedef long long int lli; typedef pair <lli,lli> ii; typedef pair <lli,ii> iii; typedef vector <lli> vi; static void my_assert(int k){ if (!k) exit(1); } static int subtask_num, N; static long long A[100001]; static long long call_count; void MinMax(long long s, long long t, long long *mn, long long *mx) { int lo = 1, hi = N, left = N+1, right = 0; my_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; } long long findGap(int T, int N) { lli c=0,arr[N],l=0,rem=0,g,r=1000000000000000000,l1=0,r1=N-1,ans1,ans2,m=0; if(T==1) { for(;l1<=r1;) { MinMax(l,r,&ans1,&ans2); arr[l1]=ans1; l1++; l=ans1+1; arr[r1]=ans2; r1--; r=ans2-1; } for(lli i=0;i<N-1;++i) m=max(m,arr[i+1]-arr[i]); } else { MinMax(l,r,&ans1,&ans2); l=ans1+1; r=ans2-1; g=(r-l+1)/(N-1); rem+=(r-l+1)%(N-1); r1=g+l-1; vector<ii> v; v.pb(mp(ans1,ans1)); while(1) { MinMax(l,min(r1+min(1*1LL,rem),r),&ans1,&ans2); if(r<=min(r1+min(1*1LL,rem),r)) break; l=1+r1+min(1*1LL,rem); r1=r1+min(1*1LL,rem)+g; if(rem>0) rem-=1; if(ans1!=-1) v.pb(mp(ans1,ans2)); } v.pb(mp(r+1,r+1)); for(lli i=0;i<lli(v.size())-1;++i) { m=max(m,v[i+1].F-v[i].S); } } return m; } int main() { FILE *in = stdin, *out = stdout; my_assert(2 == fscanf(in, "%d%d", &subtask_num, &N)); my_assert(1 <= subtask_num && subtask_num <= 2); my_assert(2 <= N && N <= 100000); for (int i=1;i<=N;i++) my_assert(1 == fscanf(in, "%lld", A+i)); for (int i=1;i<N;i++) my_assert(A[i] < A[i+1]); fprintf(out, "%lld\n", findGap(subtask_num, N)); fprintf(out, "%lld\n", call_count); }

Compilation message (stderr)

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:49:7: warning: unused variable 'c' [-Wunused-variable]
   lli c=0,arr[N],l=0,rem=0,g,r=1000000000000000000,l1=0,r1=N-1,ans1,ans2,m=0;
       ^
/tmp/ccmU9ATI.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/ccDWqvc5.o:gap.cpp:(.text+0x0): first defined here
/tmp/ccmU9ATI.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccDWqvc5.o:gap.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status