#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include #define rep(i,n) for(int i=0;i<(n);i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) ((int)(x).size()) #define pb push_back using ll = long long; using namespace std; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> N >> M; int mx = 100010; vector A(mx,0); vector> Q(N); int B = 320; vector>> qv(B,vector>(B)); vector>> qa(B,vector>(B)); rep(i,B){ rep(j,B){ qv[i][j].pb(0); qv[i][j].pb(1<<30); } } rep(i,N){ int l,r,x,y; cin >> l >> r >> x >> y; Q[i] = {l,r,x,y}; if(x>=B){ for(ll a=y;a> a; int ans = A[a]; for(int x=1;x