社区讨论
P7505求调(解决此问题的大佬NOI必金)
学术版参与者 2已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @lzileot1
- 此快照首次捕获于
- 2024/08/06 23:46 2 年前
- 此快照最后确认于
- 2024/08/07 09:11 2 年前
CPP
#include<bits/stdc++.h>
using namespace std;
queue<int>q;
int a[1111111];
long long op,n,m,k,sum;
long long tot;
int main()
{
cin>>n>>m>>k;
for (int i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+n+1);
for(int i=1;i<=n;i++)
{
if (a[i]>=-k&&a[i]<=k)
{
q.push(a[i]);
sum++;
}
}
while (m--)
{
cin>>op;
if (op==1)
{
cin>>tot;
for (int i=1;i<=sum;i++)
{
int ss=q.front();
if (ss+tot>k||ss+tot<-k)
{
q.pop();
sum--;
}
else
{
q.push(q.front()+tot);
q.pop();
}
}
}
if (op==2)
{
cin>>tot;
for (int i=1;i<=sum;i++)
{
int ss=q.front();
if (ss-tot>k||ss-tot<-k)
{
q.pop();
sum--;
}
else
{
q.push(q.front()-tot);
q.pop();
}
}
}
if (op==3)
{
cout<<q.size()<<endl;
}
}
return 0;
}
回复
共 3 条回复,欢迎继续交流。
正在加载回复...