結果
問題 | No.230 Splarraay スプラレェーイ |
ユーザー | koyumeishi |
提出日時 | 2015-07-25 06:04:12 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,697 bytes |
コンパイル時間 | 1,201 ms |
コンパイル使用メモリ | 87,460 KB |
実行使用メモリ | 37,588 KB |
最終ジャッジ日時 | 2024-07-16 04:43:05 |
合計ジャッジ時間 | 4,681 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 49 ms
6,940 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 159 ms
37,588 KB |
testcase_19 | WA | - |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:237:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 237 | scanf("%lld%lld", &n,&q); | ~~~~~^~~~~~~~~~~~~~~~~~~ main.cpp:256:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 256 | 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){ } long long get(){ if(zero) add = 0; return add; } unko operator +(const unko& x){ unko ret; if(x.zero){ //zero fill ret.zero = true; return ret; } //add if(zero){ add = 0; zero = false; } 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{ struct node{ //[l,r) long long lb; long long ub; node* left; node* right; V val; U lazy; bool is_lazy; 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; 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) return t->lazy.get(); return t->val; }else{ if(t->is_lazy){ if(t->lazy.zero) t->val = 0; 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); } } 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; } //partially covered 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); } //partially covered 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; 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); } void dbg(){ for(auto t: pool){ cerr << "[ " << t->lb << " - " << t->ub << " ) : " << t->val << " " << t->lazy << endl; } } }; #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; }