This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "cross.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
pair<int, int> arr[200000];
int it[200000], ot[200000];
int n;
int update(int st[], int idx, int v, int p, int x, int y)
{
if(idx<x || idx>y) return st[p];
if(x==y) return st[p]=v;
int mid=x+y>>1;
return st[p]=min(update(st, idx, v, p<<1, x, mid), update(st, idx, v, (p<<1)+1, mid+1, y));
}
long long SelectCross(int K, std::vector<int> I, std::vector<int> O)
{
n=I.size();
memset(it, 0x3f3f3f3f, sizeof(it));
memset(ot, 0x3f3f3f3f, sizeof(it));
for(int i=0; i<n; i++)
{
arr[i]={O[i], I[i]};
}
sort(arr, arr+n);
for(int i=0; i<K; i++)
{
update(ot, i, arr[i].first, 1, 0, n);
update(it, i, arr[i].second, 1, 0, n);
}
ll ans=0;
for(int i=0; i<n; i++)
{
int isize=it[1], osize=ot[1];
ans=max(ans, ll(osize)*osize-ll(osize-isize)*(osize-isize));
// cout<<ans<<' ';
update(ot, i, 1e9, 1, 0, n);
update(it, i, 1e9, 1, 0, n);
update(ot, (i+K)%n, arr[(i+K)%n].first, 1, 0, n);
update(it, (i+K)%n, arr[(i+K)%n].second, 1, 0, n);
}
return ans;
}
Compilation message (stderr)
cross.cpp: In function 'int update(int*, int, int, int, int, int)':
cross.cpp:13:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=x+y>>1;
~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |