TLE跪求神仙优化
查看原帖
TLE跪求神仙优化
247533
__cht楼主2020/9/8 19:59

RT,T飞惹,大佬们能指点一下可以从哪里进行优化吗???

代码如下:

#include<bits/stdc++.h>
using namespace std;
const int N = 1000010;
int n, m;
int p[N];
int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i ++) p[i] = i;
	for(int i = 1; i <= m; i ++)
	{
		int op;
		scanf("%d", &op);
		if(op == 1 || op == 2) sort(p + 1, p + 1 + n);
		if(op == 2 || op == 4) reverse(p + 1, p + 1 + n);
		if(op == 3)
		{
			int x, y;
			scanf("%d%d", &x, &y);
			swap(p[x], p[y]);
		}
	}
	for(int i = 1; i <= n; i ++) printf("%d ", p[i]);
	return 0;
} 

请不要出言不逊

2020/9/8 19:59
加载中...