Submission #648557

#TimeUsernameProblemLanguageResultExecution timeMemory
648557ghostwriterHoliday (IOI14_holiday)C++14
47 / 100
198 ms3412 KiB
#include"holiday.h" #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <debug.h> #include "grader.cpp" #else #define debug(...) #endif #define ft front #define bk back #define st first #define nd second #define ins insert #define ers erase #define pb push_back #define pf push_front #define _pb pop_back #define _pf pop_front #define lb lower_bound #define ub upper_bound #define mtp make_tuple #define bg begin #define ed end #define all(x) (x).bg(), (x).ed() #define sz(x) (int)(x).size() typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef string str; template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i)) #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i)) #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i)) #define FSN(i, n) for (int (i) = (n) - 1; (i) >= 0; --(i)) #define EACH(i, x) for (auto &(i) : (x)) #define WHILE while #define file "TEST" mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); } /* ---------------------------------------------------------------- END OF TEMPLATE ---------------------------------------------------------------- Tran The Bao - ghostwriter Training for VOI23 gold medal ---------------------------------------------------------------- DIT ME CHUYEN BAO LOC ---------------------------------------------------------------- */ namespace subtask13 { const int N = 3005; int pos[N]; pi a[N]; pll f[N]; ll rs = 0; void upd(int pos, pi v) { ++pos; for (int i = pos; i < N; i += (i & -i)) { f[i].st += v.st; f[i].nd += v.nd; } } pll get(int pos) { ++pos; pll rs = {0, 0}; for (int i = pos; i > 0; i -= (i & -i)) { rs.st += f[i].st; rs.nd += f[i].nd; } return rs; } int getpos(int x) { int cur = 0, cnt = 0, ans = N; FOS(i, 11, 0) { if (cur + (1 << i) >= N) continue; if (cnt + f[cur + (1 << i)].st >= x) ans = min(ans, cur + (1 << i)); else { cur |= 1 << i; cnt += f[cur].st; } } return ans - 1; } ll findMaxAttraction(int n, int start, int d, int attraction[]) { FRN(i, n) a[i] = {attraction[i], i}; sort(a, a + n, greater<pi>()); FRN(i, n) pos[a[i].nd] = i; FRN(i, n) { FOR(j, i, n - 1) { upd(pos[j], {1, attraction[j]}); int mv; if (j < start || i > start) continue; if (i == start) mv = j - start; else if (j == start) mv = start - i; else mv = min(2 * (start - i) + j - start, 2 * (j - start) + start - i); if (mv > d) continue; int rm = min(d - mv, j - i + 1), pos = getpos(rm); rs = max(rs, get(pos).nd); } FOR(j, i, n - 1) upd(pos[j], {-1, -attraction[j]}); } return rs; } } namespace subtask2 { const int N = 1e5 + 5; int pos[N]; pi a[N]; pll f[N]; ll rs = 0; void upd(int pos, pi v) { ++pos; for (int i = pos; i < N; i += (i & -i)) { f[i].st += v.st; f[i].nd += v.nd; } } pll get(int pos) { ++pos; pll rs = {0, 0}; for (int i = pos; i > 0; i -= (i & -i)) { rs.st += f[i].st; rs.nd += f[i].nd; } return rs; } int getpos(int x) { int cur = 0, cnt = 0, ans = N; FOS(i, 16, 0) { if (cur + (1 << i) >= N) continue; if (cnt + f[cur + (1 << i)].st >= x) ans = min(ans, cur + (1 << i)); else { cur |= 1 << i; cnt += f[cur].st; } } return ans - 1; } ll findMaxAttraction(int n, int start, int d, int attraction[]) { FRN(i, n) a[i] = {attraction[i], i}; sort(a, a + n, greater<pi>()); FRN(i, n) pos[a[i].nd] = i; FRN(i, n) { upd(pos[i], {1, attraction[i]}); int mv = i - start; if (mv > d) break; int rm = d - mv, pos = getpos(rm); rs = max(rs, get(pos).nd); } return rs; } } long long int findMaxAttraction(int n, int start, int d, int attraction[]) { if (n <= 3000) return subtask13::findMaxAttraction(n, start, d, attraction); if (start == 0) return subtask2::findMaxAttraction(n, start, d, attraction); return 0; } /* 5 2 7 10 2 20 30 1 ---------------------------------------------------------------- From Benq: stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH ---------------------------------------------------------------- */

Compilation message (stderr)

holiday.cpp: In function 'int subtask13::getpos(int)':
holiday.cpp:35:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   35 | #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
      |                               ^
holiday.cpp:63:9: note: in expansion of macro 'FOS'
   63 |         FOS(i, 11, 0) {
      |         ^~~
holiday.cpp: In function 'll subtask13::findMaxAttraction(int, int, int, int*)':
holiday.cpp:36:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   36 | #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
holiday.cpp:74:9: note: in expansion of macro 'FRN'
   74 |         FRN(i, n) a[i] = {attraction[i], i};
      |         ^~~
holiday.cpp:36:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   36 | #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
holiday.cpp:76:9: note: in expansion of macro 'FRN'
   76 |         FRN(i, n) pos[a[i].nd] = i;
      |         ^~~
holiday.cpp:36:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   36 | #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
holiday.cpp:77:9: note: in expansion of macro 'FRN'
   77 |         FRN(i, n) {
      |         ^~~
holiday.cpp:34:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   34 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
holiday.cpp:78:13: note: in expansion of macro 'FOR'
   78 |             FOR(j, i, n - 1) {
      |             ^~~
holiday.cpp:34:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   34 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
holiday.cpp:89:13: note: in expansion of macro 'FOR'
   89 |             FOR(j, i, n - 1) upd(pos[j], {-1, -attraction[j]});
      |             ^~~
holiday.cpp: In function 'int subtask2::getpos(int)':
holiday.cpp:35:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   35 | #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
      |                               ^
holiday.cpp:104:9: note: in expansion of macro 'FOS'
  104 |         FOS(i, 16, 0) {
      |         ^~~
holiday.cpp: In function 'll subtask2::findMaxAttraction(int, int, int, int*)':
holiday.cpp:36:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   36 | #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
holiday.cpp:115:9: note: in expansion of macro 'FRN'
  115 |         FRN(i, n) a[i] = {attraction[i], i};
      |         ^~~
holiday.cpp:36:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   36 | #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
holiday.cpp:117:9: note: in expansion of macro 'FRN'
  117 |         FRN(i, n) pos[a[i].nd] = i;
      |         ^~~
holiday.cpp:36:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   36 | #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
holiday.cpp:118:9: note: in expansion of macro 'FRN'
  118 |         FRN(i, n) {
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...