This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize ("Ofast")
#include "teams.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 100000, S = 316;
int n;
pair<int, int> sg[N];
vector<pair<int, int>> lp[N];
bitset<N> curr, temp, bt[N], pre[S];
void init(int nn, int a[], int b[]) {
n = nn;
for (int i = 0; i < n; i++) {
sg[i] = make_pair(b[i], a[i]);
}
sort(sg, sg+n);
for (int i = 0; i < n; i++) {
lp[sg[i].second].push_back(make_pair(sg[i].first, i));
}
priority_queue<pair<int, int>> pq;
for (int i = 1; i <= n; i++) {
for (auto& [j, idx] : lp[i]) {
pq.push(make_pair(-j, idx));
curr[idx] = 1;
}
bt[i] = curr;
while (!pq.empty() && -pq.top().first <= i) {
curr[pq.top().second] = 0;
pq.pop();
}
}
pre[0].reset();
for (int i = 1; i < S; i++) {
pre[i] = pre[i-1];
for (int j = S*(i-1); j < S*i; j++) {
pre[i][j] = 1;
}
}
}
int can(int m, int k[]) {
sort(k, k+m);
curr = pre[S-1];
for (int i = S*(S-1); i <= n; i++) {
curr[i] = 1;
}
for (int i = 0; i < m; i++) {
/*
cerr << i << endl;
for (int j = 0; j < n; j++) {
cerr << curr[j] << " ";
}
cerr << endl;
cerr << k[i] << endl;
for (int j = 0; j < n; j++) {
cerr << bt[k[i]][j] << " ";
}
cerr << endl;
temp = curr & bt[k[i]];
cerr << (int)temp.count() << endl << endl;
*/
temp = curr & bt[k[i]];
if ((int)temp.count() < k[i]) return 0;
// solo quiero los k primeros de temp
int l = 0;
int r = n-1;
while (l < r) {
int mid = (l+r) >> 1;
int block = mid/S;
for (int j = S*block; j <= mid; j++) {
pre[mid][j] = 1;
}
if ((int)(temp & pre[mid]).count() >= k[i]) r = mid;
else l = mid+1;
for (int j = S*block; j <= mid; j++) {
pre[mid][j] = 0;
}
}
// le quito a curr los k primeros de temp
int block = l/S;
for (int j = S*block; j <= l; j++) {
pre[l][j] = 1;
}
curr ^= (temp & pre[l]);
for (int j = S*block; j <= l; j++) {
pre[l][j] = 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... |