CE,为什么?
查看原帖
CE,为什么?
1100773
WTY0111楼主2025/1/27 18:40

为什么CE了?请大佬帮忙看看(语言C++11和C++14都CE)

MyCode:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M = 40000005;
list<deque<ll> > l;
ll a[M];
int main(){
	deque<ll> d;
	d.push_back(1);
	l.push_back(d);
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++){
		cin>>a[i];
	}
	for(ll i=2;i<=n;i++){
		if(a[i]==a[i-1]){
			l.back().push_back(i);
		}
		else{
			deque<ll> t;
			t.push_back(i);
			l.push_back(t);
		}
	}
	while(!l.empty()){
			auto it=l.begin();
			while(it!=l.end()){
				printf("%lld ",it->front());
				it->pop_front();
				if(it->empty()){
					it=l.erase(it);
				}
				else{
					it++;
				}
			}
			auto lst=l.begin();
			if(lst==l.end()){
				break;
			}
			auto nw=lst+1; 
			while(nw!=l.end()){
				if(a[lst->front()]==a[nw->front()]){
					if(lst->size()<nw->size()){
						while(!lst->empty()){
							nw->push_front(lst->back());
							lst->pop_back();
						}
						l.erase(lst);
						lst=nw;
						nw++;
					}
					else{
						while(!nw->empty()){
							lst->push_back(nw->front());
							nw->pop_front();
						}
						nw=l.erase(nw);
					}
				}
				else{
					lst=nw;
					nw+=1;
				}
			}
			printf("\n");
		}
	return 0;
}
2025/1/27 18:40
加载中...