#include<bits/stdc++.h> typedeflonglong LL; constint N = 2e5 + 10; int n, q; int a[N], c[N]; intdigit_sum(int x) { int res = 0; while (x) { res += x % 10; x /= 10; } return res; } voidadd(int x, int k) { for (; x <= n; x += x & -x) c[x] += k; } intquery(int x) { int res = 0; for (; x; x -= x & -x) res += c[x]; return res; } voidF() { std::cin >> n >> q; for (int i = 1; i <= n; ++i) c[i] = 0; for (int i = 1; i <= n; ++i) std::cin >> a[i]; while (q--) { int op; std::cin >> op; if (op == 1) { int l, r; std::cin >> l >> r; add(l, 1); if (r + 1 <= n) add(r + 1, -1); } else { int x; std::cin >> x; int times = query(x); int val = a[x]; while (times) { val = digit_sum(val); --times; if (val < 10) break; } std::cout << val << '\n'; } } } signedmain() { std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); int T = 1; std::cin >> T; while (T--) F(); return0; }
#include<bits/stdc++.h> typedeflonglong LL; voidG1() { int n, c; std::cin >> n >> c; std::vector<int> a(n + 10); for (int i = 1; i <= n; ++i) std::cin >> a[i], a[i] = a[i] + i; std::sort(a.begin() + 1, a.begin() + n + 1); std::vector<LL> s(n + 10, 0); for (int i = 1; i <= n; ++i) s[i] = s[i - 1] + (LL)a[i]; int l = 0, r = n; while (l < r) { int mid = l + r + 1 >> 1; if (s[mid] <= c) l = mid; else r = mid - 1; } std::cout << l << '\n'; } signedmain() { std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); int T = 1; std::cin >> T; while (T--) G1(); return0; }
#include<bits/stdc++.h> typedeflonglong LL; voidG2() { int n, c; std::cin >> n >> c; std::vector<int> a(n + 10); std::vector<int> b(n + 10); for (int i = 1; i <= n; ++i) std::cin >> a[i], b[i] = std::min(a[i] + i, a[i] + n + 1 - i); std::sort(b.begin() + 1, b.begin() + n + 1); std::vector<LL> s(n + 10, 0); for (int i = 1; i <= n; ++i) s[i] = s[i - 1] + (LL)b[i]; int ans = 0; for (int i = 1; i <= n; ++i) // 这层循环枚举哪一个点作为第一次从左边出发用传送门的点 { if (a[i] + i > c) continue; int t = std::min(a[i] + i, a[i] + n + 1 - i); // t是枚举的这个点在前缀和中的贡献 int l = 0, r = n; while (l < r) { int mid = l + r + 1 >> 1; if (s[mid] <= c - (a[i] + i)) l = mid; else r = mid - 1; } if (b[l] < t) // 说明枚举的这个点没有影响到二分分界 ans = std::max(ans, l + 1); else// 否则补上这个点的贡献再二分一次 { l = 0, r = n; while (l < r) { int mid = l + r + 1 >> 1; if (s[mid] <= c - (a[i] + i) + t) l = mid; else r = mid - 1; } ans = std::max(ans, l); //注意此时不用加一,因为枚举的这个点已经在二分的左半边 } } std::cout << ans << '\n'; } signedmain() { std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); int T = 1; std::cin >> T; while (T--) G2(); return0; }