#include<bits/stdc++.h> #define FIO cin.tie(0); ios::sync_with_stdio(false) #define all(x) (x).begin(), (x).end() #define fi first #define se second #define TEST #define TESTS int t = 1; cin >> t; while (t--)
#include<bits/stdc++.h> #define FIO cin.tie(0); ios::sync_with_stdio(false) #define all(x) (x).begin(), (x).end() #define fi first #define se second #define TEST #define TESTS int t = 1; cin >> t; while (t--)
usingnamespace std; using i64 = longlong; using u32 = unsigned; using u64 = unsignedlonglong; using pii = std::pair<int, int>;
constexprint N = 2e5 + 10; constexprint MOD = 998244353;
int n, m, cnt; int t[N], ans[N], p[N], pos[N]; struct { int t, p, v, o; } q[N];
voidadd(int x, int v){ while (x <= n) { t[x] += v; x += x & -x; } }
intquery(int x){ int res = 0; while (x) { res += t[x]; x -= x & -x; } return res; }
voidcdq(int l, int r){ if (l == r) return; int mid = l + r >> 1; cdq(l, mid); cdq(mid + 1, r); int j = l - 1; for (int i = mid + 1; i <= r; ++i) { while (j + 1 <= mid && q[j + 1].p < q[i].p) { j++; add(q[j].v, q[j].o); } ans[q[i].t] += q[i].o * (query(n) - query(q[i].v)); } for (int i = l; i <= j; ++i) { add(q[i].v, -q[i].o); } j = mid + 1; for (int i = r; i > mid; --i) { while (j - 1 >= l && q[j - 1].p > q[i].p) { j--; add(q[j].v, q[j].o); } ans[q[i].t] += q[i].o * (query(q[i].v - 1)); } for (int i = mid; i >= j; --i) { add(q[i].v, -q[i].o); } sort(q + l, q + r + 1, [&](auto x, auto y) { return x.p < y.p; }); }
voidsolve(){ cin >> n >> m; for (int i = 1; i <= n; ++i) { cin >> p[i]; pos[p[i]] = i; ++cnt; q[cnt] = {0, i, p[i], 1}; } for (int i = 1; i <= m; ++i) { int x; cin >> x; ++cnt; q[cnt] = {i, pos[x], x, -1}; } cdq(1, cnt); for (int i = 1; i < m; ++i) { ans[i] += ans[i - 1]; } for (int i = 0; i < m; ++i) { cout << ans[i] << "\n"; } }
#include<bits/stdc++.h> #define FIO cin.tie(0); ios::sync_with_stdio(false) #define all(x) (x).begin(), (x).end() #define fi first #define se second #define TEST #define TESTS int t = 1; cin >> t; while (t--)
#include<bits/stdc++.h> #define FIO cin.tie(0); ios::sync_with_stdio(false) #define all(x) (x).begin(), (x).end() #define fi first #define se second #define TEST #define TESTS int t = 1; cin >> t; while (t--)
#include<bits/stdc++.h> #define FIO cin.tie(0); ios::sync_with_stdio(false) #define all(x) (x).begin(), (x).end() #define fi first #define se second #define TEST #define TESTS int t = 1; cin >> t; while (t--)
#include<bits/stdc++.h> #define FIO cin.tie(0); ios::sync_with_stdio(false) #define all(x) (x).begin(), (x).end() #define fi first #define se second #define TEST #define TESTS int t = 1; cin >> t; while (t--)
#include<bits/stdc++.h> #define FIO cin.tie(0); ios::sync_with_stdio(false) #define all(x) (x).begin(), (x).end() #define fi first #define se second #define TEST #define TESTS int t = 1; cin >> t; while (t--)
#include<bits/stdc++.h> #define FIO cin.tie(0); ios::sync_with_stdio(false) #define all(x) (x).begin(), (x).end() #define fi first #define se second #define TEST #define TESTS int t = 1; cin >> t; while (t--)
#include<bits/stdc++.h> #define FIO cin.tie(0); ios::sync_with_stdio(false) #define all(x) (x).begin(), (x).end() #define fi first #define se second #define TEST #define TESTS int t = 1; cin >> t; while (t--)
usingnamespace std; using i64 = longlong; using u32 = unsigned; using u64 = unsignedlonglong; using pii = std::pair<int, int>;
constexprint N = 1e5 + 10; constexprint MOD = 998244353;
struct { int v, lv, rv, i; } q[N], q1[N], q2[N]; int dp[N], t[N]; int n, m;
voidmodify(int x, int v){ while (x <= n) { chkmax(t[x], v); x += x & -x; } }
intquery(int x){ int res = 0; while (x) { chkmax(res, t[x]); x -= x & -x; } return res; }
voidclear(int x){ while (x <= n) { t[x] = 0; x += x & -x; } }
voidcdq(int l, int r){ if (l == r) return; int mid = l + r >> 1; cdq(l, mid); for (int i = l; i <= mid; ++i) q1[i] = q[i]; for (int i = mid + 1; i <= r; ++i) q2[i] = q[i]; sort(q1 + l, q1 + mid + 1, [&](auto x, auto y) { return x.rv < y.rv; }); sort(q2 + mid + 1, q2 + r + 1, [&](auto x, auto y) { return x.v < y.v; }); int j = l - 1; for (int i = mid + 1; i <= r; ++i) { while (j + 1 <= mid && q1[j + 1].rv <= q2[i].v) { j++; modify(q1[j].v, dp[q1[j].i]); } chkmax(dp[q2[i].i], query(q2[i].lv) + 1); } for (int i = l; i <= j; ++i) { clear(q1[i].v); } cdq(mid + 1, r); }
voidsolve(){ cin >> n >> m; for (int i = 1; i <= n; ++i) { auto& [v, lv, rv, id] = q[i]; cin >> v; lv = rv = v; id = i; } for (int i = 0; i < m; ++i) { int x, y; cin >> x >> y; chkmin(q[x].lv, y); chkmax(q[x].rv, y); } for (int i = 1; i <= n; ++i) dp[i] = 1; cdq(1, n); int ans = 0; for (int i = 1; i <= n; ++i) { chkmax(ans, dp[i]); } cout << ans << "\n"; }
#include<bits/stdc++.h> #define FIO cin.tie(0); ios::sync_with_stdio(false) #define all(x) (x).begin(), (x).end() #define fi first #define se second #define TEST #define TESTS int t = 1; cin >> t; while (t--)
usingnamespace std; using i64 = longlong; using u32 = unsigned; using u64 = unsignedlonglong; using pii = std::pair<int, int>;
constexprint N = 5e4 + 10; constexprint MOD = 998244353;
struct { int h, v, i; } q[N], q2[N]; int t[N], a[N]; double sum[N]; int len1[N], len2[N]; double cnt1[N], cnt2[N]; int n, m;
voidmodify(int i, int v, double cnt){ while (i <= m) { if (v > t[i]) { t[i] = v; sum[i] = cnt; } elseif (v == t[i]) { sum[i] += cnt; } i += i & -i; } }
tuple<int, double> query(int i){ int mx = 0; double cnt = 0; while (i) { if (t[i] > mx) { mx = t[i]; cnt = sum[i]; } elseif (t[i] == mx) { cnt += sum[i]; } i -= i & -i; } return {mx, cnt}; }
voidclear(int i){ while (i <= m) { t[i] = 0; sum[i] = 0; i += i & -i; } }
voidcdq1(int l, int r){ if (l == r) return; int mid = l + r >> 1; cdq1(l, mid); for (int i = l; i <= r; ++i) q2[i] = q[i]; sort(q2 + l, q2 + mid + 1, [&](auto x, auto y) { return x.h > y.h; }); sort(q2 + mid + 1, q2 + r + 1, [&](auto x, auto y) { return x.h > y.h; }); int j = l - 1; for (int i = mid + 1; i <= r; ++i) { while (j + 1 <= mid && q2[j + 1].h >= q2[i].h) { j++; modify(m - q2[j].v, len1[q2[j].i], cnt1[q2[j].i]); } auto [mx, cnt] = query(m - q2[i].v); if (mx + 1 > len1[q2[i].i]) { len1[q2[i].i] = mx + 1; cnt1[q2[i].i] = cnt; } elseif (mx + 1 == len1[q2[i].i]) { cnt1[q2[i].i] += cnt; } } for (int i = l; i <= j; ++i) { clear(m - q2[i].v); } cdq1(mid + 1, r); }
voidcdq2(int l, int r){ if (l == r) return; int mid = l + r >> 1; cdq2(l, mid); for (int i = l; i <= r; ++i) q2[i] = q[i]; sort(q2 + l, q2 + mid + 1, [&](auto x, auto y) { return x.h < y.h; }); sort(q2 + mid + 1, q2 + r + 1, [&](auto x, auto y) { return x.h < y.h; }); int j = l - 1; for (int i = mid + 1; i <= r; ++i) { while (j + 1 <= mid && q2[j + 1].h <= q2[i].h) { j++; modify(q2[j].v, len2[q2[j].i], cnt2[q2[j].i]); } auto [mx, cnt] = query(q2[i].v); if (mx + 1 > len2[q2[i].i]) { len2[q2[i].i] = mx + 1; cnt2[q2[i].i] = cnt; } elseif (mx + 1 == len2[q2[i].i]) { cnt2[q2[i].i] += cnt; } } for (int i = l; i <= j; ++i) { clear(q2[i].v); } cdq2(mid + 1, r); }
voidcompute(){ for (int i = 1; i <= n; ++i) { len1[i] = cnt1[i] = len2[i] = cnt2[i] = 1; } cdq1(1, n); for (int i = 1; i < n - i + 1; ++i) { swap(q[i], q[n - i + 1]); } for (int i = 1; i <= n; ++i) { q[i].i = i; } cdq2(1, n); for (int i = 1; i < n - i + 1; ++i) { swap(len2[i], len2[n - i + 1]); swap(cnt2[i], cnt2[n - i + 1]); } }
voidsolve(){ cin >> n; for (int i = 1; i <= n; ++i) { auto& [h, v, id] = q[i]; cin >> h >> v; id = i; a[i] = v; } sort(a + 1, a + n + 1); m = unique(a + 1, a + n + 1) - a - 1; for (int i = 1; i <= n; ++i) { q[i].v = lower_bound(a + 1, a + m + 1, q[i].v) - a; } m++; compute(); int len = 0; double cnt = 0; for (int i = 1; i <= n; ++i) len = max(len, len1[i]); for (int i = 1; i <= n; ++i) { if (len1[i] == len) cnt += cnt1[i]; } cout << len << "\n"; for (int i = 1; i <= n; ++i) { if (len1[i] + len2[i] - 1 < len) cout << "0 "; else cout << fixed << setprecision(5) << (cnt1[i] * cnt2[i] / cnt) << " "; } cout << "\n"; }
#include<bits/stdc++.h> #define FIO cin.tie(0); ios::sync_with_stdio(false) #define all(x) (x).begin(), (x).end() #define fi first #define se second #define TEST #define TESTS int t = 1; cin >> t; while (t--)
#include<bits/stdc++.h> #define FIO cin.tie(0); ios::sync_with_stdio(false) #define all(x) (x).begin(), (x).end() #define fi first #define se second #define TEST #define TESTS int t = 1; cin >> t; while (t--)
#include<bits/stdc++.h> #define FIO cin.tie(0); ios::sync_with_stdio(false) #define all(x) (x).begin(), (x).end() #define fi first #define se second #define TEST #define TESTS int t = 1; cin >> t; while (t--)
#include<bits/stdc++.h> #define FIO cin.tie(0); ios::sync_with_stdio(false) #define all(x) (x).begin(), (x).end() #define fi first #define se second #define TEST #define TESTS int t = 1; cin >> t; while (t--)
usingnamespace std; using i64 = longlong; using u32 = unsigned; using u64 = unsignedlonglong; using pii = std::pair<int, int>;
constexprint N = 1e5 + 10; constexprint MOD = 998244353;
struct { int a, b, c, d, v, i, f; } q[N], q1[N], q2[N]; int tree[N], treeSum[N]; int h[N]; int n, m; int dp[N], cnt1[N];
voidmodify(int i, int v, int cnt){ while (i <= m) { if (v > tree[i]) { tree[i] = v; treeSum[i] = cnt; } elseif (v == tree[i]) { treeSum[i] = (treeSum[i] + cnt) % MOD; } i += i & -i; } }
tuple<int, int> query(int i){ int mx = 0, cnt = 0; while (i) { if (tree[i] > mx) { mx = tree[i]; cnt = treeSum[i]; } elseif (tree[i] == mx) { cnt = (cnt + treeSum[i]) % MOD; } i -= i & -i; } return {mx, cnt}; }
voidclear(int i){ while (i <= m) { tree[i] = 0; treeSum[i] = 0; i += i & -i; } }
voidcdq2(int l, int r){ if (l == r) return; int mid = l + r >> 1; cdq2(l, mid); for (int i = l; i <= r; ++i) q2[i] = q1[i]; stable_sort(q2 + l, q2 + mid + 1, [&](auto x, auto y) { return x.c < y.c; }); stable_sort(q2 + mid + 1, q2 + r + 1, [&](auto x, auto y) { return x.c < y.c; }); int j = l - 1; for (int i = mid + 1; i <= r; ++i) { while (j + 1 <= mid && q2[j + 1].c <= q2[i].c) { j++; if (q2[j].f) modify(q2[j].d, dp[q2[j].i], cnt1[q2[j].i]); } if (q2[i].f) continue; auto [mx, cnt] = query(q2[i].d); if (mx + q2[i].v > dp[q2[i].i]) { dp[q2[i].i] = mx + q2[i].v; cnt1[q2[i].i] = cnt; } elseif (mx + q2[i].v == dp[q2[i].i]) { cnt1[q2[i].i] = (cnt1[q2[i].i] + cnt) % MOD; } } for (int i = l; i <= j; ++i) { if (q2[i].f) clear(q2[i].d); } cdq2(mid + 1, r); }
voidcdq1(int l, int r){ if (l == r) return; int mid = l + r >> 1; cdq1(l, mid); for (int i = l; i <= r; ++i) { q1[i] = q[i]; q1[i].f = i <= mid; } stable_sort(q1 + l, q1 + r + 1, [&](auto x, auto y) { return x.b < y.b; }); cdq2(l, r); cdq1(mid + 1, r); }
voidsolve(){ cin >> n >> m; for (int i = 1; i <= n; ++i) { cin >> q[i].a >> q[i].b >> q[i].c >> q[i].d >> q[i].v; h[i] = q[i].d; } sort(h + 1, h + n + 1); m = unique(h + 1, h + n + 1) - h - 1; for (int i = 1; i <= n; ++i) q[i].d = lower_bound(h + 1, h + m + 1, q[i].d) - h; sort(q + 1, q + n + 1, [&](auto x, auto y) { if (x.a != y.a) return x.a < y.a; if (x.b != y.b) return x.b < y.b; if (x.c != y.c) return x.c < y.c; return x.d < y.d; }); // 去不去重均可 int t = 1; for (int i = 2; i <= n; ++i) { if (q[i].a == q[t].a && q[i].b == q[t].b && q[i].c == q[t].c && q[i].d == q[t].d) { q[t].v += q[i].v; } else { q[++t] = q[i]; } } n = t; // end for (int i = 1; i <= n; ++i) q[i].i = i, dp[i] = q[i].v, cnt1[i] = 1;
cdq1(1, n); int mx = 0, cnt = 0; for (int i = 1; i <= n; ++i) mx = max(mx, dp[i]); for (int i = 1; i <= n; ++i) if (dp[i] == mx) cnt = (cnt + cnt1[i]) % MOD; cout << mx << "\n" << cnt << "\n"; }