#include using namespace std; #define REP(i,n) for (int i = 0; i < (n); ++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 pii pair #define mp make_pair #define X first #define Y second #define maxN 100005 #define maxLog 18 int presum[maxN]; int mmin[maxN][maxLog]; int mmax[maxN][maxLog]; int N, C; pii samples[maxN]; //function conditions[12]; char buf1[10]; char buf2[10]; int time_prev[12]; int main() { while (scanf("%d", &N) == 1) { REP(i, N) scanf("%d%d", &samples[i].X, &samples[i].Y); presum[0] = 0; REP(i, N) presum[i + 1] = presum[i] + samples[i].Y; REP(i, N) mmin[i][0] = mmax[i][0] = samples[i].Y; FOR(k, 1, maxLog-1) REP(i, N) { if (i + (1 << (k-1)) >= maxN) break; mmin[i][k] = min(mmin[i][k-1], mmin[i + (1 << (k-1))][k-1]); mmax[i][k] = max(mmax[i][k-1], mmax[i + (1 << (k-1))][k-1]); } // REP(i, N+1) { // printf("%d:\n", i); // printf(" presum %d\n", presum[i]); // printf(" min"); // REP(k, maxLog) printf(" %d:%d", k, mmin[i][k]); // printf("\n"); // printf(" max"); // REP(k, maxLog) printf(" %d:%d", k, mmax[i][k]); // printf("\n"); // } scanf("%d", &C); REP(i, C) { scanf("%s%s%d", buf1, buf2, &time_prev[i]); auto condition = [&](int from, int to, int val) { double val2; if (buf2[0] == 'a') { // printf("%d %d %d\n", presum[to+1], presum[from], presum[to+1]-presum[from]); val2 = (double)(presum[to + 1] - presum[from]) / ((double)to - from + 1); } else { int k = 0; while ((1 << (k + 1)) <= to - from + 1) ++k; if (buf2[1] == 'i') { val2 = min(mmin[from][k], mmin[to - (1< val2; else return val < val2; }; int Cnt = 0; FOR(j, 1, N-1) { int to = j-1; int from_l = 0, from_r = j, from; while (from_r > from_l + 1) { from = (from_l + from_r) / 2; if (samples[from].X > samples[j].X - time_prev[i]) from_r = from; else from_l = from; } from = from_l; // printf("in %d, cond %d (look %d back), f-t: %d %d\n", j, i, time_prev[i], from, to); if (condition(from, to, samples[j].Y)) ++Cnt; } printf("%d\n", Cnt); } } return 0; }