#include "cross.h"
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
#define ff first
#define ss second
vector<pii> A;
vector<int> xx;
int N;
const int SIZE = 1 << 18;
struct ST {
int A[SIZE << 1];
void update(int x, int v) {
for (x += SIZE; x; x >>= 1) A[x] += v;
}
int query(int v) {
int x = 1;
while (x < SIZE) {
if (A[x << 1 | 1] >= v) x = x << 1 | 1;
else {
x <<= 1;
v -= A[x | 1];
}
}
return x - SIZE;
}
} seg;
ll SelectCross(int K, std::vector<int> I, std::vector<int> O) {
N = I.size();
for (int i = 0; i < N; ++i) A.emplace_back(I[i], O[i]);
sort(A.rbegin(), A.rend());
for (auto i : A) xx.push_back(i.ss);
sort(xx.begin(), xx.end());
xx.erase(unique(xx.begin(), xx.end()), xx.end());
for (auto &i : A) i.ss = lower_bound(xx.begin(), xx.end(), i.ss) - xx.begin();
int cnt = 0;
long long ans = 0;
for (auto i : A) {
seg.update(i.ss, 1);
cnt++;
if (cnt < K) continue;
ans = max(ans, 2ll * i.ff * xx[seg.query(K)] - (ll) i.ff * i.ff);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
512 KB |
Output is correct |
5 |
Correct |
14 ms |
1024 KB |
Output is correct |
6 |
Correct |
189 ms |
8544 KB |
Output is correct |
7 |
Correct |
174 ms |
8552 KB |
Output is correct |
8 |
Correct |
167 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
512 KB |
Output is correct |
5 |
Correct |
14 ms |
1024 KB |
Output is correct |
6 |
Correct |
189 ms |
8544 KB |
Output is correct |
7 |
Correct |
174 ms |
8552 KB |
Output is correct |
8 |
Correct |
167 ms |
8540 KB |
Output is correct |
9 |
Correct |
6 ms |
472 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
7 ms |
384 KB |
Output is correct |
12 |
Correct |
15 ms |
896 KB |
Output is correct |
13 |
Correct |
94 ms |
4328 KB |
Output is correct |
14 |
Correct |
177 ms |
8420 KB |
Output is correct |
15 |
Correct |
177 ms |
8420 KB |
Output is correct |
16 |
Correct |
177 ms |
8420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
512 KB |
Output is correct |
5 |
Correct |
14 ms |
1024 KB |
Output is correct |
6 |
Correct |
189 ms |
8544 KB |
Output is correct |
7 |
Correct |
174 ms |
8552 KB |
Output is correct |
8 |
Correct |
167 ms |
8540 KB |
Output is correct |
9 |
Correct |
6 ms |
472 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
7 ms |
384 KB |
Output is correct |
12 |
Correct |
15 ms |
896 KB |
Output is correct |
13 |
Correct |
94 ms |
4328 KB |
Output is correct |
14 |
Correct |
177 ms |
8420 KB |
Output is correct |
15 |
Correct |
177 ms |
8420 KB |
Output is correct |
16 |
Correct |
177 ms |
8420 KB |
Output is correct |
17 |
Correct |
6 ms |
384 KB |
Output is correct |
18 |
Correct |
6 ms |
512 KB |
Output is correct |
19 |
Correct |
14 ms |
1024 KB |
Output is correct |
20 |
Correct |
90 ms |
4460 KB |
Output is correct |
21 |
Correct |
137 ms |
7012 KB |
Output is correct |
22 |
Correct |
169 ms |
8552 KB |
Output is correct |
23 |
Correct |
168 ms |
8544 KB |
Output is correct |
24 |
Correct |
184 ms |
8548 KB |
Output is correct |
25 |
Correct |
181 ms |
8468 KB |
Output is correct |
26 |
Correct |
174 ms |
8548 KB |
Output is correct |