上面的是原题解。我的思路一样,不过使用vector实现的,第一次查找了一遍超时,想了一下原来不用,直接找就行,最后险过,听说线段树特别快。有时间试试
#include <cstdio>
#include <string>
#include <cstring>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
#define maxn 50005
#define MOD 1000000007
#define mem(a) memset(a , 0 , sizeof(a))
#define LL __int64
int arr[maxn];
int ans [maxn];
vector<int>v;
int main()
{
int t , n;
scanf("%d" , &t);
while(t--)
{
v.clear();
scanf("%d" , &n);
for(int i = 0 ; i < n ; i ++)
{
scanf("%d" , &arr[i]);
v.push_back(i+1);
}
int tmp = 0;
for(int i = n-1 ; i > 0; i --)
{
tmp = arr[i] - arr[i-1];
ans[i] = v[i-tmp];
//std::vector<int>::iterator iter=std::find(v.begin(),v.end(),ans[i]); //加了超时
v.erase(v.begin() + i - tmp); //以前是直接<span style="font-family: Arial, Helvetica, sans-serif;">v.erase(iter)</span>
}
ans[0] = v[0];
for(int i = 0 ; i < n ; i ++)
{
printf("%d" , ans[i]);
if(i != n-1) printf(" ");
}
printf("\n");
}
return 0;
}