#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define REPD(i, a, b) for(int i = a; i > b; i--)
#define REPLL(i, a, b) for(ll i = a; i < b; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORD(i, a, b) for(int i = a; i >= b; i--)
#define FORLL(i, a, b) for(ll i = a; i <= b; i++)
#define INF 2000000001
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;
typedef map<int, int>::iterator mit;
typedef vector<int> vi;
typedef vector<pii > vpii;
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define EPS 1e-9
#define PI acos(-1.0)
#define MAXN 200007
int z, n, t, a, b, c;
int ans[MAXN<];
int kroot[MAXN];
int root[MAXN];
int lt[MAXN];
int rt[MAXN];
int next_free;
void build(int v, int l, int r) {
if(l==r) return;
lt[v] = next_free++;
rt[v] = next_free++;
int mid = (l+r)/2;
build(lt[v], l, mid);
build(rt[v], mid+1, r);
}
int insert(int v, int x, int l, int r) {
int nv = next_free++;
if(l == r) {
ans[nv] = 1;
return nv;
}
int mid = (l+r)/2;
lt[nv] = lt[v];
rt[nv] = rt[v];
if(x <= mid) lt[nv] = insert(lt[v], x, l, mid);
else rt[nv] = insert(rt[v], x, mid+1, r);
ans[nv] = ans[lt[nv]] + ans[rt[nv]];
return nv;
}
int query(int v, int x, int y, int l, int r) {
if(l>=x && r<=y) {
return ans[v];
}
int mid = (l+r)/2;
int ret = 0;
if(x <= mid) ret += query(lt[v], x, y, l, mid);
if(y>mid) ret += query(rt[v], x, y, mid+1, r);
return ret;
}
vpii v;
int qr;
int res[MAXN];
tuple<int,int,int,int> queries[MAXN];
int main()
{
next_free = 1;
kroot[n] = INF;
root[n] = next_free++;
build(1,1,n);
FOR(i, 1, n) {
v.pb(mp(t, i));
}
sort(ALL(v));
FORD(i, n-1, 0) {
kroot[i] = v[i].st;
root[i] = insert(root[i+1], v[i].nd, 1, n);
}
REP(i, 0, qr) {
scanf("%d%d%d", &a
, &b
, &c
); queries[i] = make_tuple(c, a, b, i);
}
sort(queries, queries+qr);
int j = n;
FORD(i, qr-1, 0) {
while(j && kroot[j-1] > get<0>(queries[i])) j--;
res[get<3>(queries[i])] = query(root[j], get<1>(queries[i]), get<2>(queries[i]), 1, n);
}
REP
(i
, 0, qr
) printf("%d\n", res
[i
]); return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CgojZGVmaW5lIEFMTCh2KSB2LmJlZ2luKCksIHYuZW5kKCkKI2RlZmluZSBSRVAoaSwgYSwgYikgZm9yKGludCBpID0gYTsgaSA8IGI7IGkrKykKI2RlZmluZSBSRVBEKGksIGEsIGIpIGZvcihpbnQgaSA9IGE7IGkgPiBiOyBpLS0pCiNkZWZpbmUgUkVQTEwoaSwgYSwgYikgZm9yKGxsIGkgPSBhOyBpIDwgYjsgaSsrKQojZGVmaW5lIEZPUihpLCBhLCBiKSBmb3IoaW50IGkgPSBhOyBpIDw9IGI7IGkrKykKI2RlZmluZSBGT1JEKGksIGEsIGIpIGZvcihpbnQgaSA9IGE7IGkgPj0gYjsgaS0tKQojZGVmaW5lIEZPUkxMKGksIGEsIGIpIGZvcihsbCBpID0gYTsgaSA8PSBiOyBpKyspCiNkZWZpbmUgSU5GIDIwMDAwMDAwMDEKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKdHlwZWRlZiBsb25nIGRvdWJsZSBsZDsKCnR5cGVkZWYgcGFpcjxpbnQsIGludD4gcGlpOwp0eXBlZGVmIHBhaXI8bGQsIGxkPiBwbGQ7CnR5cGVkZWYgdmVjdG9yPGludD46Oml0ZXJhdG9yIHZpdDsKdHlwZWRlZiBzZXQ8aW50Pjo6aXRlcmF0b3Igc2l0Owp0eXBlZGVmIG1hcDxpbnQsIGludD46Oml0ZXJhdG9yIG1pdDsKd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IHJldHVybiBudjsKfQoKaW50IHF1ZXJ5KGludCB2LCBpbnQgeCwgaW50IHksIGludCBsLCBpbnQgcikgewogICAgaWYobD49eCAmJiByPD15KSB7CiAgICAgICAgcmV0dXJuIGFuc1t2XTsKICAgIH0KICAgIGludCBtaWQgPSAobCtyKS8yOwogICAgaW50IHJldCA9IDA7CiAgICBpZih4IDw9IG1pZCkgcmV0ICs9IHF1ZXJ5KGx0W3ZdLCB4LCB5LCBsLCBtaWQpOwogICAgaWYoeT5taWQpIHJldCArPSBxdWVyeShydFt2XSwgeCwgeSwgbWlkKzEsIHIpOwogICAgcmV0dXJuIHJldDsKfQoKdnBpaSB2OwppbnQgcXI7CmludCByZXNbTUFYTl07CnR1cGxlPGludCxpbnQsaW50LGludD4gcXVlcmllc1tNQVhOXTsKCmludCBtYWluKCkKewogICAgc2NhbmYoIiVkIiwgJm4pOwogICAgbmV4dF9mcmVlID0gMTsKICAgIGtyb290W25dID0gSU5GOwogICAgcm9vdFtuXSA9IG5leHRfZnJlZSsrOwogICAgYnVpbGQoMSwxLG4pOwogICAgRk9SKGksIDEsIG4pIHsKICAgICAgICBzY2FuZigiJWQiLCAmdCk7CiAgICAgICAgdi5wYihtcCh0LCBpKSk7CiAgICB9CiAgICBzb3J0KEFMTCh2KSk7CiAgICBGT1JEKGksIG4tMSwgMCkgewogICAgICAgIGtyb290W2ldID0gdltpXS5zdDsKICAgICAgICByb290W2ldID0gaW5zZXJ0KHJvb3RbaSsxXSwgdltpXS5uZCwgMSwgbik7CiAgICB9CiAgICBzY2FuZigiJWQiLCAmcXIpOwogICAgUkVQKGksIDAsIHFyKSB7CiAgICAgICAgc2NhbmYoIiVkJWQlZCIsICZhLCAmYiwgJmMpOwogICAgICAgIHF1ZXJpZXNbaV0gPSBtYWtlX3R1cGxlKGMsIGEsIGIsIGkpOwogICAgfQogICAgc29ydChxdWVyaWVzLCBxdWVyaWVzK3FyKTsKICAgIGludCBqID0gbjsKICAgIEZPUkQoaSwgcXItMSwgMCkgewogICAgICAgIHdoaWxlKGogJiYga3Jvb3Rbai0xXSA+IGdldDwwPihxdWVyaWVzW2ldKSkgai0tOwogICAgICAgIHJlc1tnZXQ8Mz4ocXVlcmllc1tpXSldID0gcXVlcnkocm9vdFtqXSwgZ2V0PDE+KHF1ZXJpZXNbaV0pLCBnZXQ8Mj4ocXVlcmllc1tpXSksIDEsIG4pOwogICAgfQogICAgUkVQKGksIDAsIHFyKSBwcmludGYoIiVkXG4iLCByZXNbaV0pOwogICAgcmV0dXJuIDA7Cn0KCgo=