Submission #72855

# Submission time Handle Problem Language Result Execution time Memory
72855 2018-08-27T05:51:24 Z cki86201 Gorgeous Pill (FXCUP3_gorgeous) C++11
100 / 100
540 ms 31124 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ldouble;

int N, C[300030], D[300030];
vector <pii> seg[300030];

ll T[2][1<<20];
const int ADD = 1<<19;

void update(int x, ll v) {
	x += ADD; T[0][x] = max(T[0][x], v); x >>= 1;
	while(x) T[0][x] = max(T[0][x<<1], T[0][x<<1|1]), x >>= 1;
}

ll read(int l, int r) {
	l += ADD, r += ADD;
	ll res = 0;
	while(l <= r) {
		if(l & 1) res = max(res, T[0][l++]);
		if(!(r & 1)) res = max(res, T[0][r--]);
		l >>= 1, r >>= 1;
	}
	return res;
}

void update2(int l, int r, ll val) {
	l += ADD, r += ADD;
	while(l <= r) {
		if(l & 1) T[1][l] = max(T[1][l], val);
		if(!(r & 1)) T[1][r] = max(T[1][r], val);
		l = (l + 1) >> 1, r = (r - 1) >> 1;
	}
}

ll read2(int x) {
	x += ADD;
	ll res = 0;
	while(x) res = max(res, T[1][x]), x >>= 1;
	return res;
}

int main() {
	scanf("%d", &N);
	for(int i=1;i<=N;i++) scanf("%d", C + i);
	for(int i=1;i<=N;i++) scanf("%d", D + i);
	for(int i=1;i<=N;i++) if(C[i] > 1) {
		if(i + C[i] - 1 <= N) seg[i].pb(pii(i + C[i] - 1, i));
		if(i - C[i] + 1 >= 1) seg[i - C[i] + 1].pb(pii(i, i));
	}
	for(int i=1;i<=N;i++) {
		sort(all(seg[i]));
		reverse(all(seg[i]));
	}
	for(int i=1;i<=N;i++) {
		vector <pll> upd;
		rep(j, szz(seg[i])) {
			ll val = read(seg[i][j].Fi, N) + D[seg[i][j].Se];
			
			if(i == seg[i][j].Se) update2(i, i, val - D[seg[i][j].Se]), update2(i + 1, seg[i][j].Fi, val);
			else update2(seg[i][j].Fi, seg[i][j].Fi, val - D[seg[i][j].Se]), update2(i, seg[i][j].Fi - 1, val);
			
			if(seg[i][j].Se != i) update(seg[i][j].Fi - 1, val);
			else upd.pb(pll(seg[i][j].Fi, val));
		}
		for(pll e : upd) update((int)e.Fi, e.Se);
	}
	for(int i=1;i<=N;i++) printf("%lld ", (C[i] == 1 ? D[i] : 0) + read2(i)); puts("");
	
	return 0;
}

Compilation message

gorgeous.cpp: In function 'int main()':
gorgeous.cpp:96:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  for(int i=1;i<=N;i++) printf("%lld ", (C[i] == 1 ? D[i] : 0) + read2(i)); puts("");
  ^~~
gorgeous.cpp:96:76: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  for(int i=1;i<=N;i++) printf("%lld ", (C[i] == 1 ? D[i] : 0) + read2(i)); puts("");
                                                                            ^~~~
gorgeous.cpp:72:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
gorgeous.cpp:73:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=N;i++) scanf("%d", C + i);
                        ~~~~~^~~~~~~~~~~~~
gorgeous.cpp:74:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=N;i++) scanf("%d", D + i);
                        ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7416 KB Output is correct
2 Correct 10 ms 7652 KB Output is correct
3 Correct 9 ms 7652 KB Output is correct
4 Correct 9 ms 7652 KB Output is correct
5 Correct 9 ms 7652 KB Output is correct
6 Correct 10 ms 7704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7416 KB Output is correct
2 Correct 10 ms 7652 KB Output is correct
3 Correct 9 ms 7652 KB Output is correct
4 Correct 9 ms 7652 KB Output is correct
5 Correct 9 ms 7652 KB Output is correct
6 Correct 10 ms 7704 KB Output is correct
7 Correct 11 ms 7704 KB Output is correct
8 Correct 9 ms 7704 KB Output is correct
9 Correct 10 ms 7704 KB Output is correct
10 Correct 9 ms 7752 KB Output is correct
11 Correct 11 ms 7752 KB Output is correct
12 Correct 12 ms 7792 KB Output is correct
13 Correct 11 ms 7792 KB Output is correct
14 Correct 11 ms 7816 KB Output is correct
15 Correct 10 ms 7872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7416 KB Output is correct
2 Correct 10 ms 7652 KB Output is correct
3 Correct 9 ms 7652 KB Output is correct
4 Correct 9 ms 7652 KB Output is correct
5 Correct 9 ms 7652 KB Output is correct
6 Correct 10 ms 7704 KB Output is correct
7 Correct 11 ms 7704 KB Output is correct
8 Correct 9 ms 7704 KB Output is correct
9 Correct 10 ms 7704 KB Output is correct
10 Correct 9 ms 7752 KB Output is correct
11 Correct 11 ms 7752 KB Output is correct
12 Correct 12 ms 7792 KB Output is correct
13 Correct 11 ms 7792 KB Output is correct
14 Correct 11 ms 7816 KB Output is correct
15 Correct 10 ms 7872 KB Output is correct
16 Correct 14 ms 8088 KB Output is correct
17 Correct 34 ms 9496 KB Output is correct
18 Correct 158 ms 14784 KB Output is correct
19 Correct 192 ms 16812 KB Output is correct
20 Correct 480 ms 28696 KB Output is correct
21 Correct 535 ms 29612 KB Output is correct
22 Correct 526 ms 29740 KB Output is correct
23 Correct 516 ms 29772 KB Output is correct
24 Correct 540 ms 29772 KB Output is correct
25 Correct 300 ms 31124 KB Output is correct