Submission #520420

#TimeUsernameProblemLanguageResultExecution timeMemory
520420keta_tsimakuridzeHoliday (IOI14_holiday)C++14
100 / 100
1479 ms19368 KiB
#include"holiday.h" #include<bits/stdc++.h> #define f first #define s second #define ll long long #define pii pair<ll,ll> using namespace std; const int N = 3e5 + 5; int a[N], val[N], cur = 0; ll dp[3][2][N]; pii tree[4 * N]; void upd(int u, int id, int l, int r, int t) { if(l > id || r < id) return; if(l == r) { tree[u].f += t; tree[u].s += val[l] * t; return; } int mid = (l + r) / 2; upd(2 * u, id, l, mid, t); upd(2 * u + 1, id, mid + 1, r, t); tree[u].f = tree[2 * u].f + tree[2 * u + 1].f; tree[u].s = tree[2 * u].s + tree[2 * u + 1].s; } ll get(int u, int l, int r, int k) { if(!k) return 0; if(l == r) { return (ll) min(tree[u].f, (ll)k) * val[l]; } int mid = (l + r) / 2; if(tree[2 * u + 1].f > k) { return get(2 * u + 1, mid + 1, r, k); } return tree[2 * u + 1].s + get(2 * u, l, mid, k - tree[2 * u + 1].f); } ll get(int x) { if(x < 0) return -1e5; return get(1, 1, cur, x); } void solve(int optl, int optr, int l, int r,int price, int t) { if(l > r || optl > optr) return; int mid = (l + r) / 2; //cout << l << "__" << r << endl; ll opt = 0, optm = optl; for(int i = optl; i <= optr; i++) { upd(1, a[i], 1, cur, 1); if(opt <= get(mid - (ll)i * price)) { opt = get(mid - (ll)i * price); optm = i; } } dp[price][t][mid] = opt; for(int i = optm; i <= optr; i++) upd(1, a[i], 1, cur, -1); if(l != r) solve(optm, optr, mid + 1, r, price, t); for(int i = optl; i < optm; i++) upd(1, a[i], 1, cur, -1); if(l != r) solve(optl, optm, l, mid - 1, price, t); } long long findMaxAttraction(int n, int start, int d, int attraction[]) { vector<int> x; ll sum = 0; for(int i = 0; i < n; i++) x.push_back(attraction[i]), sum += attraction[i]; sort(x.begin(), x.end()); cur =0 ; map<int,int> id; for(int i = 0; i < x.size(); i++) { if(!i || x[i] != x[i - 1]) ++cur; id[x[i]] = cur; val[cur] = x[i]; } for(int i = 0; i < n; i++) attraction[i] = id[attraction[i]]; for(int i = 0; i < n - start; i++) a[i] = attraction[i + start]; solve(0, n - start - 1, 1, d, 1, 0); solve(0, n - start - 1, 1, d, 2, 0); for(int i = start - 1; i >= 0; i--) a[start - 1 - i] = attraction[i]; solve(0, start - 1, 1, d, 1, 1); solve(0, start - 1, 1, d, 2, 1); for(int i = d; i >= 1; i--) { dp[1][1][i] = dp[1][1][i - 1]; if(i == 1) dp[2][1][i] = 0; else dp[2][1][i] = dp[2][1][i - 2]; } ll ans = 0; for(int i = 0; i <= d; i++) { ans = max(ans, dp[1][0][i] + dp[2][1][d - i]); ans = max(ans, dp[2][0][i] + dp[1][1][d - i]); } return ans; }

Compilation message (stderr)

holiday.cpp: In function 'long long int findMaxAttraction(int, int, int, int*)':
holiday.cpp:67:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |  for(int i = 0; i < x.size(); i++) {
      |                 ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...