#include <stdio.h> #include <cstring> #include <cstdlib> #include <cmath> #include <iostream> #include <algorithm> #define maxn 500010 using namespace std; struct point { int l,r,val; }tr[maxn*4]; int m,n; int a[maxn]; void buildtree(int x,int l,int r) { ...