题意
Sol
神仙题+神仙做法%%%%%%%%
我再来复述一遍。。
首先按照\(y\)坐标排序,然后维护一个扫描线从低处往高处考虑。
一个连通块的内状态使用两个变量即可维护\(ans\)表示联通块内的最大答案,\(f\)表示联通块内\(k=1\)的数量
若当前的水超过了当前的挡板,那么将当前联通块和下一个位置所在的联通块合并。
若是一个\(k=0\)的操作,则一定满足。
若是\(k=1\)的操作,那么就将\(f++\),然后更新一下答案。
#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;}
inline int read() {
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;
N = read(); M = read();
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;
}