/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package samples; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.security.KeyPair; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.TreeMap; import java.util.TreeSet; import javafx.util.Pair; /** * * @author cteam075 */ public class Samples { public static BufferedReader in; /** * */ public static List> samples; /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); // in = new BufferedReader(new FileReader("input.txt")); int numOfSamples = Integer.parseInt(in.readLine()); samples = new ArrayList(); for(int i = 0; i < numOfSamples; i++){ String row = in.readLine(); samples.add(new Pair(Integer.parseInt(row.split(" ")[0]), Integer.parseInt(row.split(" ")[1]))); } int numOfEvaluations = Integer.parseInt(in.readLine()); for(int i = 0; i < numOfEvaluations; i++){ String eval = in.readLine(); String relationOperator = eval.split(" ")[0]; String aggregateOperator = eval.split(" ")[1]; int seconds = Integer.parseInt(eval.split(" ")[2]); switch(aggregateOperator){ case "avg" : { if(relationOperator.compareTo("gt")==0)System.out.println(avgFunc(seconds, true)); else System.out.println(avgFunc(seconds, false)); break; } case "min" : { if(relationOperator.compareTo("gt")==0)System.out.println(minFunc(seconds, true)); else System.out.println(minFunc(seconds, false)); break; } case "max" : { if(relationOperator.compareTo("gt")==0)System.out.println(maxFunc(seconds, true)); else System.out.println(maxFunc(seconds, false)); break; } } } } public static int avgFunc(int seconds,boolean gt){ int res=0; for(int i = 0; i < samples.size(); i++){ int avg = 0; int count = 0; int actSecond = samples.get(i).getKey(); for(int j = i-1; j >= 0; j--){ if(samples.get(j).getKey() >= actSecond-seconds){ avg += samples.get(j).getValue(); count++; } } if(gt){ if(samples.get(i).getValue() > ((float)avg/(float)count))res++; }else{ if(samples.get(i).getValue() < ((float)avg/(float)count))res++; } } return res; } public static int minFunc(int seconds,boolean gt){ int res=0; for(int i = 1; i < samples.size(); i++){ if(samples.get(i).getKey()-seconds > samples.get(i-1).getKey())continue; int min = Integer.MAX_VALUE; int actSecond = samples.get(i).getKey(); for(int j = i-1; j >= 0; j--){ if(samples.get(j).getKey() >= actSecond-seconds){ if(samples.get(j).getValue() < min)min = samples.get(j).getValue(); } } if(gt){ if(samples.get(i).getValue() > min)res++; }else{ if(samples.get(i).getValue() < min){ res++; } } } return res; } public static int maxFunc(int seconds,boolean gt){ int res=0; for(int i = 1; i < samples.size(); i++){ if(samples.get(i).getKey()-seconds > samples.get(i-1).getKey())continue; int max = Integer.MIN_VALUE; int actSecond = samples.get(i).getKey(); for(int j = i-1; j >= 0; j--){ if(samples.get(j).getKey() >= actSecond-seconds){ if(samples.get(j).getValue() > max)max = samples.get(j).getValue(); } } if(gt){ if(samples.get(i).getValue() > max)res++; }else{ if(samples.get(i).getValue() < max)res++; } } return res; } }