站外题求优化
  • 板块学术版
  • 楼主Luogu_916767
  • 当前回复9
  • 已保存回复9
  • 发布时间2024/8/1 10:24
  • 上次更新2024/8/1 11:18:01
查看原帖
站外题求优化
916767
Luogu_916767楼主2024/8/1 10:24

RT,TLE

#include<bits/stdc++.h>

using namespace std;

int t;
int to,k;
struct node{
	int x;
	int del;
};
deque<node> q;
vector<node> a;

int main(){
	cin>>t;
	while(t -- ){
		cin>>to;
		if(to == 1){
			cin>>k;
			q.push_back({k,0});
		}else if(to == 2){
			cin>>k;
			while(k >= q.front().x-q.front().del){
				k -= q.front().x-q.front().del;
				q.pop_front();
			}
			node f = q.front();
			q.pop_front();
			f.del = k;
			q.push_front(f);
		}else if(to == 3){
			cin>>k;
			a.clear();
			while(k > q.front().x-q.front().del){
				k -= q.front().x-q.front().del;
				a.push_back(q.front());
				q.pop_front();
			}
			cout<<k+q.front().del<<"\n";
			for(int i = a.size()-1; i >= 0; i -- ){
				q.push_front(a[i]);
			}
		}else{
			int maxn = 0;
			a.clear();
			while(!q.empty()){
				maxn = max(maxn,q.front().x);
				a.push_back(q.front());
				q.pop_front();
			}
			cout<<maxn<<"\n";
			for(int i = a.size(); i >= 0; i -- ){
				q.push_front(a[i]);
			}
		}
	}
}
2024/8/1 10:24
加载中...