如何优化这个代码?
查看原帖
如何优化这个代码?
1285950
4041nofoundGeoge楼主2024/11/10 10:29
#include<bits/stdc++.h>
using namespace std;
const long long MAXN=2e5+5;
struct node{
	long long time;
	bool flag;
};
vector<node>v;
int main(){
	int Q;
	cin>>Q;
	while(Q--){
		int op;
		cin>>op;
		if(op==1){
			v.push_back({0,0});
		}
		else if(op==2){
			int t;
			cin>>t;
			for(auto i=v.begin();i!=v.end();i++){
				i->time+=t;
			}
		}
		else{
			int q;
			cin>>q;
			int cnt=0;
			for(auto i=v.begin();i!=v.end();i++){
				if(i->time>=q&&i->flag==0){
					i->flag=1;
					cnt++;
				}
			}
			cout<<cnt<<endl;
		}
	}
	return 0;
} 

赛事 TLE 了 33 个点

2024/11/10 10:29
加载中...