Submission #73834

# Submission time Handle Problem Language Result Execution time Memory
73834 2018-08-29T06:14:46 Z 김세빈(#2276) Gorgeous Pill (FXCUP3_gorgeous) C++11
100 / 100
498 ms 28944 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pll;

vector <ll> V[303030];
vector <pll> X;
ll T[1010101];
ll C[303030], D[303030];
ll n, sz;

ll get_max(ll l, ll r)
{
	ll ret = 0;
	l += sz, r += sz;
	
	for(; l<r; ){
		if(l & 1) ret = max(ret, T[l]);
		if(~r & 1) ret = max(ret, T[r]);
		l = l + 1 >> 1;
		r = r - 1 >> 1;
	}
	if(l == r) ret = max(ret, T[l]);
	
	return ret;
}

void update(ll p, ll v)
{
	p += sz; T[p] = max(T[p], v);
	
	for(p>>=1; p; p>>=1) T[p] = max(T[p << 1], T[p << 1 | 1]);
}

int main()
{
	ll i, j, r, k;
	
	scanf("%lld", &n);
	
	for(sz=1; sz<=n; sz<<=1);
	
	for(i=1; i<=n; i++){
		scanf("%lld", C + i);
		if(i - C[i] + 1 >= 1) V[i - C[i] + 1].push_back(i);
		if(i + C[i] - 1 <= n) V[i].push_back(i);
	}
	
	for(i=1; i<=n; i++){
		scanf("%lld", D + i);
	}
	
	for(i=1; i<=n; i++){
		sort(V[i].begin(), V[i].end(), [&](ll &ca, ll &cb){
			return C[ca] > C[cb];
		});
		
		X.clear();
		
		for(ll &t: V[i]){
			if(i == t){
				r = t + C[t] - 1;
				k = get_max(r, n) + D[t];
				X.emplace_back(r, k);
			}
			else{
				k = get_max(t, n) + D[t];
				update(t - 1, k);
			}
		}
		
		printf("%lld ", get_max(i, n) + (C[i] == 1) * D[i]);
		
		for(pll &p: X){
			update(p.first, p.second);
		}
	}
	
	printf("\n");
	
	return 0;
}

Compilation message

gorgeous.cpp: In function 'll get_max(ll, ll)':
gorgeous.cpp:22:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   l = l + 1 >> 1;
       ~~^~~
gorgeous.cpp:23:9: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   r = r - 1 >> 1;
       ~~^~~
gorgeous.cpp: In function 'int main()':
gorgeous.cpp:39:8: warning: unused variable 'j' [-Wunused-variable]
  ll i, j, r, k;
        ^
gorgeous.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &n);
  ~~~~~^~~~~~~~~~~~
gorgeous.cpp:46:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", C + i);
   ~~~~~^~~~~~~~~~~~~~~
gorgeous.cpp:52:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", D + i);
   ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 10 ms 7524 KB Output is correct
3 Correct 9 ms 7604 KB Output is correct
4 Correct 9 ms 7676 KB Output is correct
5 Correct 11 ms 7676 KB Output is correct
6 Correct 10 ms 7676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 10 ms 7524 KB Output is correct
3 Correct 9 ms 7604 KB Output is correct
4 Correct 9 ms 7676 KB Output is correct
5 Correct 11 ms 7676 KB Output is correct
6 Correct 10 ms 7676 KB Output is correct
7 Correct 9 ms 7676 KB Output is correct
8 Correct 8 ms 7676 KB Output is correct
9 Correct 9 ms 7676 KB Output is correct
10 Correct 10 ms 7676 KB Output is correct
11 Correct 9 ms 7788 KB Output is correct
12 Correct 10 ms 7804 KB Output is correct
13 Correct 10 ms 7804 KB Output is correct
14 Correct 12 ms 7908 KB Output is correct
15 Correct 9 ms 7908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 10 ms 7524 KB Output is correct
3 Correct 9 ms 7604 KB Output is correct
4 Correct 9 ms 7676 KB Output is correct
5 Correct 11 ms 7676 KB Output is correct
6 Correct 10 ms 7676 KB Output is correct
7 Correct 9 ms 7676 KB Output is correct
8 Correct 8 ms 7676 KB Output is correct
9 Correct 9 ms 7676 KB Output is correct
10 Correct 10 ms 7676 KB Output is correct
11 Correct 9 ms 7788 KB Output is correct
12 Correct 10 ms 7804 KB Output is correct
13 Correct 10 ms 7804 KB Output is correct
14 Correct 12 ms 7908 KB Output is correct
15 Correct 9 ms 7908 KB Output is correct
16 Correct 13 ms 8076 KB Output is correct
17 Correct 34 ms 9372 KB Output is correct
18 Correct 113 ms 13980 KB Output is correct
19 Correct 149 ms 15772 KB Output is correct
20 Correct 406 ms 26556 KB Output is correct
21 Correct 408 ms 27368 KB Output is correct
22 Correct 469 ms 27456 KB Output is correct
23 Correct 493 ms 27456 KB Output is correct
24 Correct 498 ms 27456 KB Output is correct
25 Correct 310 ms 28944 KB Output is correct