トピックリンク
問題の意味
N- $ $竹の木は、その後、$ Q $操作を使用して、$ L、R、X、Y $は、$の竹を示す[Lは、R] $ $ Y $間隔回カット各動作は、ある、あります伐採と同じ長さ(高さは、独自のカット$ lenの$を設定し、間隔がlen $木がKandao $ LEN $を持つ$よりも大きい)、カットの高さは($ yの後の点に注意してくださいどのくらいあるあなたの最初の$のx $の時間を尋ねますインターバル$が回を伐採した後、竹の高さ)は$同時に$ 0になると聞いてきます。
考え
$ Y $時間が削減されるので、木の高さは$ 0 $となり、各カットの長さの合計が等しく、$ Yの$で割ったX高さに対する各カット竹部、$フロントの長さ$ X-のため伐採$の全高が背の高い竹($ SUM1 $として示される)の木の数、竹の高さを削減し、$するよりもXの$時間を見つけるためにどのツリー会長の高さを切断最初の$のLENの$、その後半分SUM2 $は、その後、$ SUM2-SUM1の比較関係半ば$と境界の$ X * LENの$調整を。
誕生日が数日間家に帰るので、学校のつ以上のクッションは、いくつかのブログは、トレーニング中に水問題を持っているふりを書く〜
コード
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define lson (rt<<1),L,mid
#define rson (rt<<1|1),mid + 1,R
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("/home/dillonh/CLionProjects/Dillonh/in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)
const double eps = 1e-8;
const int mod = 1000000007;
const int maxn = 200000 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
int n, q, cnt, l, r, x, y;
int root[maxn];
LL sum1, sum2, sum[maxn];
struct node {
int l, r;
LL sum1, sum2;
}tree[maxn*40];
void update(int l, int r, int& x, int y, int pos) {
tree[++cnt] = tree[y], tree[cnt].sum1 += 1, tree[cnt].sum2 += pos, x = cnt;
if(l == r) return;
int mid = (l + r) >> 1;
if(pos <= mid) update(l, mid, tree[x].l, tree[y].l, pos);
else update(mid + 1, r, tree[x].r, tree[x].r, pos);
}
void query(int l, int r, int x, int y, double pos) {
if(l == r) {
if(pos - l >= eps) {
sum1 += tree[y].sum1 - tree[x].sum1;
sum2 += tree[y].sum2 - tree[x].sum2;
}
return;
}
int mid = (l + r) >> 1;
if(mid - pos > eps) query(l, mid, tree[x].l, tree[y].l, pos);
else {
sum1 += tree[tree[y].l].sum1 - tree[tree[x].l].sum1;
sum2 += tree[tree[y].l].sum2 - tree[tree[x].l].sum2;
query(mid + 1, r, tree[x].r, tree[y].r, pos);
}
}
int main() {
#ifndef ONLINE_JUDGE
FIN;
#endif
scanf("%d%d", &n, &q);
for(int i = 1; i <= n; ++i) {
scanf("%d", &x);
sum[i] = sum[i-1] + x;
update(0, 100000, root[i], root[i-1], x);
}
while(q--) {
scanf("%d%d%d%d", &l, &r, &x, &y);
double len = 1.0 * (sum[r] - sum[l-1]) / y * x;
double ub = 100000.0, lb = 0.0, mid, ans = 0.0;
for(int i = 0; i < 100; ++i) {
mid = (ub + lb) / 2;
sum1 = sum2 = 0;
query(0, 100000, root[l-1], root[r], mid);
double tot = 1.0 * (sum[r] - sum[l-1] - sum2);
double big = 1.0 * (r - l + 1 - sum1);
if(tot - big * mid - len > eps) {
ans = mid;
lb = mid;
} else {
ub = mid;
}
}
printf("%.7f\n", ans);
}
return 0;
}