#include<bits/stdc++.h> usingnamespace std; #define ll long long constint INF = 0x3f3f3f3f; constint N = 1e6 + 10; int n, q, x, L, R; int sum[N]; intlowbit(int x){ return x & -x; } voidadd(int p, int x){ for (int i = p; i <= n; i += lowbit(i)) { sum[i] += x; } } intqry(int r){ int ans = 0; for (int i = r; i > 0; i -= lowbit(i)) { ans += sum[i]; } return ans; } intmain(){ scanf("%d%d", &n, &q); for (int i = 0; i < n; i++) { scanf("%d", &x); add(x, 1); } while (q--) { scanf("%d", &x); if (x >= 1 && x <= n)add(x, 1); elseif (x < 0) { x = -x; L = 1, R = n; while (L < R) { int mid = (L + R) / 2; int t = qry(mid); if (t >= x)R = mid; else L = mid + 1; } add(L, -1); } } if (qry(n) == 0)puts("0"); else { for (int i = 1; i <= n; i++)if (qry(i) > 0) { printf("%d\n", i); return0; } } return0; }
#include<bits/stdc++.h> usingnamespace std; #define ll long long constint INF = 0x3f3f3f3f; constint N = 5e3 + 10; int n, m; int n1, n2, n3; int tot, cnt[N][3], dp[N][N]; int col[N], ans[N]; vector<int>G[N]; vector<int>cc[N]; boolbipar(int u, int c){ //1,2 col[u] = c; cnt[tot][c]++; cc[tot].push_back(u); for (int v : G[u]) { if (col[v] == col[u])returnfalse; if (!col[v]) { if (!bipar(v, 3 - c))returnfalse; } } returntrue; } intmain(){ scanf("%d%d", &n, &m); scanf("%d%d%d", &n1, &n2, &n3); for (int i = 0; i < m; i++) { int u, v; scanf("%d%d", &u, &v); G[u].push_back(v); G[v].push_back(u); } for (int i = 1; i <= n; i++) { if (!col[i]) { tot++; if (!bipar(i, 1)) { puts("NO"); return0; } } } int N1 = n1 + n3; dp[0][0] = 1; for (int i = 1; i <= tot; i++) { for (int j = 0; j <= N1; j++) { if (dp[i - 1][j]) { dp[i][j + cnt[i][1]] = 1; dp[i][j + cnt[i][2]] = 2; } } } if (dp[tot][N1])puts("YES"); else { puts("NO"); return0; } for (int i = tot; i >= 1; i--) { if (dp[i][N1] == 1) { for (int u : cc[i]) { if (col[u] == 1)ans[u] = 1; else ans[u] = 2; } N1 -= cnt[i][1]; } else { for (int u : cc[i]) { if (col[u] == 2)ans[u] = 1; else ans[u] = 2; } N1 -= cnt[i][2]; }
} for (int i = 1; i <= n && n3; i++) { if (ans[i] == 1)ans[i] = 3, n3--; } for (int i = 1; i <= n; i++)printf("%d%s", ans[i], i == n ? "\n" : ""); return0; }