洛谷 P4305 [JLOI2011]不重复数字
题目链接:[JLOI2011]不重复数字
题解原发于
两个月不写题解了,今天来水一波
这题的目标就是去重,我们都知道c++有STL
先把整个序列按值排序一遍,在按值去重,再按原来的顺序排回去,就这么简单
注意使用\(sort\)时可能会打乱前后顺序,所以也要在排序时加入另外加入与位置有关的条件
复杂度\(O(nlogn)\)
#include
#include
#define re register
using namespace std;
template
inline void read(T &x)
{
x=0;
char s=(char)getchar();
bool flag=false;
while(s<'0'||s>'9')
{
if(s=='-')
flag=true;
s=(char)getchar();
}
while(s>='0'&&s<='9')
{
x=(x<<1)+(x<<3)+(s^'0');
s=(char)getchar();
}
if(flag)
x=~x+1;
return;
}
const int N=5e4+5;
int n;
struct node
{
int val,id;
inline bool operator <(const node &rhs)const
{
return val