求助,样例过了全wa wa wa
查看原帖
求助,样例过了全wa wa wa
319556
KathyCao楼主2021/9/24 17:22

样例2跑出来了正确的结果 不过超时了 但为什么全wa了?

#include<iostream>
#include<cstdio> 
using namespace std;
int a[25000000];
int main()
{
	//freopen("stack2.in","r",stdin);
	//freopen("P7870.out","w",stdout);
	int n,op,l,r;
	long long k,cnt=0,ans;
	while(n--)
	{
		cin>>op;
		if(op==1) 
		{
			cin>>l>>r;
			for(int i=l;i<=r;i++) a[++cnt]=i;
		}
		else if(op==2) 
		{
			cin>>k;
			ans=0;
			for(int i=cnt;i>cnt-k;i--) ans+=a[i],a[i]=0;
			cout<<ans<<endl;
			cnt-=k;
		}	
	}
	return 0;
}
2021/9/24 17:22
加载中...