#include "king.h"
#include<queue>
#include<algorithm>
using namespace std;
#define ll long long
int N;
ll ret = 0;
priority_queue<int> pq;
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();
}
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);
}
}
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 |
24 ms |
24596 KB |
Correct |
2 |
Correct |
22 ms |
24740 KB |
Correct |
3 |
Correct |
26 ms |
24608 KB |
Correct |
4 |
Correct |
23 ms |
24868 KB |
Correct |
5 |
Correct |
24 ms |
24864 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
142 ms |
37132 KB |
Correct |
2 |
Correct |
195 ms |
40344 KB |
Correct |
3 |
Correct |
183 ms |
40988 KB |
Correct |
4 |
Correct |
217 ms |
40896 KB |
Correct |
5 |
Correct |
228 ms |
40892 KB |
Correct |
6 |
Correct |
216 ms |
40788 KB |
Correct |
7 |
Correct |
188 ms |
40812 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
180 ms |
36972 KB |
B = 993847 |
2 |
Partially correct |
293 ms |
40324 KB |
B = 996200 |
3 |
Partially correct |
238 ms |
40876 KB |
B = 706116 |
4 |
Partially correct |
331 ms |
41048 KB |
B = 998466 |
5 |
Partially correct |
331 ms |
40828 KB |
B = 995867 |
6 |
Partially correct |
327 ms |
40532 KB |
B = 997501 |
7 |
Partially correct |
229 ms |
40816 KB |
B = 706123 |
8 |
Correct |
162 ms |
34628 KB |
Correct |