#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long lli;
class p {
public:
lli a, b;
};
bool cmp(const p &i, const p &j) {
if(i.a!=j.a) return i.a>j.a;
else return i.b>j.b;
}
vector<lli> vx;
int n, k, sz=1;
p a[200000];
int bt[1<<19];
void upd(int k, int w) {
while(k) {
bt[k]+=w;
k>>=1;
}
}
int kth(int k) {
if(bt[1]<k) return -1;
int cur=1;
while(cur<sz) {
if(bt[cur*2+1]>=k) cur=(cur*2+1);
else {
k-=bt[cur*2+1];
cur=cur*2;
}
}
return cur-sz;
}
long long SelectCross(int K, std::vector<int> I, std::vector<int> O) {
n=I.size();
k=K;
for(int i=0;i<n;i++) {
a[i].a=I[i];
a[i].b=O[i];
vx.push_back(a[i].b);
}
if(k==1) {
lli res=0;
for(int i=0;i<n;i++) {
lli w=a[i].b*a[i].b-(a[i].b-a[i].a)*(a[i].b-a[i].a);
if(w>res) res=w;
}
return res;
}
sort(vx.begin(),vx.end());
vx.erase(unique(vx.begin(),vx.end()),vx.end());
while(sz<vx.size()) sz*=2;
sort(a,a+n,cmp);
lli res=0;
for(int i=0;i<n;i++) {
int id=lower_bound(vx.begin(),vx.end(),a[i].b)-vx.begin();
lli y=kth(k-1);
if(y<0) {
upd(sz+id,1);
continue;
}
lli x=a[i].a;
y=min(vx[y],a[i].b);
lli w=y*y-(y-x)*(y-x);
if(w>res) res=w;
upd(sz+id,1);
}
return res;
}
Compilation message
cross.cpp: In function 'long long int SelectCross(int, std::vector<int>, std::vector<int>)':
cross.cpp:63:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(sz<vx.size()) sz*=2;
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
11 ms |
1024 KB |
Output is correct |
6 |
Correct |
98 ms |
8292 KB |
Output is correct |
7 |
Correct |
92 ms |
8292 KB |
Output is correct |
8 |
Correct |
98 ms |
8296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
11 ms |
1024 KB |
Output is correct |
6 |
Correct |
98 ms |
8292 KB |
Output is correct |
7 |
Correct |
92 ms |
8292 KB |
Output is correct |
8 |
Correct |
98 ms |
8296 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
12 |
Correct |
15 ms |
1152 KB |
Output is correct |
13 |
Correct |
94 ms |
5356 KB |
Output is correct |
14 |
Correct |
184 ms |
9952 KB |
Output is correct |
15 |
Correct |
184 ms |
9960 KB |
Output is correct |
16 |
Correct |
183 ms |
9952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
11 ms |
1024 KB |
Output is correct |
6 |
Correct |
98 ms |
8292 KB |
Output is correct |
7 |
Correct |
92 ms |
8292 KB |
Output is correct |
8 |
Correct |
98 ms |
8296 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
12 |
Correct |
15 ms |
1152 KB |
Output is correct |
13 |
Correct |
94 ms |
5356 KB |
Output is correct |
14 |
Correct |
184 ms |
9952 KB |
Output is correct |
15 |
Correct |
184 ms |
9960 KB |
Output is correct |
16 |
Correct |
183 ms |
9952 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
6 ms |
384 KB |
Output is correct |
19 |
Correct |
15 ms |
1024 KB |
Output is correct |
20 |
Correct |
91 ms |
5356 KB |
Output is correct |
21 |
Correct |
142 ms |
8036 KB |
Output is correct |
22 |
Correct |
184 ms |
9956 KB |
Output is correct |
23 |
Correct |
187 ms |
9704 KB |
Output is correct |
24 |
Correct |
189 ms |
9956 KB |
Output is correct |
25 |
Correct |
178 ms |
9952 KB |
Output is correct |
26 |
Correct |
177 ms |
9948 KB |
Output is correct |