Submission #72852

# Submission time Handle Problem Language Result Execution time Memory
72852 2018-08-27T05:37:50 Z cki86201 Gorgeous Pill (FXCUP3_gorgeous) C++11
0 / 100
12 ms 7648 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(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].Fi) update2(i, i, val);
			else {
				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);
			}
			upd.pb(pll(seg[i][j].Fi, val));
			if(j == szz(seg[i]) - 1 || seg[i][j].Fi != seg[i][j+1].Fi) {
				for(pll e : upd) update((int)e.Fi, e.Se);
				upd.clear();
			}
		}
	}
	for(int i=1;i<=N;i++) printf("%lld ", read2(i)); puts("");
	
	return 0;
}

Compilation message

gorgeous.cpp: In function 'int main()':
gorgeous.cpp:99:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  for(int i=1;i<=N;i++) printf("%lld ", read2(i)); puts("");
  ^~~
gorgeous.cpp:99:51: 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 ", 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 12 ms 7416 KB Output is correct
2 Correct 8 ms 7536 KB Output is correct
3 Incorrect 10 ms 7648 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 7416 KB Output is correct
2 Correct 8 ms 7536 KB Output is correct
3 Incorrect 10 ms 7648 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 7416 KB Output is correct
2 Correct 8 ms 7536 KB Output is correct
3 Incorrect 10 ms 7648 KB Output isn't correct
4 Halted 0 ms 0 KB -