結果
問題 | No.284 門松と魔法(2) |
ユーザー | rickytheta |
提出日時 | 2016-12-22 23:21:55 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,095 bytes |
コンパイル時間 | 2,361 ms |
コンパイル使用メモリ | 174,476 KB |
実行使用メモリ | 20,736 KB |
最終ジャッジ日時 | 2024-05-08 11:20:26 |
合計ジャッジ時間 | 5,500 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | WA | - |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 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 | 2 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 2 ms
5,376 KB |
testcase_23 | AC | 9 ms
5,376 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 1 ms
5,376 KB |
testcase_27 | AC | 2 ms
5,376 KB |
testcase_28 | AC | 2 ms
5,376 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | AC | 318 ms
20,608 KB |
testcase_33 | AC | 148 ms
20,736 KB |
testcase_34 | AC | 144 ms
20,736 KB |
testcase_35 | WA | - |
testcase_36 | AC | 2 ms
5,376 KB |
testcase_37 | AC | 85 ms
16,000 KB |
testcase_38 | WA | - |
testcase_39 | WA | - |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:121:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 121 | scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:122:16: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 122 | REP(i,n)scanf("%d",a+i); | ~~~~~^~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef ll _loop_int; #define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i) #define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i) #define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i) #define DEBUG(x) cout<<#x<<": "<<x<<endl #define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl #define ALL(a) (a).begin(),(a).end() #define CHMIN(a,b) a=min((a),(b)) #define CHMAX(a,b) a=max((a),(b)) // mod const ll MOD = 1000000007ll; #define FIX(a) ((a)%MOD+MOD)%MOD // floating typedef double Real; const Real EPS = 1e-11; #define EQ0(x) (abs(x)<EPS) #define EQ(a,b) (abs(a-b)<EPS) typedef complex<Real> P; struct node{ int bef2[2],len[2],bef[2]; node(){ bef2[0]=bef2[1]=-1; len[0]=len[1]=0; bef[0]=bef[1]=-1; } node merge(const node &that){ node ret; int it1=0,it2=0; if(len[0]>that.len[0]){ ret.len[0] = len[0]; ret.bef2[0] = bef2[0]; ret.bef[0] = bef[0]; if(len[1]<that.len[0] && ret.bef2[0]!=that.bef2[0]){ ret.len[1] = that.len[0]; ret.bef2[1] = that.bef2[0]; ret.bef[1] = that.bef[0]; }else{ ret.len[1] = len[1]; ret.bef2[1] = bef2[1]; ret.bef[1] = bef[1]; } }else{ ret.len[0] = that.len[0]; ret.bef2[0] = that.bef2[0]; ret.bef[0] = that.bef[0]; if(that.len[1]<len[0] && ret.bef2[0]!=bef2[0]){ ret.len[1] = len[0]; ret.bef2[1] = bef2[0]; ret.bef[1] = bef[0]; }else{ ret.len[1] = that.len[1]; ret.bef2[1] = that.bef2[1]; ret.bef[1] = that.bef[1]; } } return ret; } void debug(){ printf("[%d,%d,%d],[%d,%d,%d]\n",len[0],bef2[0],bef[0],len[1],bef2[1],bef[1]); } }; struct segment{ int n; vector<node> data; segment(int n_){ n=1; while(n<n_)n<<=1; data.resize(2*n-1); REP(i,n){ data[i+n-1]=node(); data[i+n-1].bef[0] = data[i+n-1].bef[1] = i; } FORR(i,0,n-1)data[i]=data[2*i+1].merge(data[2*i+2]); } void set(int x,node v){ x += n-1; data[x] = v; while(x>0){ x = (x-1)/2; data[x] = data[2*x+1].merge(data[2*x+2]); } } node get(int x){ return data[x+n-1]; } node query(int l,int r,int a,int b,int k){ if(r<=a || b<=l)return node(); if(l<=a && b<=r){ return data[k]; }else{ int m = (a+b)/2; node lef = query(l,r,a,m,2*k+1); node rig = query(l,r,m,b,2*k+2); return lef.merge(rig); } } node query(int l,int r){ return query(l,r,0,n,0); } }; int n; int a[125252]; int main(){ scanf("%d",&n); REP(i,n)scanf("%d",a+i); // kowai node zaatu { map<int,int> M; REP(i,n)M[a[i]]=0; int it = 1; for(pair<int,int> P:M){ M[P.first] = it++; } REP(i,n)a[i]=M[a[i]]; } segment up(n+10),down(n+10); int ans = 0; REP(i,n){ int v = a[i]; node nxtdown = down.get(v), nxtup = up.get(v); { node q = up.query(v+1,n+5); int use = (q.bef2[0]!=v) ? 0 : 1; int nextlen = q.len[use]+1; CHMAX(ans,nextlen); int nextbef2 = q.bef[use]; if(nxtdown.len[1] < nextlen){ nxtdown.len[1] = nextlen; nxtdown.bef2[1] = nextbef2; if(nxtdown.len[0] < nxtdown.len[1]){ swap(nxtdown.len[0], nxtdown.len[1]); swap(nxtdown.bef2[0], nxtdown.bef2[1]); } } } { node q = down.query(0,v); int use = (q.bef2[0]!=v) ? 0 : 1; int nextlen = q.len[use]+1; CHMAX(ans,nextlen); int nextbef2 = q.bef[use]; if(nxtup.len[1] < nextlen){ nxtup.len[1] = nextlen; nxtup.bef2[1] = nextbef2; if(nxtup.len[0] < nxtup.len[1]){ swap(nxtup.len[0], nxtup.len[1]); swap(nxtup.bef2[0], nxtup.bef2[1]); } } } up.set(v,nxtup); down.set(v,nxtdown); } if(ans<3)ans=0; printf("%d\n",ans); return 0; }