Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
141942 黄恩宁 音乐会 C++ 通过 100 85 MS 384 KB 1633 2024-04-06 15:02:13

Tests(10/10):


#include<iostream> #include<cstdio> #include<stack> #include<queue> using namespace std; const int R=2e6; stack<int> stk; long long ans=0; int n,h,bucket[R]; void lss() { ans++; //即使bucket[stk.top()]不只一个,也只能看到一个,例如8 8 6,6只能看到一个8 stk.push(h); bucket[h]++; // cout<<"ans="<<ans<<endl; // cout<<"push "<<h<<endl; // cout<<"bucket "<<h<<" "<<bucket[h]<<endl; return; } void eqal() { ans+=bucket[h]; // cout<<"ans="<<ans<<endl; if(stk.size()>1) { // cout<<"pop "<<stk.top()<<endl; stk.pop(); lss(); } else { bucket[h]++; // cout<<"bucket "<<h<<" "<<bucket[h]<<endl; } return; } void grat() { while(!stk.empty() && h>stk.top()) { ans+=bucket[stk.top()]; bucket[stk.top()]=0; // cout<<"ans="<<ans<<endl; // cout<<"bucket "<<stk.top()<<" "<<bucket[stk.top()]<<endl; // cout<<"pop "<<stk.top()<<endl; stk.pop(); } if(!stk.empty() && h==stk.top()) eqal(); else if(!stk.empty()) lss(); else { stk.push(h); bucket[h]++; // cout<<"push "<<h<<endl; // cout<<"bucket "<<h<<" "<<bucket[h]<<endl; } return; } int main() { int i; cin>>n>>h; stk.push(h); bucket[h]=1; // cout<<"push "<<h<<endl; // cout<<"bucket "<<h<<" "<<bucket[h]<<endl; for(i=2;i<=n;i++) { cin>>h; // cout<<"cin>>"<<h<<endl; if(!stk.empty() && h<stk.top()) lss(); else if(!stk.empty() && h==stk.top()) eqal(); else if(!stk.empty()) grat(); else { stk.push(h); bucket[h]++; // cout<<"push "<<h<<endl; // cout<<"bucket "<<h<<" "<<bucket[h]<<endl; } } cout<<ans; return 0; }


测评信息: