답안 #73802

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
73802 2018-08-29T04:30:32 Z 윤교준(#2277) 놀이터에 떨어진 이상한 약 (FXCUP3_gorgeous) C++11
51 / 100
1500 ms 142916 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;

const bool debug = 0;
const int MAXN = 300005;
const int MX = 524288;

struct BIT {
	vector<int> XV;
	ll *d;
	int n;
	
	void push(int x) {
		XV.eb(x);
	}
	void precal() {
		if(XV.empty()) return;
		sorv(XV); univ(XV);
		n = sz(XV);
		d = new ll[n+1];
		fill(d, d+n+1, 0);
	}
	
	void upd(int x, ll r) {
		x = int(lower_bound(allv(XV), x) - XV.begin()) + 1;
		for(; x <= n; x += rb(x))
			if(d[x] < r) d[x] = r;
	}
	ll get(int x) {
		x = int(upper_bound(allv(XV), x) - XV.begin());
		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 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;

int A[MAXN], B[MAXN];

int N;

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

int main() {
	ios::sync_with_stdio(false);

	cin >> N;
	for(int i = 1; i <= N; i++) cin >> A[i];
	for(int i = 1; i <= N; i++) cin >> B[i];

	seg.push(1, N);
	for(int i = 1, s, e; i <= N; i++) {
		s = i-A[i]+1; e = i-1;
		if(isGood(s, e)) {
			seg.push(e, s);
			EV.eb(s, e+1, i);
		}
		s = i+1; e = i+A[i]-1;
		if(isGood(s, e)) {
			seg.push(e, s);
			EV.eb(s-1, e, -i);
		}
	}
	seg.precal(); sorv(EV);

	for(auto &evt : EV) {
		int s, e, idx; evt.f(s, e, idx);
		if(debug) printf("EVT %d %d %d\n", s, e, idx);
		if(0 < idx) {
			ll t = seg.get(e, s) + B[idx];
			seg.upd(e-1, s, t);
			if(debug) printf("GET %lld\n", t);
		} else {
			idx = -idx;
			ll t = seg.get(e, s) + B[idx];
			seg.upd(e, s+1, t);
			if(debug) printf("GET %lld\n", t);
		}
	}

	for(int i = 1; i <= N; i++)
		printf("%lld ", seg.get(i, i) + (1 == A[i] ? B[i] : 0));
	puts("");
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 41464 KB Output is correct
2 Correct 40 ms 41464 KB Output is correct
3 Correct 45 ms 41520 KB Output is correct
4 Correct 57 ms 41596 KB Output is correct
5 Correct 42 ms 41628 KB Output is correct
6 Correct 43 ms 41628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 41464 KB Output is correct
2 Correct 40 ms 41464 KB Output is correct
3 Correct 45 ms 41520 KB Output is correct
4 Correct 57 ms 41596 KB Output is correct
5 Correct 42 ms 41628 KB Output is correct
6 Correct 43 ms 41628 KB Output is correct
7 Correct 44 ms 41628 KB Output is correct
8 Correct 56 ms 41628 KB Output is correct
9 Correct 59 ms 41628 KB Output is correct
10 Correct 47 ms 41684 KB Output is correct
11 Correct 53 ms 41832 KB Output is correct
12 Correct 51 ms 41976 KB Output is correct
13 Correct 43 ms 41976 KB Output is correct
14 Correct 47 ms 41996 KB Output is correct
15 Correct 52 ms 42092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 41464 KB Output is correct
2 Correct 40 ms 41464 KB Output is correct
3 Correct 45 ms 41520 KB Output is correct
4 Correct 57 ms 41596 KB Output is correct
5 Correct 42 ms 41628 KB Output is correct
6 Correct 43 ms 41628 KB Output is correct
7 Correct 44 ms 41628 KB Output is correct
8 Correct 56 ms 41628 KB Output is correct
9 Correct 59 ms 41628 KB Output is correct
10 Correct 47 ms 41684 KB Output is correct
11 Correct 53 ms 41832 KB Output is correct
12 Correct 51 ms 41976 KB Output is correct
13 Correct 43 ms 41976 KB Output is correct
14 Correct 47 ms 41996 KB Output is correct
15 Correct 52 ms 42092 KB Output is correct
16 Correct 75 ms 43292 KB Output is correct
17 Correct 215 ms 49796 KB Output is correct
18 Correct 984 ms 75040 KB Output is correct
19 Correct 1230 ms 86524 KB Output is correct
20 Execution timed out 1589 ms 142916 KB Time limit exceeded
21 Halted 0 ms 0 KB -