大样例在本地都可以正常运行(虽然我不知道对不对)但是在洛谷评测就RE一大坨,想知道RE的原因。
#include<queue>
#include<deque>
#include<iostream>
using namespace std;
queue<int> c;
queue<int> stacks;
deque<int> s[305];
int t,n,m,k,typeonstacktop[200005],typeonstackbottom[200005],num,supportstack,cnt;
int ans[400005],ans1[400005],ans2[400005];
int main()
{
cin>>t;
while(t--)
{
cin>>n>>m>>k;
for(int i=1;i<=m;i++)
{
cin>>num;
c.push(num);
}
for(int i=1;i<n;i++)
{
stacks.push(i);
}
supportstack=n;
for(int i=1;i<=m;i++)
{
if(typeonstacktop[c.front()]!=0)
{
ans[++cnt]=1,ans1[cnt]=typeonstacktop[c.front()];
s[typeonstacktop[c.front()]].pop_front();
if(s[typeonstacktop[c.front()]].empty())supportstack=typeonstacktop[c.front()];
typeonstackbottom[c.front()]=0;
if(s[typeonstacktop[c.front()]].size()<2)stacks.push(typeonstacktop[c.front()]);
typeonstacktop[c.front()]=s[typeonstacktop[c.front()]].empty()?0:s[typeonstacktop[c.front()]].front();
c.pop();
continue;
}
if(typeonstackbottom[c.front()]!=0&&supportstack!=0)
{
ans[++cnt]=1,ans1[cnt]=supportstack;
ans[++cnt]=2,ans1[cnt]=supportstack,ans2[cnt]=typeonstackbottom[c.front()];
s[typeonstackbottom[c.front()]].pop_back();
typeonstackbottom[c.front()]=0;
if(s[typeonstackbottom[c.front()]].size()<2)stacks.push(typeonstackbottom[c.front()]);
typeonstackbottom[c.front()]=s[typeonstackbottom[c.front()]].empty()?0:s[typeonstackbottom[c.front()]].back();
c.pop();
continue;
}
if(stacks.front()==supportstack)stacks.pop();
if(stacks.empty())
{
stacks.push(supportstack);
supportstack=0;
}
ans[++cnt]=1,ans1[cnt]=stacks.front();
if(!s[stacks.front()].empty())typeonstacktop[s[stacks.front()].front()]=0;
s[stacks.front()].push_front(c.front());
num=stacks.front();
stacks.pop();
if(s[num].size()<2)stacks.push(num);
if(s[num].front()==c.front())typeonstacktop[c.front()]=num;
if(s[num].back()==c.front())typeonstackbottom[c.front()]=num;
//cout<<"stacksize:"<<num<<" "<<s[num].size()<<endl;
//cout<<"top or bottom:"<<typeonstacktop[c.front()]<<" "<<typeonstackbottom[c.front()]<<endl;
c.pop();
}
cout<<cnt<<endl;
for(int i=1;i<=cnt;i++)
{
if(ans[i]==2)cout<<ans[i]<<" "<<ans1[i]<<" "<<ans2[i]<<endl;
else cout<<ans[i]<<" "<<ans1[i]<<endl;
}
}
}
求大佬们给点原因的提示,谢谢!