#include using namespace std; #define max(a,b) ((a>b)?(a):(b)) #define min(a,b) ((a>b)?(b):(a)) typedef struct { int sum, min, max; } node; int getMin(node tree[], int left, int right, int rS, int rE, int trI); int getMin(node tree[], int left, int right, int rS, int rE, int trI) { int mid = (rS+rE)/2; if(left <= rS && right >= rE-1) return tree[trI].min; if(left >= mid) return getMin(tree, left, right, mid, rE, trI*2+1); if(right < mid) return getMin(tree, left, right, rS, mid, trI*2); int l = getMin(tree, left, right, mid, rE, trI*2+1); int r = getMin(tree, left, right, rS, mid, trI*2); return min(l,r); } int getMax(node tree[], int left, int right, int rS, int rE, int trI); int getMax(node tree[], int left, int right, int rS, int rE, int trI) { int mid = (rS+rE)/2; if(left <= rS && right >= rE-1) return tree[trI].max; if(left >= mid) return getMax(tree, left, right, mid, rE, trI*2+1); if(right < mid) return getMax(tree, left, right, rS, mid, trI*2); int l = getMax(tree, left, right, mid, rE, trI*2+1); int r = getMax(tree, left, right, rS, mid, trI*2); return max(l,r); } int getSum(node tree[], int left, int right, int rS, int rE, int trI); int getSum(node tree[], int left, int right, int rS, int rE, int trI) { int mid = (rS+rE)/2; if(left <= rS && right >= rE-1) return tree[trI].sum; if(left >= mid) return getSum(tree, left, right, mid, rE, trI*2+1); if(right < mid) return getSum(tree, left, right, rS, mid, trI*2); int l = getSum(tree, left, right, mid, rE, trI*2+1); int r = getSum(tree, left, right, rS, mid, trI*2); return l+r; } int main(){ int n, k = 1; while(cin >> n) { while(k> times[i] >> tmp; tree[k+i] = node{tmp,tmp,tmp}; } i+=k; for(; i<2*k; ++i) { tree[i] = node{0,1000000001,0}; } int k2 = k/2; while(k2 >0) { for(int i = k2; i<2*k2;++i) { tree[i].sum = tree[i*2].sum+tree[i*2+1].sum; tree[i].max = max(tree[i*2].max,tree[i*2+1].max); tree[i].min = min(tree[i*2].min,tree[i*2+1].min); } k2/=2; } int l; cin >> l; while(l--) { string s1,s2; int tf; cin >> s1 >> s2 >> tf; int index = n-1; int res = 0; for(int i = n-1; i>0; i--) { while(index >=0 && times[i]-times[index] <= tf) index--; if(index+1 == i) continue; double num; if(s2 == "min") num = getMin(tree, k+index+1, k+i-1, k, 2*k, 1); else if(s2 == "max") num = getMax(tree, k+index+1, k+i-1, k, 2*k, 1); else num = getSum(tree, k+index+1, k+i-1, k, 2*k, 1) / (double)(i-(index + 1)); if(s1 == "gt") { res += tree[i+k].sum > num; } else { res += tree[i+k].sum < num; } } cout << res << endl; } } return 0; }