結果
問題 | No.284 門松と魔法(2) |
ユーザー | koyumeishi |
提出日時 | 2015-09-25 03:45:48 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,131 bytes |
コンパイル時間 | 1,153 ms |
コンパイル使用メモリ | 95,780 KB |
実行使用メモリ | 16,036 KB |
最終ジャッジ日時 | 2024-07-19 09:08:52 |
合計ジャッジ時間 | 5,711 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
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 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 1 ms
5,376 KB |
testcase_27 | WA | - |
testcase_28 | AC | 2 ms
5,376 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
コンパイルメッセージ
main.cpp: In function ‘val func(const val&, int, int)’: main.cpp:201:1: warning: control reaches end of non-void function [-Wreturn-type] 201 | } | ^ main.cpp: In function ‘int main()’: main.cpp:208:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 208 | scanf("%d", &a[i]); | ~~~~~^~~~~~~~~~~~~
ソースコード
// (>_<)ムリ!! #include <iostream> #include <vector> #include <cstdio> #include <sstream> #include <map> #include <string> #include <algorithm> #include <queue> #include <cmath> #include <set> using namespace std; struct node{ int cnt; int l; int m; node():cnt(0),l(0),m(0){} bool operator < (const node& x) const{ return cnt < x.cnt; } bool operator == (const node& x) const{ return (cnt == x.cnt) && (l == x.l) && (m == x.m); } }; struct val{ node a; node b; val operator +(const val& x){ val ret; priority_queue<node, vector<node>, less<node>> pq; pq.push(a); pq.push(b); pq.push(x.a); pq.push(x.b); ret.a = pq.top(); pq.pop(); bool ok = false; while(pq.size() && !ok){ if(pq.top().l != ret.a.l){ ok = true; ret.b = pq.top(); }else{ pq.pop(); } } return ret; } }; ostream& operator << (ostream& os, const node& x){ os << "{" << x.cnt << ", " << x.l << ", " << x.m << "} "; return os; } ostream& operator << (ostream& os, const val& x){ os << "{ " << x.a << ", " << x.b << "} "; return os; } val comp(const val& x, const val& y){ val ret; if(x.a < y.a){ ret.a = y.a; if(x.a < y.b){ if(ret.a.m != y.b.m) ret.b = y.b; else ret.b = x.a; }else{ if(ret.a.m != x.a.m) ret.b = x.a; else ret.b = y.b; } }else{ ret.a = x.a; if(x.b < y.a){ if(ret.a.m != y.a.m) ret.b = y.a; else ret.b = x.b; }else{ if(ret.a.m != x.b.m) ret.b = x.b; else ret.b = y.a; } } return ret; } val hoge(const val& x, int a){ val ret; if(x.a.l != a){ ret.a = x.a; if(x.b.l != a){ ret.b = x.b; } }else if(x.b.l != a){ ret.a = x.b; } return ret; } class seg{ public: vector<val> v; int size; seg(int n){ size = 1; while(size<n){ size <<= 1; } v.resize(2*size); } void update(int l, int r, val& x, int lb, int ub, int pos){ if(ub<=l || r<=lb) return; if(l<=lb && ub<=r){ v[pos] = v[pos]+x; return; } update(l,r,x, lb,(lb+ub)/2, pos*2+1); update(l,r,x, (lb+ub)/2,ub, pos*2+2); v[pos] = v[pos*2+1] + v[pos*2+2]; } void update(int l, int r, val& x){ update(l,r,x,0,size,0); } val get(int l, int r, int a, int cnt, int lb, int ub, int pos){ if(ub<=l || r<=lb) return val(); if(l<=lb && ub<=r){ val ret; if(cnt == 2){ ret = hoge(v[pos], a); if((ub-lb>1)){ ret = comp(get(l,r,a,1, lb,(lb+ub)/2, pos*2+1) , get(l,r,a,1, (lb+ub)/2,ub, pos*2+2)); //ret = comp(ret, tmp); } }else{ ret = hoge(v[pos], a); } return ret; } val x; x = get(l,r, a,cnt, lb, (lb+ub)/2, pos*2+1); //x = hoge(x, a); val y; y = get(l,r, a,cnt, (lb+ub)/2, ub, pos*2+2); //y = hoge(y, a); val ret = comp(x,y); return ret; } val get(int l, int r, int a){ return get(l,r, a,2, 0,size,0); } }; template<class T> vector<T> compress(vector<T> a, int& size){ auto b = a; sort(b.begin(), b.end()); b.erase( unique(b.begin(), b.end()), b.end()); for(int i=0; i<a.size(); i++){ a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin() +1; } size = b.size(); return a; } val func(const val& x, int a, int i){ //cerr << x << " "; val ret; if(x.a.cnt == 0){ ret.a.m = a; ret.a.cnt = 1; ret.a.l = 1e6; return ret; }else{ ret.a.m = a; ret.a.cnt = x.a.cnt+1; ret.a.l = x.a.m; ret.b.m = a; ret.b.cnt = x.b.cnt+1; ret.b.l = x.b.m; if(ret.b.l == 0) ret.b.l = 1e6; } if(ret.a == ret.b){ if(ret.a.cnt == 1){ ret.b = node(); }else{ ret.b.cnt = 1; ret.b.l = 1e6; } } } int main(){ int n; cin >> n; vector<int> a(n); for(int i=0; i<n; i++){ scanf("%d", &a[i]); } int m; a = compress(a, m); a.erase( unique(a.begin(), a.end()), a.end()); n = a.size(); seg inc(m+1); seg dec(m+1); for(int i=0; i<n; i++){ val s = func(inc.get(a[i]+1, m+1, a[i]), a[i], i); //cerr << s << endl; val t = func(dec.get(0, a[i], a[i]), a[i], i); //cerr << t << endl; dec.update(a[i],a[i]+1, s); inc.update(a[i],a[i]+1, t); } int ans = 0; val x = inc.get(0,m+1, 1e9); val y = dec.get(0,m+1, 1e9); ans = max({x.a.cnt, x.b.cnt, y.a.cnt, y.b.cnt}); if(ans <= 2) ans = 0; cout << ans << endl; return 0; }