• Sign Up
• Login
• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Nov 27th, 2018 211 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1.
2. void solve(__attribute__((unused)) bool read) {
3.   int n;
4.   cin >> n;
5.   vector<double> p(n);
6.   vector<pair<int, int>> a(n);
7.   vector<Event> events;
8.   for (int i = 0; i < n; ++i) {
9.     int p0;
10.     cin >> a[i].first >> a[i].second >> p0;
11.     p[i] = p0 / 100.;
12.     events.push_back({1, a[i].first, i});
13.     events.push_back({-1, a[i].second, i});
14.   }
15.   sort(all(events));
16.   double res = 0;
17.   double log_prod = 0;
18.   int sign = 1;
19.   int open_halves = 0;
20.   for (int w = 0; w + 1 < events.size(); ++w) {
21.     auto ev = events[w];
22.     auto cur_p = p[ev.id];
23.     int is_half = fabs(cur_p - 0.5) < 1e-9;
24.     if (is_half) {
25.       open_halves += ev.type;
26.     }
27.     else if (cur_p > 0.5) {
28.       sign = -sign;
29.       log_prod += ev.type * log(2 * cur_p - 1);
30.     } else {
31.       log_prod += ev.type * log(1 - 2 * cur_p);
32.     }
33.     double odd_prob = (1 - exp(log_prod) * sign) / 2.0;
34.     if (open_halves > 0) {
35.       odd_prob = 0.5;
36.     }
37.     res += (events[w + 1].x - events[w].x) * odd_prob;
38.   }
39.   cout << res << endl;
40.
41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top