#include "teams.h"
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC target("popcnt")
#pragma GCC optimization ("O3, Ofast")
#pragma GCC optimization ("unroll-loops")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using lld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vlld = vector<lld>;
// #define endl '\n'
#define all(x) x.begin(),x.end()
#define lsb(x) x&(-x)
#define gcd(a,b) __gcd(a,b)
#define sz(x) (int)x.size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fls cout.flush()
#define fore(i,l,r) for(auto i=l;i<r;i++)
#define fo(i,n) fore(i,0,n)
#define forex(i,r,l) for(auto i=r; i>=l;i--)
#define ffo(i,n) forex(i,n-1,0)
bool cmin(ll &a, ll b) { if(b<a){a=b;return 1;}return 0; }
bool cmax(ll &a, ll b) { if(b>a){a=b;return 1;}return 0; }
void valid(ll in) { cout<<((in)?"YES\n":"NO\n"); }
ll lcm(ll a, ll b) { return (a/gcd(a,b))*b; }
ll gauss(ll n) { return (n*(n+1))/2; }
const int INF = 1e9;
const int N = 1e5 + 7;
int st[4*N];
deque<int> as[N];
int a[N], b[N];
int n;
void update (int id, int val) {
id += n;
for (st[id] = val; id > 1; id >>= 1)
st[id>>1] = min(st[id], st[id^1]);
}
int query (int ql, int qr) {
int ans = INF;
for (ql += n, qr += n+1; ql < qr; ql >>= 1, qr >>= 1) {
if (ql&1) ans = min(ans, st[ql++]);
if (qr&1) ans = min(ans, st[--qr]);
}
return ans;
}
void init(int N, int A[], int B[]) {
n = N;
vector<array<int, 2>> rs(n);
fo (i, n) rs[i] = {A[i], B[i]};
sort (all(rs));
fo (i, n) a[i] = rs[i][0], b[i] = rs[i][1];
fo (i, n) as[b[i]].push_back(i);
fore (i, 1, n+1) {
if (sz(as[i]) == 0) {
update (i, INF);
continue;
}
update(i, as[i].front());
}
}
void clear (vector<int> &dxs) {
reverse(all(dxs));
for (int i: dxs) {
as[b[i]].push_front(i);
update(b[i], i);
}
}
int can(int M, int K[]) {
sort(K, K+M);
vector<int> dxs;
fo (i, M) {
int l = 0, r = n-1, lb, rb;
while (l <= r) {
int m = (l+r)/2;
if (a[m] <= K[i]) l = m+1;
else r = m-1;
}
if (r < 0) {
clear(dxs);
return 0;
}
int w = K[i];
while (K[i] > 0) {
lb = w, rb = n;
while (lb <= rb) {
ll m = (lb + rb)/2;
if (query(w, m) <= r) rb = m-1;
else lb = m+1;
}
if (lb > n) {
clear(dxs);
return 0;
}
int j = as[lb].front();
as[lb].pop_front();
w = lb;
if (sz(as[lb]) == 0) update(lb, INF);
else update(lb, as[lb].front());
dxs.pb(j);
K[i]--;
}
}
clear(dxs);
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... |