#include using namespace std; #define rep(i, a, n) for (int i=(a); i < (n); i++) #define per(i, a, n) for (int i=(n)-1; i >= (a); i--) #define FOR(i, n) for (int i=0; i sp; set > d_s; int d_c, d_sum; void add(int i) { d_s.insert({sp[i].v, sp[i].t}); d_sum += sp[i].v; d_c++; } void del(int i) { d_s.erase({sp[i].v, sp[i].t}); d_sum -= sp[i].v; d_c--; } double op(char c) { switch (c) { case 'i': // min return d_s.begin()->first; case 'a': // max return (--d_s.end())->first; default: // avg return ((double)d_sum) / d_c; } } bool splnuje(int v, char rel, double w) { if (rel == 'l') // lt, < return v < w; else // gt, > return v > w; } int walk(char rel, char agg, int tframe) { int cnt = 0, start = 0; for(int i=0; i < N; add(i++)){ int t = sp[i].t, v = sp[i].v; while (sp[start].t < t - tframe) del(start++); if (start == i) // žádný vzorek v zadaném čase continue; double hist = op(agg); // printf("%d %d %d %lf\n", start, i, v, hist); if (splnuje(v, rel, hist)) cnt++; } return cnt; } void solve(void) { sp = {}; FOR(i, N){ int t, v; scanf("%d %d", &t, &v); sp.push_back({t, v}); } int C; scanf("%d", &C); FOR(i, C){ char buf[5]; char rel, agg; scanf("%s", buf); rel = buf[0]; scanf("%s", buf); agg = buf[1]; int frame; scanf("%d", &frame); d_s = {}, d_c = 0, d_sum = 0; printf("%d\n", walk(rel, agg, frame)); } } int main(void) { while (scanf("%d", &N) == 1) solve(); return 0; }