Number of inversions on a segment
Overall Observations
The function main() is too complex and should be broken up into multiple functions, if you do this you might notice that you are recreating your segtree struct for every query when it only needs to be created once and then each query should be applied to that structure.
Recursion is expensive in terms of resources it might be better to find iterative solutions.
The code is difficult to read and that may be why I am the first person answering.
Avoid using #include &lt;bits/stdc++.h&gt;
The header bits/stdc++.h is not part of the C++ programming standard and includes the whole world, this program needs only 2 C++ headers
#include &lt;iostream&gt;
#include &lt;vector&gt;

I realize that the programming challenge probably provided this for you, but that doesn't mean you should keep it if you know the proper includes.
Avoid using namespace std;
If you are coding professionally you probably should get out of the habit of using the using namespace std; statement. The code will more clearly define where cout and other identifiers are coming from (std::cin, std::cout). As you start using namespaces in your code it is better to identify where each function comes from because there may be function name collisions from different namespaces. The identifiercout you may override within your own classes, and you may override the operator &lt;&lt; in your own classes as well. This stack overflow question discusses this in more detail.
Variable Names
While you are using the variable names from the programming challenge, these variables names are not very descriptive and could cause you or someone who might be maintaining this code in a professional environment to make errors in the code.
Horizontal Spacing
One of the standard conventions in programming is to leave a space between an operator and an operand in any statement, this makes the code easier to read, examples:
        if(rx-lx==1){sums[x]+=v;return;}

versus
        if (rx - lx == 1) { sums[x] += v; return; }

        int m=(lx+rx)/2;

versus
        int m = (lx + rx) / 2;

Vertical Spacing
        if(rx-lx==1){sums[x]+=v;return;}
        int m=(lx+rx)/2;

versus
        if (rx - lx == 1)
        {
            sums[x] += v;
            return;
        }

        int m = (lx + rx) / 2;

As mentioned above, it isn't really clear what the variables m, rx and lx are, especially m.
Unused #define
The code contains:
#define ll long long

This is unused in the scope of the program and should be removed. There are at least 2 ways in C++ that don't require #define, one is a typedef and another is a using statement. While macros will continue to be supported in C++ to remain backwards compatible with C, the trend is to not use macros when possible.
##Magic Numbers
There are Magic Numbers throughout the program function (40, 2, 1), it might be better to create symbolic constants for them to make the code more readable and easier to maintain. These numbers may be used in many places and being able to change them by editing only one line makes maintenance easier.
Numeric constants in code are sometimes referred to as Magic Numbers, because there is no obvious meaning for them. There is a discussion of this on stackoverflow.
An enum could be used for the query type.