Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 2835
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 1, 20222022-06-01T15:16:09+00:00 2022-06-01T15:16:09+00:00

c++ – Can inserting 5*1e8 element in long long multiset crash the program?

  • 0

[ad_1]

I seem to have run in a weird problem.
I have a multiset consisting of long longs, but when I try to insert number 5*1e8, it crashes. For more info, when I try to insert the number the multiset is empty ( but I don’t see how that could affect anything ). the code is down below.

I added some string outputs, to pinpoint where the program crashes. This is a solution to problem 1418D on codeforces ( https://codeforces.com/contest/1418/problem/D ) and my program crashes on the second testcase. the program stops when it hits insert which comes after lfdsa string and iterators, multiset size is outputed.

Any help is appreciated and sorry for my bad english.

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main()
{
    multiset<ll> dif,arr;
    ll n,q;
    cin>>n>>q;
    ll x[n+1];
    for(ll k=1;k<=n;k++)
    {
        cin>>x[k];
        arr.insert(x[k]);
    }
    sort(x+1,x+1+n);
    for(ll k=2;k<=n;k++)
    {
        dif.insert(x[k]-x[k-1]);
    }
    multiset<ll>::iterator st,nd,LargestDif,it;
    
    st=arr.begin();
    nd=arr.end();
    LargestDif=dif.end();
    if(n!=1) LargestDif--;
    nd--;
    if(n>2) cout<<*nd-*st-*LargestDif<<endl;
    else cout<<"0"<<endl;
    
    for(ll k=1;k<=q;k++)
    {
        ll type,cord;
        cin>>type>>cord;
        if(arr.size()<3 && type==0)
        {
            cout<<0<<endl;
            arr.erase(arr.find(cord));
            continue;
        }
        if(arr.size()<2 && type==1)
        {
            cout<<0<<endl;
            arr.insert(cord);
            continue;
        }
        cout<<"jfads"<<endl;
        if(type==1)
        {
            arr.insert(cord);
            it=arr.find(cord);
            multiset<ll>::iterator it1,it2;
            it1=it;
            it2=it;
            it2++;
            cout<<"ghfd"<<endl;
            if(it==arr.begin())
            {
                dif.insert(*it2-*it);
            }
            else
            {
                cout<<"lfds"<<endl;
                it1--;
                if(it2==arr.end())
                {
                    cout<<"klfds"<<endl;
                    dif.insert(*it-*it1);
                }
                else
                {
                    cout<<"lfdsa"<<endl;
                    dif.erase(dif.find(*it2-*it1));
                    cout<<*it<<" "<<*it2<<" "<<*it2-*it<<" "<<dif.size()<<endl;
                    ll o=*it2-*it;
                    dif.insert(o);
                    cout<<"qwere"<<endl;
                    dif.insert(*it-*it1);
                }
                cout<<";fdasd"<<endl;
            }
        }
        else
        {
            it=arr.find(cord);
            multiset<ll>::iterator it1,it2;
            it1=it;
            it2=it;
            it2++;
            if(it==arr.begin())
            {
                dif.erase(dif.find(*it2-*it));  
            }
            else
            {
                it1--;
                if(it2==arr.end())
                {
                    dif.erase(dif.find(*it-*it1));  
                }
                else
                {
                    dif.erase(dif.find(*it2-*it));
                    dif.erase(dif.find(*it-*it1));
                    dif.insert(*it2-*it1);
                }
            }
            cout<<"sanlfas"<<endl;
            arr.erase(arr.find(cord));
        }
        cout<<"dsafdsf"<<endl;
        st=arr.begin();
        nd=arr.end();
        cout<<"bcd"<<endl;
        nd--;
        cout<<"ghsfd "<<dif.size()<<endl;
        LargestDif=dif.end();
        LargestDif--;
        cout<<"oj;dfas"<<endl;
        cout<<*nd-*st-*LargestDif<<endl;
    }
}

[ad_2]

  • 0 0 Answers
  • 5 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 2 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 4 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 3 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.