Help me in solving RANKQ problem

My issue

Can I Know how to use segment trees in this problem with the explanation and code for understanding

My code

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	return 0;
}

Problem Link: RANKQ Problem - CodeChef