• [deleted]
    + 2 comments

    include

    include

    using namespace std;

    int main() { int n=0,m=0; int t=0,l=0,r=0,x=0,sum=0; cin>>n>>m; int arr[n];

    for(int i=0;i<n;i++)
    {
        cin>>arr[n];
    }
    while(m--)
    {
        cin>>t>>l>>r;
        sum=0,x=0;
        if(t==1)
        {
            for(int j=l-1;j<=r-1;j+=2)
            {
                x = arr[j];
                arr[j] = arr[j+1];
                arr[j+1] = x;
            }
        }
        else if(t==2)
        {
            sum = 0;
            for(int k=l-1;k<=r-1;k++)
            {
                sum+=arr[k];
            }
            cout<<sum<<endl;
    
    Can anyone explain the error in this code
        }
    }
    return 0;
    

    }