
先给代码,后补文字,参考了文章思路
第一次调了好久不知道WA哪里了(寄)
又重写了一遍
//acmer mxc
#include<bits/stdc++.h>
#define mst(s,x) memset(s,x,sizeof(s));
#define sr(x) scanf("%lld",&x);
#define sr2(a,b) scanf("%d%d",&a,&b);
#define sr3(a,b,c) scanf("%d%d%d",&a,&b,&c);
#define sr3d(a,b,c) scanf("%lf%lf%lf",&a,&b,&c);
#define sr4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d);
#define f(i,a,n) for(int i=a;i<=n;i++)
#define ff(i) for(int i=1;i<=n;i++)
#define sc(x) cout<<#x<<" : "<<x<<endl;
#define hh cout<<endl;
//#define int __int128
#define pii pair<int,int>
#define mk(a,b) make_pair(a,b)
#define dd double
#define inf 0x3f3f3f3f
#define ll __int128
#define fi first
#define se second
using namespace std;
inline ll read()
{
ll x=0,w=1; char c=getchar();
while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
while(c<='9'&&c>='0') x=(x<<1)+(x<<3)+c-'0',c=getchar();
return w==1?x:-x;
}
inline void write(ll x)
{
if(x>=10) write(x/10);
putchar(x%10+'0');
}
#define int long long
//------------------------------------------------
const int N=1e6+5;
int m,n,a[N];
int q[N];
int cnt[N];
int vis[N];
int v[N];
int bj[N];
inline void solve()
{
sr2(n,m);
ff(i)
{
sr(a[i]);
cnt[a[i]]++;
}
vector<int>ans;
int l=1,r=1,pos=0;
for(int i=1;i<=n;i++)
{
if(cnt[a[i]]==0)continue;
cnt[a[i]]--;
while(!bj[a[i]]&&l<r&&a[q[r-1]]>=a[i])bj[a[q[r-1]]]=0,r--;
if(!bj[a[i]])q[r++]=i,bj[a[i]]=1;
if(cnt[a[i]]==0)
{
while(l<r&&a[q[l]]<=a[i])
{
ans.push_back(a[q[l]]);
cnt[a[q[l]]]=0;
l++;
}
}
for(int i=0;i<ans.size();i++)
if(i==0)printf("%d",ans[i]);
else printf(" %d",ans[i]);
return;
}
//------------------------------------------------
signed main()
{
clock_t c1=clock();
#ifdef LOCAL
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
#endif
//==================================
int T=1;
// cin>>T;
for(int i=1;i<=T;i++)
{
solve();
}
//==================================
end:
cerr<< "Time used:" << clock() - c1 << endl;
return 0;
}
这篇文章详细介绍了如何使用C++编程语言解决超链接相关的问题,通过memset和vector等数据结构,作者分享了一种高效的方法来处理链表和计数。代码中包含内存设置、输入读取、链表操作和结果输出的关键步骤。
312

被折叠的 条评论
为什么被折叠?



