50 Memory Exceeded

#include<iostream>
#include<stack>
using namespace std;
#define int long long
signed main(){
    int n;
    cin>>n;
    stack<int>st;
    while(n--){
        int l,r,k,a,cnt=0;
        cin>>a;
        if(a==1){
            cin>>l>>r;
            for(int i=l;i<=r;i++){
                st.push(i);
            }
        }else{
            cin>>k;
            while(k--){
                cnt+=st.top();
                st.pop();
            }
            cout<<cnt<<"\n";
        }
    }
    return 0;
}

3 条评论

  • @ 2025-4-7 19:43:01

    🤡 <- kouyiteng

    • @ 2025-3-20 21:11:08

      #include<bits/stdc++.h> using namespace std;

      typedef long long ll; struct Node{ ll l,r; }; stackc; Node z; ll n,o,a,b,k; long long s=0; int main(){

      cin>>n;
      while(n--){
          cin>>o;
      	if(o==1){
      	    cin>>a>>b;
              c.push({a,b}); 				
      	}
      	else{
      		cin>>k;
      		while(k){
      			Node g=c.top();
      			ll q=g.r-g.l+1;
      			if(q>k){
      				c.pop();
      				c.push({g.l,g.r-k});
      				s+=(g.r+g.r-k+1)*k/2;
      				k=0;
      				break;
      			}
      			else{
      			    k-=q;
      				c.pop();
      				s+=(g.r+g.l)*(g.r-g.l+1)/2;	
      			}
      		}
      		cout<<s<<endl;
      		s=0;
      	}
      }
      return 0;
      

      }

      • @ 2025-3-20 21:08:10

        #include<bits/stdc++.h> using namespace std; typedef long long ll; struct Node{ ll l,r; }; stackc; Node z; ll n,o,a,b,k; long long s=0; int main(){ cin>>n; while(n--){ cin>>o; if(o==1){ cin>>a>>b; c.push({a,b}); } else{ cin>>k;

        		while(k){
        			Node g=c.top();
        			ll q=g.r-g.l+1;
        			if(q>k){
        				c.pop();
        				c.push({g.l,g.r-k});
        				s+=(g.r+g.r-k+1)*k/2;
        				k=0;
        				break;
        			}
        			else{
        			    k-=q;
        				c.pop();
        				s+=(g.r+g.l)*(g.r-g.l+1)/2;	
        			}
        			
        		}
        		
        		cout<<s<<endl;
        		s=0;
        	}
        	
        }
        return 0;
        

        }

        • 1

        信息

        ID
        931
        时间
        1000ms
        内存
        256MiB
        难度
        9
        标签
        递交数
        47
        已通过
        4
        上传者