#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;
}
};
vector<abc> v;
long long SendInfo(std::vector<int> W, std::vector<int> C) {
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;
}
}
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();
BB = B;
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
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;
~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
24704 KB |
Correct |
2 |
Correct |
27 ms |
24832 KB |
Correct |
3 |
Correct |
27 ms |
24864 KB |
Correct |
4 |
Correct |
24 ms |
24352 KB |
Correct |
5 |
Correct |
26 ms |
24868 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
134 ms |
37336 KB |
Correct |
2 |
Correct |
202 ms |
40896 KB |
Correct |
3 |
Correct |
190 ms |
41512 KB |
Correct |
4 |
Correct |
216 ms |
41716 KB |
Correct |
5 |
Correct |
220 ms |
41644 KB |
Correct |
6 |
Correct |
222 ms |
41636 KB |
Correct |
7 |
Correct |
185 ms |
41648 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
184 ms |
37580 KB |
B = 50983 |
2 |
Partially correct |
296 ms |
40792 KB |
B = 91396 |
3 |
Partially correct |
243 ms |
41624 KB |
B = 91327 |
4 |
Partially correct |
296 ms |
41628 KB |
B = 99839 |
5 |
Partially correct |
296 ms |
41636 KB |
B = 99579 |
6 |
Partially correct |
309 ms |
41628 KB |
B = 99741 |
7 |
Partially correct |
220 ms |
41624 KB |
B = 91342 |
8 |
Correct |
156 ms |
35484 KB |
Correct |