Submission #971804

#TimeUsernameProblemLanguageResultExecution timeMemory
971804nguyentunglamMeasures (CEOI22_measures)C++17
0 / 100
80 ms35512 KiB
#include<bits/stdc++.h> #define all(v) v.begin(), v.end() #define endl "\n" using namespace std; const int N = 4e5 + 30; int n, m, d; int a[N]; long long T[4][N << 2]; void up(int s, int l, int r, int pos, int val) { if (l == r) { T[0][s] = 1; T[1][s] = val; T[2][s] = d -val; return; } int mid = l + r >> 1; if (pos <= mid) up(s << 1, l, mid, pos, val); else up(s << 1 | 1, mid + 1, r, pos, val); T[0][s] = T[0][s << 1] + T[0][s << 1 | 1]; T[1][s] = max(T[1][s << 1 | 1], T[1][s << 1] + T[0][s << 1 | 1] * d); T[2][s] = max(T[2][s << 1], T[2][s << 1 | 1] + T[0][s << 1] * d); T[3][s] = max({T[3][s << 1], T[3][s << 1 | 1], T[1][s << 1] + T[2][s << 1 | 1]}); } int32_t main() { #define task "" cin.tie(0) -> sync_with_stdio(0); if (fopen("task.inp", "r")) { freopen("task.inp", "r", stdin); freopen("task.out", "w", stdout); } if (fopen(task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } cin >> n >> m >> d; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = n + 1; i <= n + m; i++) cin >> a[i]; vector<pair<int, int> > rrh; for(int i = 1; i <= n + m; i++) rrh.emplace_back(a[i], i); sort(all(rrh)); rrh.resize(unique(all(rrh)) - rrh.begin()); for(int i = 1; i <= 4 * (n + m); i++) T[0][i] = T[1][i] = T[2][i] = -1e18; auto update = [&] (int i) { int pos = upper_bound(all(rrh), make_pair(a[i], i)) - rrh.begin(); // cout << pos << endl; up(1, 1, n + m, pos, a[i]); }; for(int i = 1; i <= n; i++) update(i); for(int i = n + 1; i <= n + m; i++) { update(i); cout << T[3][1] / 2; if (T[3][1] % 2) cout << ".5"; cout << " "; } }

Compilation message (stderr)

Main.cpp: In function 'void up(int, int, int, int, int)':
Main.cpp:21:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |   int mid = l + r >> 1;
      |             ~~^~~
Main.cpp: In function 'int32_t main()':
Main.cpp:36:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     freopen("task.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     freopen("task.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:41:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     freopen (task".inp", "r", stdin);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:42:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     freopen (task".out", "w", stdout);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...