제출 #298015

#제출 시각아이디문제언어결과실행 시간메모리
298015miss_robot휴가 (IOI14_holiday)C++14
100 / 100
2195 ms60448 KiB
#include <bits/stdc++.h> #include"holiday.h" #pragma GCC optimize("Ofast") #define ll long long using namespace std; const int L = 131072; vector<int> t[2*L]; vector<ll> p[2*L]; ll qry(int i, int l, int r, int k){ if(k <= 0) return 0; if(i >= L) return p[i][k-1]; int a = lower_bound(t[i].begin(), t[i].end(), l)-t[i].begin(), b = upper_bound(t[i].begin(), t[i].end(), r)-t[i].begin(); if(b-a == k) return p[i][b-1] - (a?p[i][a-1]:0); a = lower_bound(t[i<<1|1].begin(), t[i<<1|1].end(), l)-t[i<<1|1].begin(), b = upper_bound(t[i<<1|1].begin(), t[i<<1|1].end(), r)-t[i<<1|1].begin(); return qry(i<<1, l, r, k-(b-a)) + qry(i<<1|1, l, r, min(k, b-a)); } ll sum(int l, int r, int k){ // summe der k maximalen elemente im intervall [l, r] k = min(k, r-l+1); return qry(1, l, r, k); } void div1(int s, int d, int l, int r, int optl, int optr, ll& sol){ // erst nach rechts dann nach links if(l > r) return; ll best = -1; int opt = -1, m = (l+r)/2; for(int i = min(optr, max(optl, (d+s+2*m-1)/3)); i <= optr; i++){ ll temp = sum(m, i, d-2*(i-s)-(s-m)); if(temp > best) best = temp, opt = i; } sol = max(sol, best); div1(s, d, l, m-1, optl, opt, sol), div1(s, d, m+1, r, opt, optr, sol); } void div2(int s, int d, int l, int r, int optl, int optr, ll& sol){ // erst nach links dann nach rechts if(l > r) return; ll best = -1; int opt = -1, m = (l+r)/2; for(int i = optl; i <= max(optl, min(optr, (s-d+2*m+1)/3)); i++){ ll temp = sum(i, m, d-2*(s-i)-(m-s)); if(temp > best) best = temp, opt = i; } sol = max(sol, best); div2(s, d, l, m-1, optl, opt, sol), div2(s, d, m+1, r, opt, optr, sol); } ll findMaxAttraction(int n, int start, int d, int attraction[]){ map< int, vector<int> > m; for(int i = 0; i < n; i++) m[attraction[i]].push_back(i); int k = L, j; for(auto& tmp : m){ t[k] = tmp.second; for(auto& x : t[k]) p[k].push_back(tmp.first+(p[k].empty()?0:p[k].back())); k++; } for(int i = L-1; i; i--){ j = k = 0; while(j < (int)t[i<<1].size() && k < (int)t[i<<1|1].size()){ if(t[i<<1][j] < t[i<<1|1][k]) t[i].push_back(t[i<<1][j++]); else t[i].push_back(t[i<<1|1][k++]); p[i].push_back((j?p[i<<1][j-1]:0)+(k?p[i<<1|1][k-1]:0)); } while(j < (int)t[i<<1].size()){ t[i].push_back(t[i<<1][j++]); p[i].push_back((j?p[i<<1][j-1]:0)+(k?p[i<<1|1][k-1]:0)); } while(k < (int)t[i<<1|1].size()){ t[i].push_back(t[i<<1|1][k++]); p[i].push_back((j?p[i<<1][j-1]:0)+(k?p[i<<1|1][k-1]:0)); } } ll sol = 0; div1(start, d, 0, start, start, n-1, sol), div2(start, d, start, n-1, 0, start, sol); return sol; }

컴파일 시 표준 에러 (stderr) 메시지

holiday.cpp: In function 'long long int findMaxAttraction(int, int, int, int*)':
holiday.cpp:59:13: warning: unused variable 'x' [-Wunused-variable]
   59 |   for(auto& x : t[k]) p[k].push_back(tmp.first+(p[k].empty()?0:p[k].back()));
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...