結果
問題 | No.489 株に挑戦 |
ユーザー | koyumeishi |
提出日時 | 2017-02-24 23:35:03 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 802 ms / 1,000 ms |
コード長 | 9,440 bytes |
コンパイル時間 | 1,472 ms |
コンパイル使用メモリ | 123,532 KB |
実行使用メモリ | 132,580 KB |
最終ジャッジ日時 | 2024-07-19 23:07:19 |
合計ジャッジ時間 | 7,614 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 243 ms
100,816 KB |
testcase_01 | AC | 156 ms
66,116 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 3 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 3 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 3 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 16 ms
9,216 KB |
testcase_16 | AC | 239 ms
101,368 KB |
testcase_17 | AC | 49 ms
18,944 KB |
testcase_18 | AC | 134 ms
58,816 KB |
testcase_19 | AC | 109 ms
48,428 KB |
testcase_20 | AC | 281 ms
115,732 KB |
testcase_21 | AC | 68 ms
30,848 KB |
testcase_22 | AC | 27 ms
13,696 KB |
testcase_23 | AC | 179 ms
71,564 KB |
testcase_24 | AC | 329 ms
132,580 KB |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 802 ms
125,160 KB |
testcase_27 | AC | 353 ms
121,960 KB |
testcase_28 | AC | 2 ms
5,376 KB |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | AC | 329 ms
132,456 KB |
testcase_31 | AC | 288 ms
125,288 KB |
testcase_32 | AC | 174 ms
71,952 KB |
testcase_33 | AC | 316 ms
126,880 KB |
testcase_34 | AC | 270 ms
111,968 KB |
testcase_35 | AC | 108 ms
47,408 KB |
testcase_36 | AC | 45 ms
21,632 KB |
testcase_37 | AC | 168 ms
70,260 KB |
コンパイルメッセージ
In function 'void {anonymous}::print(const H&) [with H = int]', inlined from 'void {anonymous}::print(const H&, const T& ...) [with H = int; T = {int}]' at main.cpp:30:106, inlined from 'void {anonymous}::println(const T& ...) [with T = {int, int}]' at main.cpp:31:65, inlined from 'int main()' at main.cpp:338:10: main.cpp:29:53: warning: 'jj' may be used uninitialized [-Wmaybe-uninitialized] 29 | template<class H> void print(const H& head){ cout << head; } | ~~~~~^~~~~~~ main.cpp: In function 'int main()': main.cpp:325:10: note: 'jj' was declared here 325 | int ii,jj; | ^~ In function 'void {anonymous}::print(const H&, const T& ...) [with H = int; T = {int}]', inlined from 'void {anonymous}::println(const T& ...) [with T = {int, int}]' at main.cpp:31:65, inlined from 'int main()' at main.cpp:338:10: main.cpp:30:93: warning: 'ii' may be used uninitialized [-Wmaybe-uninitialized] 30 | template<class H, class ... T> void print(const H& head, const T& ... tail){ cout << head << " "; print(tail...); } | ~~~~~~~~~~~~~^~~~~~ main.cpp: In function 'int main()': main.cpp:325:7: note: 'ii' was declared here 325 | int ii,jj; | ^~
ソースコード
#include <iostream> #include <vector> #include <cstdio> #include <sstream> #include <map> #include <string> #include <algorithm> #include <queue> #include <cmath> #include <functional> #include <set> #include <ctime> #include <random> #include <chrono> #include <cassert> #include <tuple> #include <utility> using namespace std; namespace { using Integer = long long; //__int128; template<class T, class S> istream& operator >> (istream& is, pair<T,S>& p){return is >> p.first >> p.second;} template<class T> istream& operator >> (istream& is, vector<T>& vec){for(T& val: vec) is >> val; return is;} template<class T> istream& operator , (istream& is, T& val){ return is >> val;} template<class T, class S> ostream& operator << (ostream& os, const pair<T,S>& p){return os << p.first << " " << p.second;} template<class T> ostream& operator << (ostream& os, const vector<T>& vec){for(size_t i=0; i<vec.size(); i++) os << vec[i] << (i==vec.size()-1?"":" "); return os;} template<class T> ostream& operator , (ostream& os, const T& val){ return os << " " << val;} template<class H> void print(const H& head){ cout << head; } template<class H, class ... T> void print(const H& head, const T& ... tail){ cout << head << " "; print(tail...); } template<class ... T> void println(const T& ... values){ print(values...); cout << endl; } template<class H> void eprint(const H& head){ cerr << head; } template<class H, class ... T> void eprint(const H& head, const T& ... tail){ cerr << head << " "; eprint(tail...); } template<class ... T> void eprintln(const T& ... values){ eprint(values...); cerr << endl; } class range{ Integer start_, end_, step_; public: struct range_iterator{ Integer val, step_; range_iterator(Integer v, Integer step) : val(v), step_(step) {} Integer operator * (){return val;} void operator ++ (){val += step_;} bool operator != (range_iterator& x){return step_ > 0 ? val < x.val : val > x.val;} }; range(Integer len) : start_(0), end_(len), step_(1) {} range(Integer start, Integer end) : start_(start), end_(end), step_(1) {} range(Integer start, Integer end, Integer step) : start_(start), end_(end), step_(step) {} range_iterator begin(){ return range_iterator(start_, step_); } range_iterator end(){ return range_iterator( end_, step_); } }; inline string operator "" _s (const char* str, size_t size){ return move(string(str)); } constexpr Integer my_pow(Integer x, Integer k, Integer z=1){return k==0 ? z : k==1 ? z*x : (k&1) ? my_pow(x*x,k>>1,z*x) : my_pow(x*x,k>>1,z);} constexpr Integer my_pow_mod(Integer x, Integer k, Integer M, Integer z=1){return k==0 ? z%M : k==1 ? z*x%M : (k&1) ? my_pow_mod(x*x%M,k>>1,M,z*x%M) : my_pow_mod(x*x%M,k>>1,M,z);} constexpr unsigned long long operator "" _ten (unsigned long long value){ return my_pow(10,value); } inline int k_bit(Integer x, int k){return (x>>k)&1;} //0-indexed mt19937 mt(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()); template<class T> string join(const vector<T>& v, const string& sep){ stringstream ss; for(size_t i=0; i<v.size(); i++){ if(i>0) ss << sep; ss << v[i]; } return ss.str(); } inline string operator * (string s, int k){ string ret; while(k){ if(k&1) ret += s; s += s; k >>= 1; } return ret; } } constexpr long long mod = 9_ten + 7; class TrivialBitVector{ public: vector<int> v; vector<int> rank_; vector<int> select_0; vector<int> select_1; TrivialBitVector(vector<int>& v_) : v(v_){ rank_.resize(v.size()+1, 0); for(int i=1; i<=v.size(); i++){ rank_[i] = rank_[i-1] + v[i-1]; } for(int i=0; i<v.size(); i++){ (v[i] ? select_1 : select_0).push_back( i ); } } int at(int pos){ assert(0 <= pos && pos < v.size()); return v[pos]; } //count of q in [0, ub) int rank(int q, int ub){ assert(ub <= v.size()); int ret = rank_[ub]; if(q == 0) ret = ub - ret; return ret; } //the position of the (t+1)-th occurrence of q int select(int q, int t){ auto& s = q ? select_1 : select_0; if(t >= s.size()) return -1; return s[t]; } }; // T = unsigned int / unsigned long long // B = bitvector container type template<class T, class B> class WaveletMatrix{ vector<B> m; vector<int> L_size; T lg; //left most bit T mx; const int len; public: WaveletMatrix(vector<T>& v) : len(v.size()){ mx = *max_element(v.begin(), v.end()); lg = 0; while((T(1)<<lg+1) <= mx) lg++; m.reserve(lg+1); L_size.resize(lg+1); deque<int> l,r; l.resize(len); iota(l.begin(), l.end(), 0); for(int k=0; k<=lg; k++){ deque<int> l_, r_; vector<int> bits(len); L_size[k] = l.size(); for(int i=0; i<l.size(); i++){ bits[i] = (v[ l[i] ] >> (lg-k))&1; if( (v[ l[i] ] >> (lg-k))&1 ){ r_.push_back( l[i] ); }else{ l_.push_back( l[i] ); } } for(int i=0; i<r.size(); i++){ bits[l.size() + i] = (v[ r[i] ] >> (lg-k))&1; if( (v[ r[i] ] >> (lg-k))&1 ){ r_.push_back( r[i] ); }else{ l_.push_back( r[i] ); } } swap(l, l_); swap(r, r_); m.emplace_back(bits); /* for(int i=0; i<len; i++){ cerr << bits[i]; }cerr << endl; */ } } int count(T q, int lb, int ub){ return rank(q, ub, lb, 0); } int count_less_than(T q, int lb, int ub){ if(ub<=lb) return 0; if(q >= mx) return ub-lb; return rank_less_than_(q, lb, ub, 0); } //return t-th occurence position of q //if q is not in the list then return -1 int select(T q, int t){ if(q >= (T(1)<<lg+1)) return -1; return select(q,t, 0,len, 0); } //return (t+1)-th biggest {value, pos} in [lb,ub) pair<int,int> quantile(int lb, int ub, int t, int k=0){ if(t >= ub-lb) return {-1,-1}; int val = 0; int pos = lb; int r = m[k].rank(1, ub); int l = m[k].rank(1, lb); if(k==lg){ if(r-l > t){ pos = m[k].select(1, r-1 - t); return {1, pos}; }else{ pos = m[k].select(0, ub-1-t-l ); return {0, pos}; } } if( r-l > t ){ auto tmp = quantile(L_size[k+1] + l, L_size[k+1] + r, t, k+1); val = (T(1)<<(lg-k)) | tmp.first; pos = m[k].select(1, tmp.second - L_size[k+1]); }else{ auto tmp = quantile(lb-l, ub-r, t-(r-l), k+1); val = tmp.first; pos = m[k].select(0, tmp.second); } return {val, pos}; } int quantile_pos(int lb, int ub, int t, int k=0){ if(t >= ub-lb) return -1; int val = 0; int pos = lb; int r = m[k].rank(1, ub); int l = m[k].rank(1, lb); if(k==lg){ if(r-l > t){ return m[k].select(1, r-1 - t); }else{ return m[k].select(0, ub-1-t-l ); } } if( r-l > t ){ auto tmp = quantile_pos(L_size[k+1] + l, L_size[k+1] + r, t, k+1); pos = m[k].select(1, tmp - L_size[k+1]); }else{ auto tmp = quantile_pos(lb-l, ub-r, t-(r-l), k+1); pos = m[k].select(0, tmp); } return pos; } int quantile_val(int lb, int ub, int t, int k=0){ if(t >= ub-lb) return -1; int val = 0; int r = m[k].rank(1, ub); int l = m[k].rank(1, lb); if(k==lg){ if(r-l > t){ return 1; }else{ return 0; } } if( r-l > t ){ auto tmp = quantile_val(L_size[k+1] + l, L_size[k+1] + r, t, k+1); val = (T(1)<<(lg-k)) | tmp; }else{ auto tmp = quantile_val(lb-l, ub-r, t-(r-l), k+1); val = tmp; } return val; } private: //return count of the occurence of q in [0, ub) int rank(T q, int ub, int lb=0, int k=0){ if(q > mx) return 0; //ub = min(len, ub); int bit = (q>>lg-k) & 1; int r = m[k].rank(bit, ub); int l = m[k].rank(bit, lb); if(k==lg) return r - l; if(bit == 0){ return rank(q, r, l, k+1); }else{ return rank(q, L_size[k+1] + r, L_size[k+1] + l, k+1); } } int rank_less_than_(T q, int lb, int ub, int k=0){ if(q >= mx) return ub-lb; int res = 0; int bit = (q>>lg-k) & 1; int r = m[k].rank(bit, ub); int l = m[k].rank(bit, lb); if(bit == 1){ res += ub-lb - (r-l); } if(k==lg) return res + r - l; if(bit == 0){ return res + rank_less_than_(q, l, r, k+1); }else{ return res + rank_less_than_(q, L_size[k+1] + l, L_size[k+1] + r, k+1); } } int select(T q, int t, int lb, int ub, int k){ int bit = (q>>lg-k) & 1; int r = m[k].rank(bit, ub); int l = m[k].rank(bit, lb); if(k==lg){ return (r-l > t) ? m[k].select(bit, l+t) : -1; }else{ if(bit == 0){ t = select(q, t, l,r, k+1); }else{ t = select(q, t, L_size[k+1] + l, L_size[k+1] + r, k+1) - L_size[k+1]; } if(t <= -1) return -1; return m[k].select(bit, t); } } }; int main(){ int n,d,k; cin >> n,d,k; vector<long long> x(n); cin >> x; for(int i=0; i<n; i++){ x[i] = (x[i] << 32) + n - i; } x.resize(n+n+10, 0); WaveletMatrix<long long, TrivialBitVector> w(x); long long ans = -114514893; int ii,jj; for(int i=0; i<n; i++){ int j = w.quantile_pos(i, i+d+1, 0); int vv = (x[j]>>32) - (x[i]>>32); if(ans < vv){ ii = i; jj = j; ans = vv; } } println(ans * k); if(ans != 0) println(ii,jj); return 0; }