defck(u): a=[] while u: a.append(u%10) u//=10 a.reverse() n=len(a) cnt1,cnt2,cnt3=0,0,0 for i inrange(n): if a[i]==2: cnt1+=1 if a[i]==0and cnt1>0: cnt2+=1 if a[i]==2and cnt2>0: cnt3+=1 if a[i]==3and cnt3>0: returnTrue returnFalse ans=0 for i inrange(12345678,98765432+1): if ck(i): ans+=1 print((98765432-12345678+1)-ans)
a=[0]*100000 ans=0 for i inrange(1,2024): a[i]=i for i inrange(1,4501): res=0 for j inrange(1,i//2+1): k=i-j if j!=k: res+=min(a[j],a[k]) else: res+=a[j]//2 res+=a[i] ans=max(res,ans) print(ans)
int n, m; intmain() { ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; vector<int> a(n), s(n); for (int i = 0; i < n; ++i) { cin >> a[i] >> s[i]; } auto check = [&](LL t) { std::vector<pair<LL, LL>> v; for (int i = 0; i < n; ++i) { if (t >= s[i]) v.push_back({a[i] - (t - s[i]), a[i] + (t - s[i])}); } sort(v.begin(), v.end()); if (sz(v) == 0 || v[0].first > 1) returnfalse; LL r = v[0].second; for (int i = 1; i < sz(v); ++i) { if (v[i].first <= r + 1) r = max(r, v[i].second); elsebreak; } return r >= m; }; LL l = 1, r = 2e9; while (l < r) { LL mid = l + r >> 1; if (check(mid)) r = mid; else l = mid + 1; } cout << r << '\n'; return0; }
publicstaticvoidmain(String[] args) { Scannersc=newScanner(System.in); n = sc.nextInt(); m = sc.nextInt(); int[] a = newint[n]; int[] s = newint[n]; for (inti=0; i < n; ++i) { a[i] = sc.nextInt(); s[i] = sc.nextInt(); } longl=1, r = 2_000_000_000; while (l < r) { longmid= l + r >>> 1; if (check(mid, a, s)) r = mid; else l = mid + 1; } System.out.println(r); }
privatestaticbooleancheck(long t, int[] a, int[] s) { List<Pair<Long, Long>> v = newArrayList<>(); for (inti=0; i < n; ++i) { if (t >= s[i]) { v.add(newPair<>(a[i] - (t - s[i]), a[i] + (t - s[i]))); } } v.sort(Comparator.comparingLong(Pair::getKey)); if (v.size() == 0 || v.get(0).getKey() > 1) returnfalse; longr= v.get(0).getValue(); for (inti=1; i < v.size(); ++i) { if (v.get(i).getKey() <= r + 1) r = Math.max(r, v.get(i).getValue()); elsebreak; } return r >= m; }
staticclassPair<K, V> { privatefinal K key; privatefinal V value;
n, m = map(int, input().split()) a = [] s = [] for i inrange(n): a_i, s_i = map(int, input().split()) a.append(a_i) s.append(s_i)
defcheck(t): v = [] for i inrange(n): if t >= s[i]: v.append((a[i] - (t - s[i]), a[i] + (t - s[i]))) v.sort() iflen(v) == 0or v[0][0] > 1: returnFalse r = v[0][1] for i inrange(1, len(v)): if v[i][0] <= r + 1: r = max(r, v[i][1]) else: break return r >= m
l = 1 r = 2_000_000_000 while l < r: mid = (l + r) // 2 if check(mid): r = mid else: l = mid + 1
from collections import Counter from typing importList
N = 200010 g = [[] for _ inrange(N)] depth = [[] for _ inrange(N)] d = [0] * N a = [0] * N fa = [0] * N f = [[0] * 2for _ inrange(N)] s = [Counter() for _ inrange(N)]
n = int(input()) d[1] = 1 max_depth = 0 arrt = [int(n) for n ininput("").split()] for i inrange(2, n + 1): fa[i] = arrt[i - 2]#int(input()) g[fa[i]].append(i) d[i] = d[fa[i]] + 1 max_depth = max(max_depth, d[i])
arrt = [int(n) for n ininput("").split()]
for i inrange(1, n + 1): a[i] = arrt[i - 1] #int(input())
for i inrange(1, n + 1): depth[d[i]].append(i)
for j inrange(max_depth, 0, -1): for u in depth[j]: if s[j + 1]: f[u][0] = max(f[u][0], max(s[j + 1].keys()))
f[u][1] = a[u] for v in g[u]: s[j + 1][f[v][1]] -= 1 if s[j + 1][f[v][1]] == 0: del s[j + 1][f[v][1]]
from collections import Counter from typing importList
N = 200010 g = [[] for _ inrange(N)] depth = [[] for _ inrange(N)] d = [0] * N a = [0] * N fa = [0] * N f = [[0] * 2for _ inrange(N)] s = [Counter() for _ inrange(N)]
n = int(input()) d[1] = 1 max_depth = 0 arrt = [int(n) for n ininput("").split()] for i inrange(2, n + 1): fa[i] = arrt[i - 2]#int(input()) g[fa[i]].append(i) d[i] = d[fa[i]] + 1 max_depth = max(max_depth, d[i])
arrt = [int(n) for n ininput("").split()]
for i inrange(1, n + 1): a[i] = arrt[i - 1] #int(input())
for i inrange(1, n + 1): depth[d[i]].append(i)
for j inrange(max_depth, 0, -1): for u in depth[j]: if s[j + 1]: f[u][0] = max(f[u][0], max(s[j + 1].keys()))
f[u][1] = a[u] for v in g[u]: s[j + 1][f[v][1]] -= 1 if s[j + 1][f[v][1]] == 0: del s[j + 1][f[v][1]]
voidadd(int x, T v){ for (; x <= n; x += x & (-x)) { a[x] ^= v; } }
T sum(int x){ auto ans = T(); for (; x; x -= x & (-x)) { ans ^= a[x]; } return ans; }
T rangeSum(int l, int r){ returnsum(r) ^ sum(l); } }; int n, m, tot; int a[N], in[N], out[N]; std::vector<int> e[N]; voiddfs(int u, int fa){ in[u] = ++tot; for (auto v : e[u]) { if (v == fa) continue; dfs(v, u); } out[u] = tot; } intmain() { ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; Fenwick<int> tr(n); for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 0; i < n - 1; ++i) { int u, v; cin >> u >> v; e[u].push_back(v); e[v].push_back(u); } dfs(1, 0); for (int i = 1; i <= n; ++i) tr.add(in[i], a[i]); int op, x, y; for (int i = 0; i < m; ++i) { cin >> op >> x; if (op == 1) { cin >> y; int v = tr.rangeSum(in[x] - 1, in[x]); tr.add(in[x], y ^ v); } else { cout << tr.rangeSum(in[x] - 1, out[x]) << '\n'; } } return0; }
publicclassMain { staticintN=100010; staticint n, m, tot; staticint[] a = newint[N], in = newint[N], out = newint[N], b = newint[N]; static List<Integer>[] e = newList[N];
staticvoidadd(int x, int v) { for (; x <= n; x += x & (-x)) { b[x] ^= v; } }
staticintsum(int x) { intans=0; if (x == 0) return0; for (; x > 0; x -= x & (-x)) { ans ^= b[x]; } return ans; }
staticintrangeSum(int l, int r) { return sum(r) ^ sum(l); }
staticvoiddfs(int u, int fa) { in[u] = ++tot; for (int v : e[u]) { if (v == fa) continue; dfs(v, u); } out[u] = tot; }
publicstaticvoidmain(String[] args)throws IOException { BufferedReaderreader=newBufferedReader(newInputStreamReader(System.in)); BufferedWriterwriter=newBufferedWriter(newOutputStreamWriter(System.out)); String[] temp = reader.readLine().split(" "); n = Integer.parseInt(temp[0]); m = Integer.parseInt(temp[1]); temp = reader.readLine().split(" "); for (inti=1; i <= n; ++i) { a[i] = Integer.parseInt(temp[i - 1]); e[i]=newArrayList<>(); } for (inti=0; i < n - 1; ++i) { temp = reader.readLine().split(" "); intu= Integer.parseInt(temp[0]); intv= Integer.parseInt(temp[1]); e[u].add(v); e[v].add(u); } dfs(1, 0); for (inti=1; i <= n; ++i) { add(in[i], a[i]); } for (inti=0; i < m; ++i) { temp = reader.readLine().split(" "); intop= Integer.parseInt(temp[0]); intx= Integer.parseInt(temp[1]); if (op == 1) { inty= Integer.parseInt(temp[2]); intv= rangeSum(in[x] - 1, in[x]); add(in[x], y ^ v); } else { writer.write(rangeSum(in[x] - 1, out[x]) + "\n"); } } reader.close(); writer.flush(); writer.close(); } }
N = 100010 n, m, tot = 0, 0, 0 a = [0]*N in_ = [0]*N out = [0]*N b = [0]*N e = [[] for _ inrange(N)]
defadd(x, v): while x <= n: b[x] ^= v x += x & (-x)
defsum_(x): ans = 0 if x == 0: return ans while x > 0: ans ^= b[x] x -= x & (-x) return ans
defrangeSum(l, r): return sum_(r) ^ sum_(l)
defdfs(u, fa): global tot in_[u] = tot = tot + 1 for v in e[u]: if v == fa: continue dfs(v, u) out[u] = tot
defmain(): global n, m, tot n, m = map(int, sys.stdin.readline().split()) a[1:n+1] = map(int, sys.stdin.readline().split()) for _ inrange(n - 1): u, v = map(int, sys.stdin.readline().split()) e[u].append(v) e[v].append(u) dfs(1, 0) for i inrange(1, n+1): add(in_[i], a[i]) for _ inrange(m): op, x, *extra = map(int, sys.stdin.readline().split()) if op == 1: y = extra[0] v = rangeSum(in_[x] - 1, in_[x]) add(in_[x], y ^ v) else: print(rangeSum(in_[x] - 1, out[x]))
#include<bits/stdc++.h> usingnamespace std; int x, n, a[100005], res, k, r; intmain(){ scanf("%d", &x); n = 1; while (n * (n - 1) / 2 < x) n++; printf("%d\n", n); if (n * (n - 1) / 2 == x) { for (int i = 1; i <= n; i++) a[i] = n - i + 1; } else { res = n * (n - 1) / 2 - x; if (res <= n / 2) { r = n; for (int i = 1; i <= res; i++) { a[r--] = i; a[r--] = i; } for (int i = r; i >= 1; i--) a[i] = res + (r - i + 1); } else { res = n - res - 1; r = n; for (int i = 1; i <= res; i++) { a[r--] = i; a[r--] = i; } for (int i = r; i >= 2; i--) a[i] = res + (r - i + 1); a[1] = res + 1; } } for (int i = 1; i <= n; i++) printf("%d%c", a[i], i == n? '\n' : ' '); return0; }
if (n * (n - 1) / 2 == x) { int[] a = newint[n + 1]; for (inti=1; i <= n; i++) { a[i] = n - i + 1; } for (inti=1; i <= n; i++) { System.out.print(a[i]); if (i == n) { System.out.println(); } else { System.out.print(" "); } } } else { int[] a = newint[n + 1]; intres= n * (n - 1) / 2 - x; int r;
if (res <= n / 2) { r = n; for (inti=1; i <= res; i++) { a[r--] = i; a[r--] = i; } for (inti= r; i >= 1; i--) { a[i] = res + (r - i + 1); } } else { res = n - res - 1; r = n; for (inti=1; i <= res; i++) { a[r--] = i; a[r--] = i; } for (inti= r; i >= 2; i--) { a[i] = res + (r - i + 1); } a[1] = res + 1; }
for (inti=1; i <= n; i++) { System.out.print(a[i]); if (i == n) { System.out.println(); } else { System.out.print(" "); } } } } }