题目大意:
维护个栈,去重保留最上层
题目分析:
啥也不是,数组模拟 \(\text{stack} + \text{unordered\_map}\) 直接秒掉。
复杂度 \(O(n)\)
代码实现:
#include <bits/stdc++.h>
#define debug(x) cerr<<#x<<": "<<x<<endl;
#define int long long
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
return x*f;
}
namespace Larry76{
const int MAX_SIZE = 2e5;
string sta[MAX_SIZE];
map<string,bool>hashtable;
int top = 0;
void main(){
//Code Here;
int n;
cin>>n;
string buffer;
while(n--){
cin>>buffer;
sta[++top] = buffer;
}
while(top){
if(!hashtable[sta[top]]){
cout<<sta[top]<<endl;
hashtable[sta[top]] = 1;
}
--top;
}
}
}
signed main(){
#ifdef LOCAL
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
double c1 = clock();
#else
ios::sync_with_stdio(false);
#endif
//============================================
Larry76::main();
//============================================
#ifdef LOCAL
double c2 = clock();
cerr<<"Used Time: "<<c2-c1<<"ms"<<endl;
if(c2-c1>1000)
cerr<<"Warning!! Time Limit Exceeded!!"<<endl;
fclose(stdin);
fclose(stdout);
#endif
return 0;
}
标签:ch,buffer,题解,top,int,while,CF637B
From: https://www.cnblogs.com/larry76/p/17130431.html