Submission #72855

#TimeUsernameProblemLanguageResultExecution timeMemory
72855cki86201Gorgeous Pill (FXCUP3_gorgeous)C++11
100 / 100
540 ms31124 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...