acwing_xyy

$$\href{https://www.acwing.com/blog/content/26205/}{\Huge\color{blue}{个人主页}}$$$RenDe Primary school$

2613

Whalefall.

lpq1234
yxc的小迷妹

xyh不是xyy

R虎虎生威R
charming.
yxᴄ
shijiahao123_fdfsbv_da_sb

NUC-CYJ

Samuely

acwing_xyy
5小时前
hh刷刷存在感

acwing_xyy
21小时前
#include <cstdio>
#include <cstring>
#include <algorithm>

const int N = 1e5 + 5;

int n, w[N], stk[N], top, h[N];
long long res;

int main() {
while (scanf("%d", &n), n) {
res = top = h[n + 1] = 0;

for (int i = 1; i <= n; i ++ ) scanf("%d", h + i);
for (int i = 1; i <= n + 1; i ++ ) {
if (stk[top] < h[i]) {
stk[ ++ top] = h[i];
w[top] = 1;
} else {
int width = 0;
while (stk[top] > h[i]) {
width += w[top];
res = std::max(res, (long long)width * stk[top]);
top -- ;
}
stk[ ++ top] = h[i];
w[top] = width + 1;
}
}

printf("%lld\n", res);
}
}


acwing_xyy
21小时前
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;

typedef long long ll;

const int N = 120005, base = 1e9;

int n, primes[N], cnt, sum[N], a, b;
bool st[N];

vector<ll> res;

void get_primes(int n) {
for (int i = 2; i <= n; i ++ ) {
if (!st[i]) primes[cnt ++ ] = i;

for (int j = 0; primes[j] <= n / i; j ++ ) {
st[i * primes[j]] = true;

if (i % primes[j] == 0) break;
}
}
}

int get(int n, int p) {
int res = 0;
while (n) {
res += n / p;
n /= p;
}

return res;
}

vector<ll> mul(vector<ll> a, int b) {
ll t = 0;
vector<ll> c;

for (int i = 0; i < a.size() || t; i ++ ) {
if (i < a.size()) t += a[i] * b;

c.push_back(t % base);
t /= base;
}

while (c.size() > 1 && c.back() == 0) c.pop_back();

return c;
}

int main() {
scanf("%d", &n);
a = n * 2, b = n;

get_primes(a);

for (int i = 0; i < cnt; i ++ )
sum[i] = get(a, primes[i]) - get(b, primes[i]) - get(a - b, primes[i]);

int k = n + 1;
for (int i = 0; i < cnt; i ++ )
if (primes[i] <= k) {
while (k % primes[i] == 0) {
k /= primes[i];
sum[i] -- ;
}
}
res.push_back(1);
for (int i = 0; i < cnt; i ++ )
for (int j = 0; j < sum[i]; j ++ )
res = mul(res, primes[i]);

printf("%lld", res.back());
for (int i = res.size() - 2; i >= 0; i -- ) printf("%09lld", res[i]);

return 0;
}


acwing_xyy
21小时前
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;

const int N = 25;

int n, cnt, stk[N];
vector<int> tmp;

void dfs(int top, int x) {
if (cnt >= 20) return ;
if (x > n && top == 0) {
for (int i = 0; i < tmp.size(); i ++ ) printf("%d", tmp[i]);
puts("");
cnt ++ ;

return ;
}
if (top) {
int t = stk[top];
tmp.push_back(stk[top]);

dfs(top - 1, x);

stk[top] = t;
tmp.pop_back();
}
if (x <= n) {
stk[top + 1] = x;
dfs(top + 1, x + 1);
}
}

int main() {
scanf("%d", &n);

dfs(0, 1);

return 0;
}


acwing_xyy
21小时前
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <stack>

using namespace std;

const int N = 1e6 + 5;

stack<int> stk1, stk2;
int q, sum[N], f[N];
char op;

int main() {
memset(f, -0x3f, sizeof f);

scanf("%d", &q);
while (q -- ) {
scanf(" %c", &op);

if (op == 'D') {
if (stk1.empty()) continue;

stk1.pop();
}
if (op == 'L') {
if (stk1.empty()) continue;

stk2.push(stk1.top());
stk1.pop();
}
if (op == 'R') {
if (stk2.empty()) continue;

stk1.push(stk2.top());
stk2.pop();

int len = stk1.size();
sum[len] = sum[len - 1] + stk1.top();
f[len] = std::max(f[len - 1], sum[len]);
}
if (op == 'Q') {
int k;
scanf("%d", &k);

printf("%d\n", f[k]);
}

if (op == 'I') {
int k;
scanf("%d", &k);

stk1.push(k);

int len = stk1.size();

sum[len] = sum[len - 1] + stk1.top();
f[len] = std::max(f[len - 1], sum[len]);
}
}

return 0;
}


acwing_xyy
21小时前
class MinStack {
public:
/** initialize your data structure here. */
stack<int> stk_1, stk_2;

MinStack() {

}

void push(int x) {
stk_1.push(x);
if (stk_2.empty() || stk_2.top() >= x)
stk_2.push(x);
}

void pop() {
if (stk_2.top() == stk_1.top()) stk_2.pop();
stk_1.pop();
}

int top() {
return stk_1.top();
}

int getMin() {
return stk_2.top();
}
};

/**
* Your MinStack object will be instantiated and called as such:
* MinStack obj = new MinStack();
* obj.push(x);
* obj.pop();
* int param_3 = obj.top();
* int param_4 = obj.getMin();
*/


lpq1234发起攻击, fireflylightの小号受到97点伤害 acwing_xyy使用分身, 出现一个新的acwing_xyy fireflylight发起攻击, lpq1234受到70点伤害 fireflylightの小号发起攻击, acwing_xyy受到84点伤害, acwing_xyy发动隐匿 The_Golden_Dragon_Month使用地裂术  fireflylight回避了攻击  fireflylightの小号受到31点伤害  肝帝666受到28点伤害  lpq1234受到20点伤害 肝帝666发起攻击, The_Golden_Dragon_Month受到32点伤害 acwing_xyy发起攻击, lpq1234受到61点伤害 fireflylightの小号发起攻击, The_Golden_Dragon_Month回避了攻击 fireflylight发起攻击, 唐の月回避了攻击 lpq1234使用瘟疫, fireflylight体力减少70% acwing_xyy发起攻击, fireflylightの小号受到35点伤害 The_Golden_Dragon_Month发起攻击, fireflylight受到132点伤害  fireflylight被击倒了 唐の月发起攻击, fireflylightの小号回避了攻击 肝帝666使用诅咒, fireflylightの小号受到78点伤害, fireflylightの小号被诅咒了 fireflylightの小号发起攻击, 唐の月受到55点伤害 lpq1234发起攻击, 诅咒使伤害加倍, fireflylightの小号受到168点伤害  fireflylightの小号被击倒了  lpq1234召唤亡灵, fireflylightの小号变成了丧尸 acwing_xyy发起攻击, lpq1234受到59点伤害 The_Golden_Dragon_Month发起攻击, 肝帝666受到60点伤害 acwing_xyy发起攻击, lpq1234受到45点伤害  lpq1234被击倒了  丧尸消失了 唐の月发起攻击, 肝帝666受到64点伤害 肝帝666发起攻击, acwing_xyy受到32点伤害 The_Golden_Dragon_Month使用地裂术  肝帝666受到25点伤害 acwing_xyy发起攻击, 肝帝666受到76点伤害 唐の月发起攻击, 肝帝666受到35点伤害  肝帝666被击倒了 胜者 得分 击杀 致命一击 acwing_xyy 396 1 The_Golden_Dragon_Month 368 1 唐の月 169 1 败者 得分 击杀 致命一击 lpq1234 582 1 acwing_xyy 肝帝666 203 0 唐の月 fireflylightの小号 159 0 lpq1234 fireflylight 90 0 The_Golden_Dragon_Month

lpq1234发起攻击, fireflylightの小号受到97点伤害 acwing_xyy使用分身, 出现一个新的acwing_xyy fireflylight发起攻击, lpq1234受到70点伤害 fireflylightの小号发起攻击, acwing_xyy受到84点伤害, acwing_xyy发动隐匿 The_Golden_Dragon_Month使用地裂术  fireflylight回避了攻击  fireflylightの小号受到31点伤害  肝帝666受到28点伤害  lpq1234受到20点伤害 肝帝666发起攻击, The_Golden_Dragon_Month受到32点伤害 acwing_xyy发起攻击, lpq1234受到61点伤害 fireflylightの小号发起攻击, The_Golden_Dragon_Month回避了攻击 fireflylight发起攻击, 唐の月回避了攻击 lpq1234使用瘟疫, fireflylight体力减少70% acwing_xyy发起攻击, fireflylightの小号受到35点伤害 The_Golden_Dragon_Month发起攻击, fireflylight受到132点伤害  fireflylight被击倒了 唐の月发起攻击, fireflylightの小号回避了攻击 肝帝666使用诅咒, fireflylightの小号受到78点伤害, fireflylightの小号被诅咒了 fireflylightの小号发起攻击, 唐の月受到55点伤害 lpq1234发起攻击, 诅咒使伤害加倍, fireflylightの小号受到168点伤害  fireflylightの小号被击倒了  lpq1234召唤亡灵, fireflylightの小号变成了丧尸 acwing_xyy发起攻击, lpq1234受到59点伤害 The_Golden_Dragon_Month发起攻击, 肝帝666受到60点伤害 acwing_xyy发起攻击, lpq1234受到45点伤害  lpq1234被击倒了  丧尸消失了 唐の月发起攻击, 肝帝666受到64点伤害 肝帝666发起攻击, acwing_xyy受到32点伤害 The_Golden_Dragon_Month使用地裂术  肝帝666受到25点伤害 acwing_xyy发起攻击, 肝帝666受到76点伤害 唐の月发起攻击, 肝帝666受到35点伤害  肝帝666被击倒了 胜者 得分 击杀 致命一击 acwing_xyy 396 1 The_Golden_Dragon_Month 368 1 唐の月 169 1 败者 得分 击杀 致命一击 lpq1234 582 1 acwing_xyy 肝帝666 203 0 唐の月 fireflylightの小号 159 0 lpq1234 fireflylight 90 0 The_Golden_Dragon_Month

#include <cstdio>
#include <algorithm>
#include <cstring>

typedef long long ll;

const int N = 1e5 + 5;

struct Node {
int l, r;
ll sum, add, mul;
};

Node tr[N * 4];
int n, m, p, w[N];

void pushup(int u) {
tr[u].sum = (tr[u << 1].sum + tr[u << 1 | 1].sum) % p;
}

void eval(Node &t, int add, int mul) {
t.sum = ((ll)t.sum * mul + (ll)(t.r - t.l + 1) * add) % p;
t.mul = (ll)t.mul * mul % p;
}

void pushdown(int u) {
eval(tr[u << 1], tr[u].add, tr[u].mul);
eval(tr[u << 1 | 1], tr[u].add, tr[u].mul);

tr[u].add = 0, tr[u].mul = 1;
}

void build(int u, int l, int r) {
if (l == r) tr[u] = {l, r, w[l], 0, 1};
else {
tr[u] = {l, r, 0, 0, 1};

int mid = l + r >> 1;
build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);

pushup(u);
}
}

void modify(int u, int l, int r, int add, int mul) {
if (tr[u].l >= l && tr[u].r <= r) eval(tr[u], add, mul);
else {
int mid = tr[u].l + tr[u].r >> 1;

pushdown(u);
if (l <= mid) modify(u << 1, l, r, add, mul);
if (r > mid) modify(u << 1 | 1, l, r, add, mul);

pushup(u);
}
}

int query(int u, int l, int r) {
if (tr[u].l >= l && tr[u].r <= r) return tr[u].sum;

pushdown(u);
int mid = tr[u].l + tr[u].r >> 1;

int sum = 0;
if (l <= mid) sum = (sum + query(u << 1, l, r)) % p;
if (r > mid) sum = (sum + query(u << 1 | 1, l, r)) % p;

return sum;
}

int main() {
scanf("%d %d", &n, &p);
for (int i = 1; i <= n; i ++ )
scanf("%d", w + i);
build(1, 1, n);

scanf("%d", &m);
while (m -- ) {
int op;
scanf("%d", &op);

int t, g, c;
if (op == 1) {
scanf("%d %d %d", &t, &g, &c);
modify(1, t, g, 0, c);
}
if (op == 2) {
scanf("%d %d %d", &t, &g, &c);
modify(1, t, g, c, 1);
}
if (op == 3) {
scanf("%d %d", &t, &g);
printf("%d\n", query(1, t, g));
}
}

return 0;
}