답안 #73808

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
73808 2018-08-29T04:41:47 Z 윤교준(#2277) 놀이터에 떨어진 이상한 약 (FXCUP3_gorgeous) C++11
51 / 100
1500 ms 94864 KB
#include <bits/stdc++.h>
#define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
static unsigned char str[8800088], *p=str;
static ll __arrll[20000000], *__arrllp = __arrll;
inline ll* newll(const unsigned int SZ) {
	__arrllp += SZ;
	return __arrllp - SZ;
}
static int __arrint[20000000], *__arrintp = __arrint;
inline int* newint(const unsigned int SZ) {
	__arrintp += SZ;
	return __arrintp - SZ;
}

const int MAXN = 300005;
const int MX = 524288;

struct BIT {
	ll *d;
	int *XV;
	int n, i;
	
	void pushpoint() { n++; }
	void precalpoint() {
		if(!n) return;
		XV = newint(n);
	}
	void push(int x) { XV[i++] = x; }
	void precal() {
		if(!n) return;
		sort(XV, XV+n);
		n = int(unique(XV, XV+n) - XV);
		d = newll(n+1);
		fill(d, d+n+1, 0);
	}
	
	void upd(int x, ll r) {
		x = int(lower_bound(XV, XV+n, x) - XV) + 1;
		for(; x <= n; x += rb(x))
			if(d[x] < r) d[x] = r;
	}
	ll get(int x) {
		x = int(upper_bound(XV, XV+n, x) - XV);
		ll r = 0;
		for(; 0 < x; x -= rb(x))
			if(r < d[x]) r = d[x];
		return r;
	}
};

struct SEG {
	BIT d[MX*2];

	void pushpoint(int x, int y) {
		for(x += MX; x; x >>= 1)
			d[x].pushpoint();
	}
	void precalpoint() {
		for(int i = 1; i < MX*2; i++)
			d[i].precalpoint();
	}
	void push(int x, int y) {
		for(x += MX; x; x >>= 1)
			d[x].push(y);
	}
	void precal() {
		for(int i = 1; i < MX*2; i++)
			d[i].precal();
	}

	void upd(int x, int y, ll r) {
		for(x += MX; x; x >>= 1)
			d[x].upd(y, r);
	}
	ll get(int s, int y) {
		ll r = 0, t; int e = MX-1;
		for(s += MX, e += MX; s <= e; s >>= 1, e >>= 1) {
			if(s&1) {
				t = d[s].get(y);
				if(r < t) r = t;
				s++;
			}
			if(~e&1) {
				t = d[e].get(y);
				if(r < t) r = t;
				e--;
			}
		}
		return r;
	}
} seg;

struct EVT {
	EVT(int s, int e, int x) : s(s), e(e), x(x) {}
	int s, e, x;

	inline void f(int &_s, int &_e, int &_x) const {
		_s = s; _e = e; _x = x;
	}
	bool operator < (const EVT &t) const {
		return (e-s) > (t.e-t.s);
	}
};

vector<EVT> EV;
vector<pii> LV;

int A[MAXN], B[MAXN];

int N;

inline bool isGood(int s, int e) { return 1 <= s && s <= e && e <= N; }

int main() {
	fread(str, 1, 8800088, stdin);

	rf(N)
	for(int i = 1; i <= N; i++) { rf(A[i]) }
	for(int i = 1; i <= N; i++) { rf(B[i]) }

	LV.eb(1, N);
	for(int i = 1, s, e; i <= N; i++) {
		s = i-A[i]+1; e = i-1;
		if(isGood(s, e)) {
			LV.eb(s, e);
			EV.eb(s, e+1, i);
		}
		s = i+1; e = i+A[i]-1;
		if(isGood(s, e)) {
			LV.eb(s, e);
			EV.eb(s-1, e, -i);
		}
	}
	for(auto &v : LV) seg.pushpoint(v.second, v.first);
	seg.precalpoint();
	for(auto &v : LV) seg.push(v.second, v.first);
	seg.precal(); sorv(EV);

	for(auto &evt : EV) {
		int s, e, idx; evt.f(s, e, idx);
		if(0 < idx) {
			ll t = seg.get(e, s) + B[idx];
			seg.upd(e-1, s, t);
		} else {
			idx = -idx;
			ll t = seg.get(e, s) + B[idx];
			seg.upd(e, s+1, t);
		}
	}

	for(int i = 1; i <= N; i++)
		printf("%lld ", seg.get(i, i) + (1 == A[i] ? B[i] : 0));
	puts("");
	return 0;
}

Compilation message

gorgeous.cpp: In function 'int main()':
gorgeous.cpp:131:7: warning: ignoring return value of 'size_t fread(void*, size_t, size_t, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  fread(str, 1, 8800088, stdin);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 504 KB Output is correct
2 Correct 11 ms 616 KB Output is correct
3 Correct 10 ms 652 KB Output is correct
4 Correct 11 ms 652 KB Output is correct
5 Correct 10 ms 652 KB Output is correct
6 Correct 10 ms 652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 504 KB Output is correct
2 Correct 11 ms 616 KB Output is correct
3 Correct 10 ms 652 KB Output is correct
4 Correct 11 ms 652 KB Output is correct
5 Correct 10 ms 652 KB Output is correct
6 Correct 10 ms 652 KB Output is correct
7 Correct 9 ms 756 KB Output is correct
8 Correct 9 ms 756 KB Output is correct
9 Correct 10 ms 756 KB Output is correct
10 Correct 11 ms 756 KB Output is correct
11 Correct 18 ms 928 KB Output is correct
12 Correct 15 ms 944 KB Output is correct
13 Correct 14 ms 992 KB Output is correct
14 Correct 13 ms 992 KB Output is correct
15 Correct 13 ms 1104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 504 KB Output is correct
2 Correct 11 ms 616 KB Output is correct
3 Correct 10 ms 652 KB Output is correct
4 Correct 11 ms 652 KB Output is correct
5 Correct 10 ms 652 KB Output is correct
6 Correct 10 ms 652 KB Output is correct
7 Correct 9 ms 756 KB Output is correct
8 Correct 9 ms 756 KB Output is correct
9 Correct 10 ms 756 KB Output is correct
10 Correct 11 ms 756 KB Output is correct
11 Correct 18 ms 928 KB Output is correct
12 Correct 15 ms 944 KB Output is correct
13 Correct 14 ms 992 KB Output is correct
14 Correct 13 ms 992 KB Output is correct
15 Correct 13 ms 1104 KB Output is correct
16 Correct 32 ms 2456 KB Output is correct
17 Correct 139 ms 8648 KB Output is correct
18 Correct 804 ms 32952 KB Output is correct
19 Correct 1111 ms 42680 KB Output is correct
20 Execution timed out 1571 ms 94864 KB Time limit exceeded
21 Halted 0 ms 0 KB -