# loj#6032. 「雅礼集训 2017 Day2」水箱(并查集 贪心 扫描线)

## Sol

```#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int MAXN = 1e6 + 10, INF = 1e9 + 7, mod = 998244353;
template <typename A, typename B> inline bool chmin(A &a, B b){if(a > b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline bool chmax(A &a, B b){if(a < b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline LL add(A x, B y) {if(x + y < 0) return x + y + mod; return x + y >= mod ? x + y - mod : x + y;}
template <typename A, typename B> inline void add2(A &x, B y) {if(x + y < 0) x = x + y + mod; else x = (x + y >= mod ? x + y - mod : x + y);}
template <typename A, typename B> inline LL mul(A x, B y) {return 1ll * x * y % mod;}
template <typename A, typename B> inline void mul2(A &x, B y) {x = (1ll * x * y % mod + mod) % mod;}
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, M, cnt, ans[MAXN], f[MAXN], fa[MAXN];
int find(int x) {
return fa[x] ? fa[x] = find(fa[x]) : x;
}
struct Query {
int opt, x, y;
bool operator < (const Query &rhs) const {
return y == rhs.y ? opt < rhs.opt : y < rhs.y;
}
}q[MAXN];
void solve() {
memset(ans, 0, sizeof(ans)); memset(f, 0, sizeof(f)); memset(fa, 0, sizeof(fa));
cnt = 0;
for(int i = 1; i < N; i++) q[++cnt] = {-1, i, read()};
for(int i = 1; i <= M; i++) q[++cnt].x = read(), q[cnt].y = read(), q[cnt].opt = read();
stable_sort(q + 1, q + cnt + 1);
int ret = 0;
for(int i = 1; i <= cnt; i++) {
int op = q[i].opt, x = q[i].x;
if(op == -1) {
int y = find(x + 1); x = find(x);
fa[y] = x; f[x] += f[y]; ans[x] += ans[y]; chmax(ret, ans[x]);
} else if(op == 0) {
chmax(ret, ++ans[find(x)]);
} else {
x = find(x); chmax(ans[x], ++f[x]);
chmax(ret, ans[x]);
}
}
cout << ret << '\n';
}
int main() {
for(int T = read(); T--; solve());
return 0;
}```

1811 篇文章126 人订阅

0 条评论

## 相关文章

12720

### 实验2 基本图元光栅化

（1） 阅读学习所给的直线光栅化的DDA算法示范代码，将其彻底弄懂，根据实验思考题找出其中的错误；同时能在计算机上编译运行，输出正确结果，指出错误并截图保存为图...

11520

### LeetCode 975 Odd Even Jump

You are given an integer array A. From some starting index, you can make a seri...

15630

### LeetCode 974 Subarray Sums Divisible by K

Given an array A of integers, return the number of (contiguous, non-empty) subar...

13420

15310

33620

### LeetCode 976 Largest Perimeter Triangle

Given an array A of positive lengths, return the largest perimeter of a triangle...

11530

35730

### LeetCode 973 K Closest Points to Origin

We have a list of points on the plane. Find the K closest points to the origin ...

13430

### LeetCode 949 Largest Time for Given Digits

Given an array of 4 digits, return the largest 24 hour time that can be made.

12230