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 "king.h"
#include<queue>
#include<algorithm>
using namespace std;
#define ll long long
int N;
ll ret = 0;
priority_queue<int> pq;
struct abc {
int idx, val;
bool operator <(abc a)const {
return val < a.val;
}
};
long long SendInfo(std::vector<int> W, std::vector<int> C) {
vector<abc> v;
N = W.size();
for (int i = 0; i < N; i++)
pq.push(-C[i]);
sort(W.begin(), W.end());
for (int i = 0; i < N; i++)
{
while (!pq.empty() && W[i] > -pq.top()) pq.pop();
if (pq.empty()) break;
ret = W[i];
pq.pop();
}
for (int i = 0; i < N; i++) {
v.push_back({ i,C[i] });
}
sort(v.begin(), v.end());
for (int i = 0; i < N; i++) {
if (v[i].val > ret) {
ret = i;
break;
}
if (i == N-1) {
ret = N-1;
}
}
return ret;
}
#include "vassal.h"
#include<vector>
#include<algorithm>
using namespace std;
#define SZ 1'000'000
long long BB;
int NN;
int seg[2100000];
vector<int> x[1000101];
int Update(int idx, int val, int n, int l, int r)
{
if (r < idx || idx < l) return seg[n];
if (l == r) return seg[n] += val;
int mid = l + r >> 1;
return seg[n] = Update(idx, val, n * 2, l, mid) + Update(idx, val, n * 2 + 1, mid + 1, r);
}
int Query(int L, int R, int n, int l, int r)
{
if (r < L || R < l) return 0;
if (L <= l && r <= R) return seg[n];
int mid = l + r >> 1;
return Query(L, R, n * 2, l, mid) + Query(L, R, n * 2 + 1, mid + 1, r);
}
int Kth(int k, int n, int l, int r)
{
if (l == r) return l;
int mid = l + r >> 1;
if (k <= seg[n * 2]) return Kth(k, n * 2, l, mid);
return Kth(k - seg[n * 2], n * 2 + 1, mid + 1, r);
}
void Init(long long B, std::vector<int> C){
NN = C.size();
for (int i = 0; i < NN; i++)
{
Update(C[i], 1, 1, 1, SZ);
x[C[i]].push_back(i);
}
sort(C.begin(), C.end());
if (-B != NN) BB = C[-B];
else BB = 1e9;
}
int Maid(int W){
if (W > BB) return -1;
if (Query(W, SZ, 1, 1, SZ) == 0) return -1;
int cnt = Query(0, W - 1, 1, 1, SZ) + 1;
int idx = Kth(cnt, 1, 1, SZ);
int ret = x[idx].back();
Update(idx, -1, 1, 1, SZ);
x[idx].pop_back();
return ret;
}
Compilation message (stderr)
vassal.cpp: In function 'int Update(int, int, int, int, int)':
vassal.cpp:17:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
vassal.cpp: In function 'int Query(int, int, int, int, int)':
vassal.cpp:25:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
vassal.cpp: In function 'int Kth(int, int, int, int)':
vassal.cpp:32:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 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... |