摘要:很容易想到离线的做法,倍增往上找,然后整个dfs一遍,但是需要用到树状数组 顺便,求log2(x)千万别写log(x) / log(2),精度会出问题,直接写log2(x)就行了 #include <bits/stdc++.h> using namespace std; const int N =
阅读全文
摘要:从左往右扫,找到比第i个小的第一个数字,l[i] = l[last] + (i - last) * m[i],用单调栈O(n)维护这个过程,再从右往左扫,同理可以算出r数组,注意一下long long #include <bits/stdc++.h> using namespace std; con
阅读全文