• 欢迎光临~

# CF1455G

## Solution

``````// 德丽莎你好可爱德丽莎你好可爱德丽莎你好可爱德丽莎你好可爱德丽莎你好可爱
// 德丽莎的可爱在于德丽莎很可爱，德丽莎为什么很可爱呢，这是因为德丽莎很可爱！
// 没有力量的理想是戏言，没有理想的力量是空虚
#include <bits/stdc++.h>
#define LL long long
#define int long long
using namespace std;
char ibuf[1 << 15], *p1, *p2;
#define getchar() (p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 1 << 15, stdin), p1==p2) ? EOF : *p1++)
char ch = getchar();  int x = 0, f = 1;
while (ch < '0' || ch > '9')  {  if (ch == '-')  f = -1;  ch = getchar();  }
while (ch >= '0' && ch <= '9')  x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
return x * f;
}
void print(LL x) {
if (x > 9)  print(x / 10);
putchar(x % 10 + '0');
}
template<class T> bool chkmin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool chkmax(T &a, T b) { return a < b ? (a = b, true) : false; }
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define repd(i, l, r) for (int i = (l); i >= (r); i--)
#define REP(i, l, r)  for (int i = (l); i < (r); i++)
bool o1;
const int N = 2e5 + 5, lim = 2e5, inf = 2e17;
int n, S, num, nex[N], first[N], v[N];
int st[N], tp;
struct node {  int id, x, y;  } a[N];
vector <int> ver[N];
int rt[N * 19], lc[N * 19], rc[N * 19], s[N * 19], tot, tag[N * 19];
void pushup(int p) {
s[p] = min(s[lc[p]], s[rc[p]]);
}
void gettag(int p,int val) {
s[p] += val;
tag[p] += val;
}
void pushdown(int p) {
if (!tag[p])  return;
if (lc[p])  s[lc[p]] += tag[p], tag[lc[p]] += tag[p];
if (rc[p])  s[rc[p]] += tag[p], tag[rc[p]] += tag[p];
tag[p] = 0;
}
void change(int &p,int l,int r,int pos,int val) {
if (!p)  p = ++tot;
if (l == r) { s[p] = val;  return;   }
pushdown(p);
int mid = (l + r) >> 1;
if (pos <= mid)  change(lc[p], l, mid, pos, val);
else  change(rc[p], mid + 1, r, pos, val);
pushup(p);
}
int ask(int p,int l,int r,int pos) {
if (!p)  return inf;
if (l == r)  return s[p];
pushdown(p);
int mid = (l + r) >> 1;
if (pos <= mid)  return ask(lc[p], l, mid, pos);
else  return ask(rc[p], mid + 1, r, pos);
}
int merge(int x,int y,int a,int b) {
if (!x || !y)  return x + y;
int nowrt = ++tot;
if (a == b) {
s[nowrt] = min(s[x], s[y]);
return nowrt;
}
pushdown(x);
pushdown(y);
int mid = (a + b) >> 1;
lc[nowrt] = merge(lc[x], lc[y], a, mid);
rc[nowrt] = merge(rc[x], rc[y], mid + 1, b);
pushup(nowrt);
return nowrt;
}
int cnt = 0;
void dfs(int x) {
change(rt[x], 0, lim, a[x].x, 0);
for (auto to : ver[x]) {
if (a[to].id == 1) {
int now = s[rt[x]];
gettag(rt[x], a[to].y);
if (a[to].x != S)  change(rt[x], 0, lim, a[to].x, now);
else  change(rt[x], 0, lim, a[to].x, inf);
} else if (a[to].id == 2) {
int val = ask(rt[x], 0, lim, a[to].x);
if (val != inf) {
dfs(to);
gettag(rt[to], val);
change(rt[x], 0, lim, a[to].x, inf);
rt[x] = merge(rt[x], rt[to], 0, lim);
}
}
}
}
bool o2;
void solve() {
// cout << (&o2 - &o1) * 1.0 / 1024 / 1024 << "n";
cin >> n >> S;
st[0] = n + 1;
rep (i, 1, n) {
string it ;
cin >> it;
if (it == "set") {
a[i].id = 1;
cin >> a[i].x >> a[i].y;
ver[st[tp]].push_back(i);
} else if (it == "if") {
a[i].id = 2;
cin >> a[i].x;
ver[st[tp]].push_back(i);
st[++tp] = i;
} else if (it == "end") {
tp--;
}
}
s[0] = inf;
dfs(n + 1);
cout << s[rt[n + 1]] << "n";
}
signed main () {
#ifdef LOCAL_DEFINE
freopen("1.in", "r", stdin);
freopen("1.ans", "w", stdout);
#endif
ios :: sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T = 1;  while (T--)  solve();
#ifdef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.n";
#endif
return 0;
}
``````