답안 #148489

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
148489 2019-09-01T04:32:33 Z mit한의대지망생(#3602, TAMREF, imeimi2000, suzy) 십자가 놓기 (FXCUP4_cross) C++17
8 / 100
101 ms 8420 KB
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map>
#include "cross.h"

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();
		int 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:64:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(sz<vx.size()) sz*=2;
        ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 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 1152 KB Output is correct
6 Correct 99 ms 8420 KB Output is correct
7 Correct 95 ms 8164 KB Output is correct
8 Correct 101 ms 8292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 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 1152 KB Output is correct
6 Correct 99 ms 8420 KB Output is correct
7 Correct 95 ms 8164 KB Output is correct
8 Correct 101 ms 8292 KB Output is correct
9 Incorrect 5 ms 384 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 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 1152 KB Output is correct
6 Correct 99 ms 8420 KB Output is correct
7 Correct 95 ms 8164 KB Output is correct
8 Correct 101 ms 8292 KB Output is correct
9 Incorrect 5 ms 384 KB Output isn't correct
10 Halted 0 ms 0 KB -