CodeForces 815D. Karen and Cards

来源:互联网 发布:手机数据共享怎么用 编辑:程序博客网 时间:2024/06/06 03:52

Karen just got home from the supermarket, and is getting ready to go to sleep.

After taking a shower and changing into her pajamas, she looked at her shelf and saw an album. Curious, she opened it and saw a trading card collection.

She recalled that she used to play with those cards as a child, and, although she is now grown-up, she still wonders a few things about it.

Each card has three characteristics: strengthdefense and speed. The values of all characteristics of all cards are positive integers. The maximum possible strength any card can have is p, the maximum possible defense is q and the maximum possible speed is r.

There are n cards in her collection. The i-th card has a strength ai, defense bi and speed ci, respectively.

A card beats another card if at least two of its characteristics are strictly greater than the corresponding characteristics of the other card.

She now wonders how many different cards can beat all the cards in her collection. Two cards are considered different if at least one of their characteristics have different values.

Input

The first line of input contains four integers, npq and r (1 ≤ n, p, q, r ≤ 500000), the number of cards in the collection, the maximum possible strength, the maximum possible defense, and the maximum possible speed, respectively.

The next n lines each contain three integers. In particular, the i-th line contains aibi and ci (1 ≤ ai ≤ p1 ≤ bi ≤ q1 ≤ ci ≤ r), the strength, defense and speed of the i-th collection card, respectively.

Output

Output a single integer on a line by itself, the number of different cards that can beat all the cards in her collection.

Examples
input
3 4 4 52 2 51 3 44 1 1
output
10
input
5 10 10 101 1 11 1 11 1 11 1 11 1 1
output
972
Note

In the first test case, the maximum possible strength is 4, the maximum possible defense is 4 and the maximum possible speed is 5. Karen has three cards:

  • The first card has strength 2, defense 2 and speed 5.
  • The second card has strength 1, defense 3 and speed 4.
  • The third card has strength 4, defense 1 and speed 1.

There are 10 cards that beat all the cards here:

  1. The card with strength 3, defense 3 and speed 5.
  2. The card with strength 3, defense 4 and speed 2.
  3. The card with strength 3, defense 4 and speed 3.
  4. The card with strength 3, defense 4 and speed 4.
  5. The card with strength 3, defense 4 and speed 5.
  6. The card with strength 4, defense 3 and speed 5.
  7. The card with strength 4, defense 4 and speed 2.
  8. The card with strength 4, defense 4 and speed 3.
  9. The card with strength 4, defense 4 and speed 4.
  10. The card with strength 4, defense 4 and speed 5.

In the second test case, the maximum possible strength is 10, the maximum possible defense is 10 and the maximum possible speed is 10. Karen has five cards, all with strength 1, defense 1 and speed 1.

Any of the 972 cards which have at least two characteristics greater than 1 can beat all of the cards in her collection.

题意:有n张card,每张card有三个属性a, b, c,上界为p, q, r,求有多少张card能打败原来的那n张card。打败定义为至少有两个属性比另一个大。
题解:3维体积并
考虑补集转化,然后相当于有一堆限制(p, q, r),只要满足(a <= p, b <= q, c <= r)就可以了。
然后是个三维体积并
由于这题的特殊性质,所以可以按照c排序从大到小加入,然后用set维护轮廓线的拐点
#include <bits/stdc++.h>#define xx first#define yy second#define mp make_pair#define pb push_back#define fill(x, y) memset(x, y, sizeof x)#define copy(x, y) memcpy(x, y, sizeof x)using namespace std;typedef long long LL;typedef pair < int, int > pa;inline int read(){int sc = 0, f = 1; char ch = getchar();while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }while (ch >= '0' && ch <= '9') sc = sc * 10 + ch - '0', ch = getchar();return sc * f;}const int MAXN = 500005;int n, p, q, r, a[MAXN], b[MAXN], c[MAXN], top;vector < pa > v[MAXN];set < pa > S;LL ans, cur;inline void solve(pa t){auto it = S.upper_bound(t), jt = it --;int last_x = t.xx;if (jt -> yy >= t.yy) return ;while (true){cur += 1LL * (last_x - it -> xx) * (t.yy - jt -> yy);last_x = it -> xx;jt = it --;if (jt -> yy >= t.yy) break;}it = -- S.upper_bound(t);while (true){if (it -> yy > t.yy) break;jt = it --;S.erase(jt);}S.insert(t);}int main(){#ifdef wxh010910freopen("data.in", "r", stdin);#endifn = read(), p = read(), q = read(), r = read();ans = 1LL * p * q * r;for (int i = 1; i <= n; i ++) a[i] = read(), b[i] = read(), c[i] = read(), v[a[i]].pb(mp(b[i], r)), v[a[i]].pb(mp(q, c[i])), v[p].pb(mp(b[i], c[i]));S.insert(mp(0, r + 1)); S.insert(mp(q + 1, 0));for (int i = p; i; i --, ans -= cur) for (auto x : v[i]) solve(x);cout << ans << endl;return 0;}


原创粉丝点击