读完题目,你的第一想法肯定是直接暴力就能过了。实际上在看完数据之后。。。QAQ。好吧,肯定不能暴力,那
么现在就要去寻找它的特征。根据它的特征,我们可以分析出要用线段树去做这道题。那么当我们确定这个算法时,我
们就要找下一个难点:如何建立这个树?这里就直接告诉你叭:首先,我们要根据大小将初始数组排列,然后再根据原
来的顺序再排回来,然后根据每一个数的大小对号入座,在入座的过程中我们计算在这个叶子节点的右边有多少个已经
入座的元素,这时候就体现出来了线段树的便捷:查询效率为O(log n) 级别。然后使用sum分别记录,最后输出sum。
#include <iostream>
#include <cstring>
#include <string>
#include <fstream>
#include <algorithm>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <map>
#define inf 0x7ffffff
#define ll long long
using namespace std;
ll scan() {
ll x=0;
ll flag=0;
char ch=getchar();
while(ch<'0'||ch>'9') {
ch=getchar();
if(ch=='-')
flag=