本文遵守 CC BY 知识共享协议。
解法
注意到题目标签中有 模拟 标签,可想到使用 循环结构 + 选择结构 判断每次操作情况。
用变量 volume 存储音量,变量 status 存储状态。每次 操作时把 volume 与 取最大值使其保持非负。
时间复杂度 。
代码
#include<bits/stdc++.h>
using namespace std;
int q,volume;
bool status;
int main(){
scanf("%d",&q);
while(q--){
int a;
scanf("%d",&a);
if(a==1) volume++;
else if(a==2) volume=max(0,volume-1);
else if(a==3) status=!status;
puts(status&&volume>=3?"Yes":"No");
}
return 0;
}