Mean Requests
time limit per test

4 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

In this problem you will have to deal with a real algorithm that is used in the VK social network.

As in any other company that creates high-loaded websites, the VK developers have to deal with request statistics regularly. An important indicator reflecting the load of the site is the mean number of requests for a certain period of time of T seconds (for example, T = 60 seconds = 1 min and T = 86400 seconds = 1 day). For example, if this value drops dramatically, that shows that the site has access problem. If this value grows, that may be a reason to analyze the cause for the growth and add more servers to the website if it is really needed.

However, even such a natural problem as counting the mean number of queries for some period of time can be a challenge when you process the amount of data of a huge social network. That's why the developers have to use original techniques to solve problems approximately, but more effectively at the same time.

Let's consider the following formal model. We have a service that works for n seconds. We know the number of queries to this resourceat at each moment of time t (1 ≤ t ≤ n). Let's formulate the following algorithm of calculating the mean with exponential decay. Let c be some real number, strictly larger than one.

  1. // setting this constant value correctly can adjust // the time range for which statistics will be calculated double c = some constant value;
    // as the result of the algorithm's performance this variable will contain // the mean number of queries for the last // T seconds by the current moment of time double mean = 0.0;
    for t = 1..n: // at each second, we do the following: // at is the number of queries that came at the last second; mean = (mean + at / T) / c;

Thus, the mean variable is recalculated each second using the number of queries that came at that second. We can make some mathematical calculations and prove that choosing the value of constant c correctly will make the value of mean not very different from the real mean value ax at t - T + 1 ≤ x ≤ t.

The advantage of such approach is that it only uses the number of requests at the current moment of time and doesn't require storing the history of requests for a large time range. Also, it considers the recent values with the weight larger than the weight of the old ones, which helps to react to dramatic change in values quicker.

However before using the new theoretical approach in industrial programming, there is an obligatory step to make, that is, to test its credibility practically on given test data sets. Your task is to compare the data obtained as a result of the work of an approximate algorithm to the real data.

You are given n values at, integer T and real number c. Also, you are given m moments pj (1 ≤ j ≤ m), where we are interested in the mean value of the number of queries for the last T seconds. Implement two algorithms. The first one should calculate the required value by definition, i.e. by the formula . The second algorithm should calculate the mean value as is described above. Print both values and calculate the relative error of the second algorithm by the formula , where approx is the approximate value, obtained by the second algorithm, and real is the exact value obtained by the first algorithm.

Input

The first line contains integer n (1 ≤ n ≤ 2·105), integer T (1 ≤ T ≤ n) and real number c (1 < c ≤ 100) — the time range when the resource should work, the length of the time range during which we need the mean number of requests and the coefficient c of the work of approximate algorithm. Number c is given with exactly six digits after the decimal point.

The next line contains n integers at (1 ≤ at ≤ 106) — the number of queries to the service at each moment of time.

The next line contains integer m (1 ≤ m ≤ n) — the number of moments of time when we are interested in the mean number of queries for the last T seconds.

The next line contains m integers pj (T ≤ pj ≤ n), representing another moment of time for which we need statistics. Moments pj are strictly increasing.

Output

Print m lines. The j-th line must contain three numbers realapprox and error, where:

  •  is the real mean number of queries for the last T seconds;
  • approx is calculated by the given algorithm and equals mean at the moment of time t = pj (that is, after implementing the pj-th iteration of the cycle);
  •  is the relative error of the approximate algorithm.

The numbers you printed will be compared to the correct numbers with the relative or absolute error 10 - 4. It is recommended to print the numbers with at least five digits after the decimal point.

Sample test(s)
input
  1. 1 1 2.000000 1 1 1
output
  1. 1.000000 0.500000 0.500000
input
  1. 11 4 1.250000 9 11 7 5 15 6 6 6 6 6 6 8 4 5 6 7 8 9 10 11
output
  1. 8.000000 4.449600 0.443800 9.500000 6.559680 0.309507 8.250000 6.447744 0.218455 8.000000 6.358195 0.205226 8.250000 6.286556 0.237993 6.000000 6.229245 0.038207 6.000000 6.183396 0.030566 6.000000 6.146717 0.024453
input
  1. 13 4 1.250000 3 3 3 3 3 20 3 3 3 3 3 3 3 10 4 5 6 7 8 9 10 11 12 13
output
  1. 3.000000 1.771200 0.409600 3.000000 2.016960 0.327680 7.250000 5.613568 0.225715 7.250000 5.090854 0.297813 7.250000 4.672684 0.355492 7.250000 4.338147 0.401635 3.000000 4.070517 0.356839 3.000000 3.856414 0.285471 3.000000 3.685131 0.228377 3.000000 3.548105 0.182702
    我看不懂关于real的那个公式。后来发现他是前T个的meanorz
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<math.h>
  4. using namespace std;
  5. typedef long long ll ;
  6. const int M = * 1e5 + ;
  7. int a [M] ;
  8. int n , T , m;
  9. double c ;
  10. double real , mean , error ;
  11.  
  12. int main ()
  13. {
  14. // freopen ("a.txt" , "r" , stdin ) ;
  15. scanf ("%d%d%lf" , &n , &T , &c) ;
  16. for (int i = ; i <= n ; i++) {
  17. scanf ("%d", &a[i] ) ;
  18. }
  19. scanf ("%d" , &m) ;
  20.  
  21. int b[M] ;
  22. for (int i = ; i <= m ; i++) {
  23. scanf ("%d" , &b[i]) ;
  24. }
  25. double sum = ;
  26. double mean = ;
  27. int k = ;
  28. for (int i = ; i <= n ; i++) {
  29. sum += a[i] ;
  30. if (i > T) {
  31. sum -= a[i - T] ;
  32. }
  33. mean = (double) 1.0 * (mean + 1.0 * a[i] / T) / c ;
  34. if (i == b[k]) {
  35. real = 1.0 * sum / T ;
  36. error = fabs (real - mean) / real ;
  37. printf ("%.6f %.6f %.6f\n" , real , mean , error ) ;
  38. k++ ;
  39. }
  40. }
  41. return ;
  42. }

cf.VK CUP 2015.B.Mean Requests的更多相关文章

  1. cf.VK CUP 2015.C.Name Quest(贪心)

    Name Quest time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  2. Codeforces Round VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM 暴力出奇迹!

    VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM Time Lim ...

  3. Codeforces VK CUP 2015 D. Closest Equals(线段树+扫描线)

    题目链接:http://codeforces.com/contest/522/problem/D 题目大意:  给你一个长度为n的序列,然后有m次查询,每次查询输入一个区间[li,lj],对于每一个查 ...

  4. VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) E. Correcting Mistakes 水题

    E. Correcting Mistakes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...

  5. VK Cup 2015 - Finals, online mirror D. Restructuring Company 并查集

    D. Restructuring Company Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  6. VK Cup 2015 - Round 1 -E. Rooks and Rectangles 线段树最值+扫描线

    题意: n * m的棋盘, k个位置有"rook"(车),q次询问,问是否询问的方块内是否每一行都有一个车或者每一列都有一个车? 满足一个即可 先考虑第一种情况, 第二种类似,sw ...

  7. VK Cup 2015 - Round 2 (unofficial online mirror, Div. 1 only) B. Work Group 树形dp

    题目链接: http://codeforces.com/problemset/problem/533/B B. Work Group time limit per test2 secondsmemor ...

  8. VK Cup 2015 - Qualification Round 1 D. Closest Equals 离线+线段树

    题目链接: http://codeforces.com/problemset/problem/522/D D. Closest Equals time limit per test3 secondsm ...

  9. codeforces VK Cup 2015 - Qualification Round 1 B. Photo to Remember 水题

    B. Photo to Remember Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/522/ ...

随机推荐

  1. MVC5 + EF6 + Bootstrap3 (7) Bootstrap的栅格系统

    文章来源: Slark.NET-博客园http://www.cnblogs.com/slark/p/mvc5-ef6-bs3-get-started-grid.html 上一节:ASP.NET MVC ...

  2. 【APUE】Chapter17 Advanced IPC & sign extension & 结构体内存对齐

    17.1 Introduction 这一章主要讲了UNIX Domain Sockets这样的进程间通讯方式,并列举了具体的几个例子. 17.2 UNIX Domain Sockets 这是一种特殊s ...

  3. 一句话概括下spring框架及spring cloud框架主要组件

    作为java的屌丝,基本上跟上spring屌丝的步伐,也就跟上了主流技术.spring 顶级项目:Spring IO platform:用于系统部署,是可集成的,构建现代化应用的版本平台,具体来说当你 ...

  4. c# r3 inline hook

    前言 老婆喜欢在QQ游戏玩拖拉机,且安装了一个记牌器小软件,打开的时候弹出几个IE页面加载很多广告,于是叫我去掉广告.想想可以用OD进行nop填充,也可以写api hook替换shellexecute ...

  5. jquery的基本动画方法

    1 在使用$.extent()的时候,我们一般不放function类型,如果放的话,提前测试下. ?2 Function类型是一种基本类型还是引用类型呢. 3 $('<div>') 指创建 ...

  6. asp.net 预编译和动态编译

    在asp.net中,编译可以分为:动态编译Dynamical Compilation和预编译(Precompilation). 动态编译 深入剖析ASP.NET的编译原理之一:动态编译(Dynamic ...

  7. 一头扎进EasyUI2

    惯例广告一发,对于初学真,真的很有用www.java1234.com,去试试吧! 一头扎进EasyUI第6讲 .日历组件 <div class="easyui-calendar&quo ...

  8. asp.net mvc 中的部分视图

    使用方法:@Html.Action(action, controller)加载局部页面.例如在模板页中使用:@Html.Action("Contact", "Compan ...

  9. jquery.validate.js常用扩展函数

    $(function () { // 判断整数value是否等于0 jQuery.validator.addMethod("isIntEqZero", function (valu ...

  10. Daily Scrum – 1/5

    Meeting Minutes 开始了新的sprint: 开始准备英语版本的翻译: Progress part 组员 今日工作 Time (h) 明日计划 Time (h)   Wei         ...