제출 #1077840

#제출 시각아이디문제언어결과실행 시간메모리
1077840steveonalex휴가 (IOI14_holiday)C++17
30 / 100
785 ms4676 KiB
#include "holiday.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define MASK(i) (1LL << (i)) #define GETBIT(mask, i) (((mask) >> (i)) & 1) #define ALL(v) (v).begin(), (v).end() #define block_of_code if(true) ll max(ll a, ll b){return (a > b) ? a : b;} ll min(ll a, ll b){return (a < b) ? a : b;} ll gcd(ll a, ll b){return __gcd(a, b);} ll lcm(ll a, ll b){return a / gcd(a, b) * b;} ll LASTBIT(ll mask){return (mask) & (-mask);} int pop_cnt(ll mask){return __builtin_popcountll(mask);} int ctz(ull mask){return __builtin_ctzll(mask);} int logOf(ull mask){return 63 - __builtin_clzll(mask);} mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);} double rngesus_d(double l, double r){ double cur = rngesus(0, MASK(60) - 1); cur /= MASK(60) - 1; return l + cur * (r - l); } template <class T1, class T2> bool maximize(T1 &a, T2 b){ if (a < b) {a = b; return true;} return false; } template <class T1, class T2> bool minimize(T1 &a, T2 b){ if (a > b) {a = b; return true;} return false; } template <class T> void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){ for(auto item: container) out << item << separator; out << finish; } template <class T> void remove_dup(vector<T> &a){ sort(ALL(a)); a.resize(unique(ALL(a)) - a.begin()); } struct FenwickTree{ int n; vector<ll> a; FenwickTree(int _n){ n = _n; a.resize(n+1); } void update(int i, ll v){ while(i <= n){ a[i] += v; i += LASTBIT(i); } } ll get(int i){ ll ans = 0; while(i > 0){ ans += a[i]; i -= LASTBIT(i); } return ans; } int lower_bound(ll v){ int p = MASK(logOf(n)), idx = 0; while(p > 0){ if (idx + p < n && v > a[idx + p]){ idx += p; v -= a[idx]; } p >>= 1; } return idx + 1; } }; ll what(int n, int s, int d, int a[], int l){ vector<pair<int, int>> b(n); for(int i = 0; i<n; ++i) b[i] = {a[i], i}; sort(ALL(b), greater<pair<int, int>>()); vector<int> pos(n); for(int i = 0; i<n; ++i) pos[b[i].second] = i; ll ans = 0; for(int x = 0; x <= 1; ++x){ FenwickTree bit(n), sum(n); for(int i = s + 1; i < n; ++i) { bit.update(pos[i] + 1, 1); sum.update(pos[i] + 1, a[i]); } int r = n-1; for(int i = s; i>=0; --i){ bit.update(pos[i] + 1, 1); sum.update(pos[i] + 1, a[i]); int dis1 = s - i; int dis2 = l - dis1 * 2; if (dis2 < 0) break; while(r > s + dis2){ bit.update(pos[r] + 1, -1); sum.update(pos[r] + 1, -a[r]); r--; } if (r < s) continue; maximize(ans, sum.get(bit.lower_bound(d - l))); } reverse(ALL(pos)); reverse(a, a + n); s = n - s - 1; } return ans; } ll findMaxAttraction(int n, int start, int d, int a[]){ ll ans = 0; // for(int i = 0; i<d; ++i) cout << what(n, start, d, a, i) << " "; cout << "\n"; int l = 0, r = d - 1; while(r - l >= 3){ int m1 = l + (r - l) / 3; int m2 = r - (r - l) / 3; ll v1 = what(n, start, d, a, m1); ll v2 = what(n, start, d, a, m2); if (v1 > v2) r = m2; else l = m1; } for(int i = l; i<=r; ++i) maximize(ans, what(n, start, d, a, i)); return ans; } // int main(void){ // ios::sync_with_stdio(0);cin.tie(0); cout.tie(0); // clock_t start = clock(); // int n, s, d; // cin >> n >> s >> d; // int attraction[n]; // for(int i = 0; i<n; ++i) cin >> attraction[i]; // cout << findMaxAttraction(n, s, d, attraction) << "\n"; // cerr << "Time elapsed: " << clock() - start << " ms\n"; // return 0; // }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...