#include "teams.h"
#include <bits/stdc++.h>
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;
struct Fenwick {
vector<multiset<int>> ft;
int n;
Fenwick () { }
Fenwick (int n): n (n + 4), ft (n + 4) { }
void insrt (int i, int x) {
i++;
for (; i < n; i += lsb(i))
ft[i].insert(x);
}
void delet (int i, int x) {
i++;
for (; i < n; i += lsb(i))
ft[i].erase(ft[i].find(x));
}
int query (int i, int x) {
i++;
int ans = INF;
for (; i > 0; i -= lsb(i)) {
auto it = ft[i].lower_bound(x);
if (it == ft[i].end()) continue;
ans = min(ans, *it);
}
return ans;
}
};
const int N = 5e5 + 7;
deque<int> as[N];
Fenwick ft;
int a[N], b[N];
int n;
void init(int N, int A[], int B[]) {
n = N;
vector<array<ll, 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];
ft = Fenwick (n);
fo (i, n) ft.insrt (i, b[i]);
fo (i, n) as[b[i]].push_back(i);
}
int can(int M, int K[]) {
sort(K, K+M);
vector<int> dxs;
fo (i, M) {
ll l = 0, r = n-1;
while (l <= r) {
ll m = (l+r)/2;
if (a[m] <= K[i]) l = m+1;
else r = m-1;
}
if (r < 0) return 0;
int w = K[i];
while (K[i] > 0) {
int x = ft.query (r, w);
if (x == INF) return 0;
int j = as[x].front();
ft.delet (j, x);
dxs.pb(j);
as[x].pop_front();
K[i]--;
}
}
reverse(all(dxs));
for (ll i: dxs) as[b[i]].push_front(i), ft.insrt (i, b[i]);
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... |