全RE+TLE在线求助
查看原帖
全RE+TLE在线求助
113021
月满西楼楼主2022/1/22 15:40

用stl的双向队列解的,四个tle剩余的全是RE。数据都能过,望各位大佬指点一二,感激不尽!

#include<bits/stdc++.h>
using namespace std;
int a[1008611];
int T[1008611];
deque<int> q;
long long int m,n,k;
char op;
long long int ans;
long long int x;
int main()
{
	cin>>n>>m>>k;
	ans=n;
	
	for (int i=0;i<n;i++)
	{
		cin>>a[i];
		T[a[i]+k]++;
	}
	for(int i=0;i<2*k+1;i++)
	{
		q.push_back(T[i]);
		//cout<<T[i];
	}
	while(m--)
	{
		cin>>op;
		if(op=='3')
		{
			cout<<ans<<endl;	
		}
		else
		{
			cin>>x;
			if(op=='1')
			{
				while(x--)
				{
					q.push_front(0);
					if(q.back()==1)
						ans--;
					q.pop_back();
				}
			}
			else
			{
				while(x--)
				{
					q.push_back(0);
					if(q.front()==1)
						ans--;
					q.pop_front();
				}
			}
		}
	}
	return 0;
}

再次感谢!!!

2022/1/22 15:40
加载中...