#include
#define int long long
#define pb push_back
using namespace std;
const int maxn = 1e6 + 100;
int a[maxn];
void solve() {
int n; string s; cin >> n >> s;
s = '.' + s;
int k, w, q;cin >> k >> w >> q;
int cnt = 0;
a[cnt] = n + 1;
for (int i = 1; i <= n; i++) if (s[i] == '0')a[++cnt] = i;
a[cnt + 1] = n + 1;
int maxx = 0;
for (int i = 1; i <= cnt; i++) {
int posb = a[i];
int posa1 = a[lower_bound(a + 1, a + 1 + cnt, posb - k) - a - 1];
int posa2 = a[lower_bound(a + 1, a + 1 + cnt, posb - k) - a];
int posc1 = a[lower_bound(a + 1, a + 1 + cnt, posb + k) - a - 1];
int posc2 = a[lower_bound(a + 1, a + 1 + cnt, posb + k) - a];
if (posa1 < posb && posb <= a[cnt]) maxx = max(maxx, w - abs(posb + k - posa1) * q);
if (posa2 < posb && posb <= a[cnt]) maxx = max(maxx, w - abs(posb + k - posa2) * q);
if (posa1 < posb && posb < posc1 && posc1 <= a[cnt]) maxx = max(maxx, 2 * w - abs(posa1 + k - posb) * q - abs(posb + k - posc1) * q);
if (posa1 < posb && posb < posc2 && posc2 <= a[cnt]) maxx = max(maxx, 2 * w - abs(posa1 + k - posb) * q - abs(posb + k - posc2) * q);
if (posa2 < posb && posb < posc1 && posc1 <= a[cnt]) maxx = max(maxx, 2 * w - abs(posa2 + k - posb) * q - abs(posb + k - posc1) * q);
if (posa2 < posb && posb < posc2 && posc2 <= a[cnt]) maxx = max(maxx, 2 * w - abs(posa2 + k - posb) * q - abs(posb + k - posc2) * q);
}
cout << maxx << endl;
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t; t = 1;
while (t--) {
solve();
}
return 0;
}
#include
#define int long long
#define pb push_back
using namespace std;
const int maxn = 1e6 + 100;
const int mod = 1e9 + 7;
struct node {
int val, maxval;
}a[maxn];
int p[maxn];
int b[maxn];
bool cmp(int a, int b) {
return a > b;
}
void solve() {
int n, k, s;
cin >> n >> k >> s;
int maxx = 0;
for (int i = 0; i < n; i++) cin >> p[i];
for (int i = 0; i < n; i++) {
int aa, bb, c, d;
cin >> aa >> bb >> c >> d;
a[i].val = max(aa, bb);
a[i].maxval = max(a[i].val, max(c, d));
}
for (int i = 0; i < (1 << n); i++) {
int cnt = 0;
for (int j = 0; j < n; j++) {
if (i & (1 << j)) b[j] = a[j].maxval, cnt++;
else b[j] = a[j].val;
}
if (cnt <= k) {
sort(b, b + n, cmp);
int sum = s;
int ans = 0;
for (int j = 0; j < n; j++) {
sum += b[j];
if (sum >= p[j]) ans++;
}
maxx = max(maxx, ans);
}
}
cout << maxx << endl;
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t; t = 1;
while (t--) {
solve();
}
return 0;
}
给定一个区间 [ l , r l,r l,r] ,求这个区间内有多少个数字满足以下条件:
0 ≤ \leq ≤ l , r l,r l,r ≤ \leq ≤ 1 0 10 10^{10} 1010
#include
#define int long long
#define pb push_back
using namespace std;
const int maxn = 1e6 + 100;
typedef long long ll;
ll prime[1006];
bool sf[2006];
void sushu() {
ll num = 0;
memset(sf, true, sizeof(sf));
sf[1] = false;
sf[0] = false;
for (int i = 2; i < 1000; i++) {
if (sf[i]) prime[++num] = i;
for (int j = 1; j <= num; j++) {
if (i * prime[j] > 1000) break;
sf[i * prime[j]] = false;
if (i % prime[j] == 0) break;
}
}
}
int l, r;
int ans1 = 0; int ans2 = 0;
vector<int>g[100];
void dfs(int x,int sum,int f) {
if (sum < l) {
if (f == 1) ans1++;
}
else return;
for (int i = 0; i < g[x].size(); i++) {
int to = g[x][i];
if (to == 1) dfs(to, sum * 10 + to, 1);
else dfs(to, sum * 10 + to, f);
}
}
void dfs2(int x, int sum,int f) {
if (sum <= r) {
if (f == 1) ans2++;
}
else return;
for (int i = 0; i < g[x].size(); i++) {
int to = g[x][i];
if (to == 1) dfs2(to, sum * 10 + to, 1);
else dfs2(to, sum * 10 + to, f);
}
}
void solve() {
for (int i = 0; i <= 9; i++) {
for (int j = 0; j <= 9; j++) {
if (sf[i + j])g[i].push_back(j);
}
}
cin >> l >> r;
for (int i = 1; i <= 9; i++) {
if (i == 1) {
dfs(i, i, 1);
dfs2(i, i, 1);
}
else {
dfs(i, i, 0);
dfs2(i, i, 0);
}
}
cout << ans2 - ans1 << endl;
}
signed main() {
int t; t = 1;
sushu();
while (t--) {
solve();
}
return 0;
}
给一串长度为 n n n的字符串,字符串里面的字符仅包含 ‘1’,‘2’,‘3’,分别表示使用鬼眼,鬼影,鬼手的能力。每使用其中一个鬼的能力,这个鬼就会吸收其他两个鬼各一半的能力,且假设这三种鬼的能力值为1,按照这个字符串顺序使用对应鬼的能力后,将三种鬼的力量值%998244353代入
有 m m m次操作,每行三个整数
1 x y : 表示修改字符串的第x位修改成数字y
2 x y : 表示查询 l,r 这段字符串
0 ≤ \leq ≤ n , m n,m n,m ≤ \leq ≤ 1 0 5 10^{5} 105