跳到正文

题解

题解:AT_abc392_f [ABC392F] Insert

FrozenRose约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年12月23日
收录
2026年6月22日
更新
2026年11月14日
篇幅
约 1 分钟

版本

  1. v1当前

看了一圈题解区的大佬们的代码也太长了,发一篇自己的。

STL: rope

众所周知,rope 是一个类似平衡树的东西,支持很多操作。

介绍其中的 11 种用法(使用 aa 作为一个 rope):

a.insert(pos,x) 在 pospos 位置后插入 xx,注意 rope 的位置是从 00 开始的,单次操作复杂度大概是 O(Nlog⁡N)O(N \log N)。

又已知 rope 可以使用 for(auto i:a)进行遍历。

所以本题就直接最朴素地做,大概 16 行,目前见到过的最短的 F:

C++
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace std;
using namespace __gnu_cxx;
rope<int>tr;
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++)
	{
		int x;cin>>x;x--;
		tr.insert(x,i);
	}
	for(auto i:tr)cout<<i<<' ';
	return 0;
}
原文
存档评论3 条抓取于