Suspicious Samples
Time limit2sMemory limit512 MB
For each condition, count samples whose value is greater or less than the min, max, or average of samples in the preceding time window.
- Level
Medium6 of 10
- Topics
- Sliding window, Queue, Array, Implementation
- Solved
- No attempts yet
Problem
Fatima is a researcher. She studies water circulation in the river basins of her country. She collects samples from meteorological stations that measure various climate values, then looks for interesting patterns in those samples. Her program reads incoming sample data in real time and prints the samples that are interesting or suspicious in some way. Whether a sample counts as interesting or suspicious is decided by a fixed set of conditions, such as "the value is greater than the average of the last two hours" or "the value is lower than anything else in the last five minutes". Conditions like these are easy to put into a program.
Today Fatima doubts yesterday's results, so she came to you, an experienced programmer. She thinks her program did not evaluate the data correctly and asks you to verify its results. She brings the complete sequence of samples and describes the set of conditions. Read the samples and produce the output the conditions call for. Fatima will compare your output with the output of her program and decide what to do next.
Input
The input holds several test cases. Process it until end of file.
The first line of each test case contains one integer (), the number of samples. Each of the following lines describes one sample with two integers and (, ), meaning that the sample value was acquired at time . Times are given in seconds elapsed since some fixed moment in the past and form a strictly increasing sequence ( for all and with ).
The next line contains one integer (), the number of conditions to evaluate. Each of the following lines specifies one condition as three tokens separated by a space.
- A relation operator , either gt (greater than) or lt (less than).
- An aggregate function , one of min (minimum), max (maximum), avg (average).
- An integer (), the length of the time interval to consider, in seconds.
A condition applied to a sample value checks how relates to an aggregate of the samples acquired before . The function picks that aggregate.
Precisely, is the set of all samples acquired before but no more than seconds earlier, that is, every sample with . The sample value satisfies condition if and only if the relation holds. For example, the sample value 800 together with lt min 300 reads as "is 800 less than the minimum sample value acquired in the five minutes before this 800 was obtained?". The sample itself is not an element of . The average is the exact value, with no rounding.
The sum of over all test cases does not exceed .
Output
For each test case, take the conditions in the order they are given and print one integer per condition on its own line: the number of sample values that satisfy that condition. If the time interval a condition specifies holds no samples, that condition is never counted as satisfied.