Given are integer sequences $A=(a_1,a_2,…,a_N)$, $T=(t_1,t_2,…,t_N)$, and $X=(x_1,x_2,…,x_Q)$. Let us define $N$ functions $f_1(x),f_2(x),…,f_N(x)$ as follows:
n = int(input()) low, high, add = -10 ** 18, 10 ** 18, 0 for _ inrange(n): a, t = map(int, input().split()) if t == 1: low += a high += a add += a elif t == 2: low = max(low, a) high = max(high, a) elif t == 3: low = min(low, a) high = min(high, a) q = int(input()) s = input() list = [int(_) for _ in s.split()] for x inlist: print(min(high, max(low, x + add)))
classSolution: defdeleteDuplicates(self, head: ListNode) -> ListNode: q = ListNode() q.next = head ans = q while q and q.nextand q.next.next: while q.nextand q.next.nextand q.next.val == q.next.next.val: val = q.next.val p = q.next while p and p.val == val: p = p.next q.next = p q = q.next return ans.next
typedeflonglong ll; usingnamespace std; constint N = 1e5 + 5; vector<int> G[N]; int n, x, y, cnt, id[N] = {1}, ans[N];
voiddfs1(int son, int father){//编号 for (auto kid:G[son]) { if (kid != father) dfs1(kid, son); } if (!id[son]) { if (id[father]) {//若父亲结点已被编号直接输出-1 printf("-1\n"); exit(0); } id[father] = id[son] = ++cnt; } }
voiddfs2(int son, int father, int color){//染色 ans[son] = color; for (auto kid:G[son]) { if (kid != father) dfs2(kid, son, (id[kid] == id[son] ? color : color ^ 1)); } }
intmain(){ cin >> n; for (int i = 0; i < n - 1; i++) { cin >> x >> y; G[x].push_back(y); G[y].push_back(x); } dfs1(1, 0); dfs2(1, 0, 0); for (int i = 1; i <= n; i++) putchar(ans[i] ? 'R' : 'B'); return0; }
classUnionset { public: vector<int> father; vector<int> sum; int cnt = 0; public: voidinit(int n){ father.resize(n); for (int i = 0; i < n; i++) father[i] = i; sum.resize(n); cnt = n; }
intfindFather(int x){ return x == father[x] ? x : father[x] = findFather(father[x]); }
boolUnion(int x, int y){ x = findFather(x), y = findFather(y); if (x == y) return0; if (sum[x] < sum[y]) swap(x, y); father[y] = x; sum[x] += sum[y]; --cnt; return1; } };
classSolution { public: vector<vector<int>> findCriticalAndPseudoCriticalEdges(int n, vector<vector<int>> &edges) { int m = edges.size(); for (int i = 0; i < m; i++) edges[i].push_back(i); sort(edges.begin(), edges.end(), [](constauto &u, constauto &v) { return u[2] < v[2]; }); int value = 0; Unionset a = Unionset(); a.init(n); for (auto i:edges) if (a.Union(i[0], i[1])) value += i[2]; vector<vector<int>> ans(2); for (int i = 0; i < m; i++) { Unionset b = Unionset(); b.init(n); int v = 0; for (int j = 0; j < m; j++) { if (i != j && b.Union(edges[j][0], edges[j][1])) v += edges[j][2]; } if (b.cnt != 1 || (b.cnt == 1 && v > value)) { ans[0].emplace_back(edges[i][3]); continue; } Unionset c = Unionset(); c.init(n); c.Union(edges[i][0], edges[i][1]); v = edges[i][2]; for (int j = 0; j < m; j++) { if (i != j && c.Union(edges[j][0], edges[j][1])) v += edges[j][2]; } if (v == value) ans[1].push_back(edges[i][3]); } return ans; } };
typedeflonglong ll; usingnamespace std; constint N = 1e5 + 5; int n, k, flag = 0, a[N], pos[N]; deque<int> q;
intmain(){ cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; pos[a[i]] = i; } for (int i = 1; i <= n; i++) { if (pos[i] != i) { k = pos[i] - i + 1; break; } } if (!k) { cout << "yes\n" << "1"; return0; } for (int i = 1; i <= k; i++) q.push_back(a[i]); for (int i = k + 1; i <= n + k; i++) { if (!(flag % 2)) { if (i - k == q.front()) q.pop_front(); elseif (i - k == q.back()) flag ^= 1, q.pop_back(); else { cout << "no"; return0; } } elseif (flag % 2) { if (i - k == q.back()) q.pop_back(); elseif (i - k == q.front()) flag ^= 1, q.pop_front(); else { cout << "no"; return0; } } if (i <= n) { if (flag % 2) q.push_front(a[i]); else q.push_back(a[i]); } } cout << "yes\n" << k; return0; }