結果
問題 | No.284 門松と魔法(2) |
ユーザー | snuke |
提出日時 | 2015-09-19 01:05:17 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,057 bytes |
コンパイル時間 | 1,303 ms |
コンパイル使用メモリ | 102,024 KB |
実行使用メモリ | 86,144 KB |
最終ジャッジ日時 | 2024-07-19 07:32:57 |
合計ジャッジ時間 | 16,533 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 147 ms
81,024 KB |
testcase_01 | WA | - |
testcase_02 | AC | 144 ms
81,024 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 147 ms
81,024 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 147 ms
81,024 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 148 ms
81,024 KB |
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 | 146 ms
81,152 KB |
testcase_27 | AC | 145 ms
81,024 KB |
testcase_28 | AC | 146 ms
81,024 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 620 ms
81,280 KB |
testcase_32 | WA | - |
testcase_33 | AC | 599 ms
86,016 KB |
testcase_34 | AC | 593 ms
86,144 KB |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | AC | 780 ms
81,280 KB |
testcase_38 | WA | - |
testcase_39 | WA | - |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:107:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 107 | scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:108:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 108 | rep(i,n) scanf("%d",&ax[i]); | ~~~~~^~~~~~~~~~~~~
ソースコード
#include <cstdio> #include <algorithm> #include <stack> #include <queue> #include <deque> #include <vector> #include <string> #include <string.h> #include <cstdlib> #include <ctime> #include <cmath> #include <map> #include <set> #include <iostream> #include <sstream> #include <numeric> #include <cctype> #define fi first #define se second #define rep(i,n) for(int i = 0; i < n; ++i) #define rrep(i,n) for(int i = 1; i <= n; ++i) #define drep(i,n) for(int i = n-1; i >= 0; --i) #define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next) #define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++) #define rng(a) a.begin(),a.end() #define maxs(x,y) x = max(x,y) #define mins(x,y) x = min(x,y) #define pb push_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcount #define snuke srand((unsigned)clock()+(unsigned)time(NULL)); using namespace std; typedef long long int ll; typedef pair<int,int> P; typedef vector<int> vi; typedef vector<vi> vvi; inline int in() { int x; scanf("%d",&x); return x;} inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');} const int MX = 100005, INF = 1000010000; const int MY = 100005; const ll LINF = 1000000000000000000ll; const double eps = 1e-10; int n; int ax[MX]; map<int,int> mp; // Segment tree (RMQ type) struct seg { vector<vvi> d; int x2; seg(){} seg(int mx){ x2 = 1; while(x2 < mx) x2 <<= 1; d.resize(x2<<1,{{0,-10,-10},{0,-10,-10}}); } void add(int i, vi x){ for(i+=x2;i;i>>=1) { if (d[i][0][0] <= x[0]) { if (d[i][0][1] != x[1]) d[i][1] = d[i][0]; d[i][0] = x; } else if (d[i][1][0] < x[0] && d[i][1][1] != x[1]) { d[i][1] = x; } } } vi get(int a, int b, int x, int i=1, int l=0, int r=-10){ // cout<<a<<" "<<b<<" "<<x<<" "<<i<<" "<<l<<" "<<r<<endl; if (a >= b) return {0,-10,-10}; if (a < 0) return {0,-10,-10}; if (b > x2) return {0,-10,-10}; if (r == -10) r = x2; if(a <= l && r <= b) { if (d[i][0][1] != x) return d[i][0]; return d[i][1]; } int c = (l+r)>>1; vi res = {0,-10,-10}; if(a < c) res = max(res,get(a,b,x,i<<1,l,c)); if(c < b) res = max(res,get(a,b,x,i<<1|1,c,r)); return res; } }; // int solve() { seg dl(MY), dr(MY); rep(i,n) { int a = ax[i]; vi ml = dl.get(0,a,a); vi mr = dr.get(a+1,MY,a); vi nl = max(dl.get(0,ml[1],a),dl.get(ml[1]+1,a,a)); vi nr = max(dr.get(a+1,mr[1],a),dr.get(mr[1]+1,MY,a)); dl.add(a,{mr[0]+1,mr[2],a}); dr.add(a,{ml[0]+1,ml[2],a}); dl.add(a,{nr[0]+1,nr[2],a}); dr.add(a,{nl[0]+1,nl[2],a}); // cout<<i<<" "<<a<<endl; // priv(ml); // priv(mr); // priv(nl); // priv(nr); } return max(dl.get(0,MY,-10)[0],dr.get(0,MY,-10)[0]); } int main() { scanf("%d",&n); rep(i,n) scanf("%d",&ax[i]); rep(i,n) mp[ax[i]] = 0; int cnt = 0; for (auto it = mp.begin(); it != mp.end(); ++it) it->se = cnt++; rep(i,n) ax[i] = mp[ax[i]]; int ans = solve(); if (ans < 3) ans = 0; cout<<ans<<endl; return 0; }