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 "teams.h"
#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
using namespace std;
using pii = pair<int, int>;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define PB push_back
#define F first
#define S second
const int MAXN = 500010;
int n;
pii pt[MAXN];
void init(int N, int A[], int B[]) {
n=N;
forn(i, n) pt[i]={A[i], B[i]};
sort(pt, pt+n, [](pii a, pii b){
return a.S < b.S;
});
}
int cou(int x1, int x2, int y1, int y2){
int ret=0;
forn(i, n) ret+=(pt[i].F>=x1 && pt[i].F<x2 && pt[i].S>=y1 && pt[i].S<y2);
return ret;
}
// greatest one less than bound (if you add it completely, you get it)
pii binary(int x1, int x2, int bound){
int ret=0, del=0;
forn(i, n){
if(pt[i].F>=x1 && pt[i].F<x2) ++ret, ++del;
if(ret==bound) return {pt[i].S, del};
if(i==n-1 || pt[i].S != pt[i+1].S) del=0;
}
assert(0);
return {-1, -1};
}
bool solve(vector<pii>& dom, vector<int>& xt, pii ins, int target){
int del=0;
while(ins.S >= dom.back().S){
if(ins.S == dom.back().S) del=xt.back();
dom.pop_back();
xt.pop_back();
}
while(true){
int obt = cou(dom.back().F, ins.F + 1, ins.S, dom.back().S) - del;
if(obt < target){
target-=obt;
ins.S=dom.back().S;
del = xt.back();
dom.pop_back();
xt.pop_back();
}
else{
int base = cou(dom.back().F, ins.F + 1, 0, ins.S);
pii res = binary(dom.back().F, ins.F + 1, target + base);
dom.PB({ins.F, res.F});
xt.PB(res.S);
return true;
}
if(dom.empty()) return false;
}
}
int can(int m, int arr[]) {
int dummy=0;
forn(i, m){
dummy+=arr[i];
if(dummy>n) return 0;
}
sort(arr, arr+m);
vector<pii> dom;
vector<int> xt;
dom.PB({-1, MAXN});
xt.PB(0);
int cnt=0;
forn(i, m){
++cnt;
if(i==m-1 || arr[i]!=arr[i+1]){
if(!solve(dom, xt, {arr[i], arr[i]}, cnt*arr[i])){
return 0;
}
cnt=0;
}
}
return 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |