結果
問題 | No.230 Splarraay スプラレェーイ |
ユーザー | koyumeishi |
提出日時 | 2015-07-25 07:09:08 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 6,145 bytes |
コンパイル時間 | 853 ms |
コンパイル使用メモリ | 85,144 KB |
実行使用メモリ | 24,060 KB |
最終ジャッジ日時 | 2024-07-16 04:45:02 |
合計ジャッジ時間 | 3,949 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 11 ms
19,000 KB |
testcase_01 | AC | 11 ms
18,852 KB |
testcase_02 | AC | 12 ms
18,820 KB |
testcase_03 | AC | 11 ms
18,872 KB |
testcase_04 | AC | 11 ms
18,724 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | RE | - |
testcase_10 | WA | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | WA | - |
testcase_14 | AC | 56 ms
18,844 KB |
testcase_15 | WA | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:254:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 254 | scanf("%lld%lld", &n,&q); | ~~~~~^~~~~~~~~~~~~~~~~~~ main.cpp:273:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 273 | scanf("%lld%lld%lld", &x,&l,&r); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <iostream> #include <vector> #include <cstdio> #include <sstream> #include <map> #include <string> #include <algorithm> #include <queue> #include <cmath> #include <set> #include <stack> using namespace std; struct unko{ long long add; bool zero; unko(long long add_, bool zero_) : add(add_), zero(zero_) { } unko():add(0),zero(false){ } unko operator +(const unko& x){ unko ret; if(x.zero){ //zero fill ret.zero = true; return ret; } //add ret.add = add + x.add; return ret; } long long operator *(const long long& x){ if(zero) return 0; return add * x; } }; //V := type of node value //U := type of lazy value template<class V=int, class U=int> class Dynamic_SegmentTree{ public: struct node{ //[l,r) long long lb; long long ub; node* left; node* right; V val; U lazy; bool is_lazy; node() : lb(0), ub(0), left(nullptr), right(nullptr), val(V()), lazy(U()), is_lazy(false) { } node(long long l, long long r, V v, U u) : lb(l), ub(r), left(nullptr), right(nullptr), val(v), lazy(u), is_lazy(false) { } }; //vector<node*> pool; vector<node> nodes_pool; int pool_itr; node* root; V default_v; U default_l; //range add V evaluate_vv(V a, V b){ return a+b; } U evaluate_ll(U& a, U& b){ return a+b; } V evaluate_vl(node* t){ if(t->ub - t->lb == 1){ if(t->is_lazy){ if(t->lazy.zero){ t->val = t->lazy.add; t->lazy.add = 0; t->lazy.zero = false; }else{ t->val += t->lazy.add; t->lazy.add = 0; } } return t->val; }else{ if(t->is_lazy){ if(t->lazy.zero) t->val = default_v; return t->val + t->lazy * (t->ub - t->lb); } return t->val; } } inline void set_children(node* t){ if(t->left == nullptr){ //t->left = new node(t->lb, (t->lb+t->ub)/2, default_v, default_l); //t->right = new node((t->lb+t->ub)/2, t->ub, default_v, default_l); //pool.push_back(t->left); //pool.push_back(t->right); if(nodes_pool.size() <= pool_itr+2) nodes_pool.resize(nodes_pool.size() + 100); t->left = &nodes_pool[pool_itr++]; t->right = &nodes_pool[pool_itr++]; t->left->lb = t->lb; t->left->ub = (t->lb+t->ub)/2; t->right->lb = (t->lb+t->ub)/2; t->right->ub = t->ub; } } void propagete(node* t){ if(t->is_lazy == false) return; if(t->ub - t->lb == 1){ t->val = evaluate_vl(t); }else{ set_children(t); for(node* ch : {t->left, t->right}){ if(ch->is_lazy){ ch->lazy = evaluate_ll(ch->lazy, t->lazy); }else{ ch->lazy = t->lazy; } ch->is_lazy = true; //ch->val = default_v; //range fill } } t->lazy = default_l; t->is_lazy = false; if(t->left != nullptr) t->val = evaluate_vv(evaluate_vl(t->left), evaluate_vl(t->right)); } void range_update(node* t, long long lb, long long ub, U new_val){ if(ub <= t->lb || t->ub <= lb) return; //out of range propagete(t); if(lb <= t->lb && t->ub <= ub){ // fully covered t->lazy = new_val; t->is_lazy = true; //t->val = default_v; //range fill return; } set_children(t); range_update(t->left, lb,ub, new_val); range_update(t->right, lb,ub, new_val); t->val = evaluate_vv(evaluate_vl(t->left), evaluate_vl(t->right)); } V range_evaluate(node* t, long long lb, long long ub){ if(ub <= t->lb || t->ub <= lb) return default_v; //out of range propagete(t); if(lb <= t->lb && t->ub <= ub){ // fully covered return evaluate_vl(t); } set_children(t); V l_val = range_evaluate(t->left, lb,ub); V r_val = range_evaluate(t->right, lb,ub); return evaluate_vv(l_val, r_val); } public: Dynamic_SegmentTree(long long size, V default_value, U default_lazy) : default_v(default_value), default_l(default_lazy) { long long sz = 1; while(sz < size) sz <<= 1LL; nodes_pool.resize(50000); pool_itr = 0; root = &nodes_pool[pool_itr++]; root->lb = 0; root->ub = sz; //root = new node(0, sz, default_value, default_lazy); //pool.push_back(root); } /* ~Dynamic_SegmentTree(){ for(int i=0; i<pool.size(); i++){ delete(pool[i]); } } */ // A[pos] <- set_val void update(long long pos, V set_val){ node* t = root; stack<node*> s; s.push(t); while(t->ub - t->lb != 1){ set_children(t); propagete(t); if ( pos < (t->ub + t->lb) / 2 ){ t = t->left; }else{ t = t->right; } s.push(t); } propagete(t); s.top() -> val = set_val; s.pop(); while(s.size()){ t = s.top(); s.pop(); t->val = evaluate_vv(evaluate_vl(t->left), evaluate_vl(t->right)); } } void range_update(long long lb, long long ub, U new_val){ range_update(root, lb, ub, new_val); } V range_evaluate(long long lb, long long ub){ return range_evaluate(root, lb, ub); } }; #define MOD 1000000000000000009 int main(){ long long n,q; scanf("%lld%lld", &n,&q); int team = 2; Dynamic_SegmentTree<long long, unko> a(n+1, 0, unko()); Dynamic_SegmentTree<long long, unko> b(n+1, 0, unko()); Dynamic_SegmentTree<long long, unko> c(n+1, 0, unko()); Dynamic_SegmentTree<long long, unko> d(n+1, 0, unko()); Dynamic_SegmentTree<long long, unko> e(n+1, 0, unko()); vector<unsigned long long> ans(5,0); vector<Dynamic_SegmentTree<long long, unko>*> seg(5); seg[0] = &a; seg[1] = &b; seg[2] = &c; seg[3] = &d; seg[4] = &e; for(int i=0; i<q; i++){ long long x,l,r; scanf("%lld%lld%lld", &x,&l,&r); if(x==0){ vector<unsigned long long> cnt(5,0); unsigned long long my_max = 0; for(int j=0; j<team; j++){ cnt[j] = seg[j]->range_evaluate(l,r+1); my_max = max(my_max, cnt[j]); } vector<int> max_ele; for(int j=0; j<team; j++){ if(cnt[j] == my_max) max_ele.push_back(j); } if(max_ele.size() != 1) continue; ans[max_ele[0]] += my_max; if(ans[max_ele[0]] >= MOD) ans[max_ele[0]] -= MOD; }else{ for(int j=0; j<team; j++){ seg[j]->range_update(l,r+1, x-1==j?(unko){1,false}:(unko){0,true}); } } } for(int i=0; i<team; i++){ unsigned long long cnt = seg[i]->range_evaluate(0,n); ans[i] += cnt; if(ans[i] >= MOD) ans[i] -= MOD; cout << ans[i] << (i==4?"\n":" "); } return 0; }