Codeforces 138C (interval update + discretization)

Source: Internet
Author: User

Test instructions: There are n trees on the horizon, given the coordinates and height of each tree, then the probability of falling to the left and the probability of falling to the right, and 1, and then given the location of the M mushroom, each mushroom has a magical value, if the mushroom is crushed, that is, in a tree [A[i]-h[i], a[i]) or (A[i], a [i] + h[i]] within the range, the magic value is gone, only the mushrooms that survive have magical values, and ask to survive the magical values of the mushroom's expectations.
The problem: You can see that the range of N and M is 1e5, and the coordinate range is 1e9, so be sure to discretization, and then update the probability value of each interval, single-point query each mushroom interval of the probability value by its magic value.

#include <cstdio>#include <cstring>#include <algorithm>#include <map>using namespace STD;Const intN =100005;intN, M, A[n], h[n], b[n], z[n], c[n <<2];DoubleTree[n <<4], Flag[n <<4], Pl[n], pr[n]; map<int, int>mpvoidPushdown (intK) {if(Flag[k]) {Tree[k *2] *= Tree[k]; Tree[k *2+1] *= Tree[k]; Flag[k *2] = Flag[k *2+1] =1; TREE[K] =1.0; FLAG[K] =0; }}voidBuildintKintLeftintright) {Flag[k] =0; TREE[K] =1.0;if(Left! = right) {intMid = (left + right)/2; Build (k *2, left, mid); Build (k *2+1, Mid +1, right); }}voidModifyintKintLeftintRightintL1,intR1,Doublex) {if(L1 <= left && right <= R1)        {tree[k] *= x; FLAG[K] =1;return; } pushdown (k);intMid = (left + right)/2;if(L1 <= mid) modify (k *2, left, Mid, L1, R1, X);if(R1 > Mid) modify (k *2+1, Mid +1, right, L1, R1, x);}DoubleQueryintKintLeftintRightintPOS) {if(left = right)returnTREE[K]; Pushdown (k);intMid = (left + right)/2;if(Pos <= mid)returnQuery (k *2, left, Mid, POS);Else        returnQuery (k *2+1, Mid +1, right, POS);}intMain () {scanf("%d%d", &n, &m); Mp.clear ();intCNT =0; for(inti =1; I <= N; i++) {scanf("%D%D%LF%LF", &a[i], &h[i], &pl[i], &pr[i]); Pl[i]/=100.0, Pr[i]/=100.0;        C[++CNT] = A[i];        C[++CNT] = A[i]-h[i];    C[++CNT] = A[i] + h[i]; } for(inti =1; I <= m; i++) {scanf("%d%d", &b[i], &z[i]);    C[++CNT] = B[i]; } sort (C +1, C +1+ CNT); CNT = unique (c +1, C +1+ CNT)-(c +1); for(inti =1; I <= CNT;    i++) Mp[c[i]] = i; Build1,1, CNT); for(inti =1; I <= N; i++) {Modify (1,1, CNT, Mp[a[i]-h[i]], Mp[a[i]-1,1.0-Pl[i]); Modify1,1, CNT, Mp[a[i]] +1, Mp[a[i] + h[i]],1.0-Pr[i]); }Doubleres =0; for(inti =1; I <= m; i++) Res + = z[i] * Query (1,1, CNT, mp[b[i]]);printf("%lf\n", res);return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codeforces 138C (interval update + discretization)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.