Submission #73806

# Submission time Handle Problem Language Result Execution time Memory
73806 2018-08-29T04:33:22 Z 윤교준(#2277) Gorgeous Pill (FXCUP3_gorgeous) C++11
51 / 100
1500 ms 133740 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;
}

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 = newll(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() {
	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]) }

	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(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:114: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);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 51 ms 41300 KB Output is correct
2 Correct 53 ms 41456 KB Output is correct
3 Correct 51 ms 41524 KB Output is correct
4 Correct 45 ms 41524 KB Output is correct
5 Correct 44 ms 41592 KB Output is correct
6 Correct 44 ms 41600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 41300 KB Output is correct
2 Correct 53 ms 41456 KB Output is correct
3 Correct 51 ms 41524 KB Output is correct
4 Correct 45 ms 41524 KB Output is correct
5 Correct 44 ms 41592 KB Output is correct
6 Correct 44 ms 41600 KB Output is correct
7 Correct 55 ms 41600 KB Output is correct
8 Correct 56 ms 41636 KB Output is correct
9 Correct 47 ms 41636 KB Output is correct
10 Correct 51 ms 41788 KB Output is correct
11 Correct 48 ms 41968 KB Output is correct
12 Correct 50 ms 41968 KB Output is correct
13 Correct 48 ms 41968 KB Output is correct
14 Correct 49 ms 42060 KB Output is correct
15 Correct 54 ms 42060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 41300 KB Output is correct
2 Correct 53 ms 41456 KB Output is correct
3 Correct 51 ms 41524 KB Output is correct
4 Correct 45 ms 41524 KB Output is correct
5 Correct 44 ms 41592 KB Output is correct
6 Correct 44 ms 41600 KB Output is correct
7 Correct 55 ms 41600 KB Output is correct
8 Correct 56 ms 41636 KB Output is correct
9 Correct 47 ms 41636 KB Output is correct
10 Correct 51 ms 41788 KB Output is correct
11 Correct 48 ms 41968 KB Output is correct
12 Correct 50 ms 41968 KB Output is correct
13 Correct 48 ms 41968 KB Output is correct
14 Correct 49 ms 42060 KB Output is correct
15 Correct 54 ms 42060 KB Output is correct
16 Correct 93 ms 43292 KB Output is correct
17 Correct 287 ms 49256 KB Output is correct
18 Correct 1287 ms 72808 KB Output is correct
19 Correct 1493 ms 82404 KB Output is correct
20 Execution timed out 1589 ms 133740 KB Time limit exceeded
21 Halted 0 ms 0 KB -