solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
#include <bits/stdc++.h> using namespace std; int n, x, y, mx, idx; int deg[100010]; vector<int> edge[100010]; bool vis[100010]; bool can = true; void dfs(int u) { vis[u] = true; int sz_u = (int)edge[u].size(); if (u != idx && sz_u == 2) { can = false; return; } for (int i = 0; i < sz_u && can; ++i) {...
10
CPP
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse4") const long double EPS = 1e-9; const long long INF = 1e9; const long long mod = 1e9 + 7; using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); long long n, m, k; long long q; vector<vector<long ...
10
CPP
from collections import defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue,copy,time sys.setrecursionlimit(10**8) INF = float('inf') mod = 10**9+7 eps = 10**-7 def inp(): return int(input()) def inpl(): return list(map(int, input().split())) def inpl_str(): return list(input().split()) N = inp() cnt...
10
PYTHON3
# https://codeforces.com/contest/1189/problem/D1 n = int(input()) g = {} p = {} path = {} flg = True for _ in range(n-1): u,v = map(int, input().split()) if u not in g: g[u] = [] g[u].append(v) if v not in g: g[v] = [] g[v].append(u) flg = 'YES' for x in g: if le...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; int32_t main() { cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long n; cin >> n; vector<vector<long long>> graph(n + 1); if (n == 2) { cout << "YES" << "\n"; return 0; } for (long long i = 0; i < n - 1; i++) { long long...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 1; vector<long long> v[N]; int main() { long long n; cin >> n; for (int i = 0; i < n - 1; i++) { long long x, y; cin >> x >> y; v[x].push_back(y); v[y].push_back(x); } for (int i = 1; i <= n; i++) { if (v[i].size() == ...
10
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; long mmid(long a, long b, long c) { return a < b ? (b < c ? b : max(a, c)) : (b > c ? b : min(a, c)); } ll modinv(ll a) { ll b = 1000000007, u = 1, v = 0, t; while (b) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v...
10
CPP
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int main() { ios::sync_with_stdio(0), cin.tie(0); long long int n; cin >> n; vector<long long int> v[n + 1]; for (long long int i = 0; i < n - 1; i++) { long long int x, y; cin >> x >> y; v[x].push_back(y); v[y].push_bac...
10
CPP
#include <bits/stdc++.h> long long mod = 998244353; using namespace std; const long long N = 1e5 + 5; vector<long long> g[N]; long long n; void fail() { cout << "NO\n"; exit(0); } long long cnt = 1; void dfs(long long node, long long p = 0) { if (g[node].size() == 2) cnt = 0; for (long long nx : g[node]) { ...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long inf = 998244353; bool cmp(pair<int, pair<int, int>> a, pair<int, pair<int, int>> b) { if (a.first >= b.first) return false; return true; } int main() { long long n, i = 0, j, k, m, q, l, r = 0, w, x, y, z = 0; string t, s; cin >> n; vector<vector...
10
CPP
import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writab...
10
PYTHON3
n = int(input()) deg = [0]*n for i in range(n-1): u, v = map(int, input().split()) deg[u-1] += 1 deg[v-1] += 1 if all(i != 2 for i in deg): print("YES") else: print("NO") # cnt = sum(1 for i in deg if i == 1) # if cnt*(cnt-1)//2 >= n - 1: # print("YES") # else: # print("NO")
10
PYTHON3
from math import log2 from collections import defaultdict import sys input = sys.stdin.readline ''' for CASES in range(int(input())): n, m = map(int, input().split()) n = int(input()) A = list(map(int, input().split())) S = input().strip() sys.stdout.write(" ".join(map(str,ans))+"\n") ''' inf = 100000000000000000 # 1e...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector<int> d(n + 1); for (int i = 1; i <= n - 1; ++i) { int u, v; cin >> u >> v; d[u]++, d[v]++; } bool ok = 1; for (int i = 1; i <= n; ++i) { ...
10
CPP
n = int(input()) g = [[] for i in range(n)] for i in range(n - 1): u, v = map(int, input().split()) u -= 1 v -= 1 g[u].append(v) g[v].append(u) for v in range(n): if len(g[v]) == 2: print('NO') exit(0) print('YES')
10
PYTHON3
a = int(input()) A = [0]*a k=0 for i in range(a-1): q,w = map(int,input().split()) A[q-1]+=1 if A[q-1]==2: k+=1 elif A[q-1]==3: k-=1 A[w-1]+=1 if A[w-1]==2: k+=1 elif A[w-1]==3: k-=1 if k == 0: print('YES') else: print('NO')
10
PYTHON3
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } int main() { long long n; cin >> n; vector<long long> a[100001]; for (long long i = 0; i < n - 1; i++) { long long x, y; cin >> x >> y; a[x].push_back(y); a[y...
10
CPP
#include <bits/stdc++.h> using namespace std; void fast(string name = "") { ios_base::sync_with_stdio(0); cin.tie(0); if ((int)name.size() > 0) { freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } } const int N = 1e5; int deg[N]; int n; void solve() { cin >> ...
10
CPP
n = int(input()) dep = [] for i in range(n) : dep.append(0) for i in range(n-1) : a, b = input().split(' ') a = int(a) b = int(b) dep[a-1] = dep[a-1]+1 dep[b-1] = dep[b-1]+1 good = 1 for i in range(n) : if dep[i] == 2 : good = 0 if good == 1 : print('YES') else : print('NO')...
10
PYTHON3
#!/usr/bin/env python import os import sys from io import BytesIO, IOBase def main(): n = int(input()) d = [[] for _ in range(n)] for i in range(n-1): u, v = map(int, input().split()) u -= 1 v -= 1 d[u].append(v) d[v].append(u) for i in range(n): if len(...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; long long bigmod(long long b, long long p, long long md) { if (p == 0) return 1; if (p % 2 == 1) { return ((b % md) * bigmod(b, p - 1, md)) % md; } else { long long y = bigmod(b, p / 2, md); return (y * y) % md; } } int deg[100005]; int main() { int n;...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 500010; int n, m, d[N]; inline int read() { int sym = 0, res = 0; char ch = 0; while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar(); while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar(); return sym ? -res : res; } void fil...
10
CPP
#include <bits/stdc++.h> using namespace std; long long ar[100005], n, flag; int main() { cin >> n; for (int i = 0; i < n - 1; i++) { long long l, r; cin >> l >> r; ar[l]++; ar[r]++; } for (int i = 0; i < n + 1; i++) if (ar[i] == 2) flag = 1; if (!flag) cout << "YES"; else cout <...
10
CPP
n=int(input()) tree={} for i in range(n-1): a,b=[int(x) for x in input().split()] if a not in tree: tree[a]=1 else: tree[a]+=1 if b not in tree: tree[b]=1 else: tree[b]+=1 for item in tree: if tree[item]==2: print('NO') break else: print('YES')...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; bool b2(const pair<pair<int, int>, int> &p1, const pair<pair<int, int>, int> &p2) { return p1.first.first > p2.first.first; } bool b1(const pair<pair<int, int>, int> &p1, const pair<pair<int, int>, int> &p2) { return p1.first.second < p2.first.second; } ...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long int inf = 1e18, M = 1e9 + 7; const long long int N = 1e5 + 5; vector<long long int> v[N]; void solve() { long long int n; cin >> n; long long int a, b; for (long long int i = 1; i < n; ++i) { cin >> a >> b; v[a].push_back(b); v[b].push_ba...
10
CPP
from collections import defaultdict, deque, Counter from sys import stdin, stdout from heapq import heappush, heappop import math import io import os import math import bisect #?############################################################ def isPrime(x): for i in range(2, x): if i*i > x: brea...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n + 1); int u, v; for (int i = 0; i < n - 1; i++) { cin >> u >> v; a[u]++; a[v]++; } bool check = false; for (int i = 1; i <= n; i++) if (a[i] == 2) check = true; if (check) cout << "NO"; el...
10
CPP
#include <bits/stdc++.h> using namespace std; vector<int> v[100005]; int main() { int t, q, n, m, x, y, i, j, k; scanf("%d", &n); for (i = 1; i < n; i++) { scanf("%d%d", &x, &y); v[x].push_back(y); v[y].push_back(x); } int f = 0; for (i = 1; i <= n; i++) { if (v[i].size() == 2) { f = 1...
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a, b; vector<vector<int>> A(n); for (int i = 0; i < (n - 1); i++) { cin >> a >> b; A[a - 1].push_back(b - 1); A[b - 1].push_back(a - 1); } if (n <= 2) { cout << "YES" << endl; return 0; } bool flag = fa...
10
CPP
#include <bits/stdc++.h> using namespace std; vector<int> N[100005]; void addE(int a, int b) { N[a].push_back(b); N[b].push_back(a); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, a, b; cin >> n; for (int i = 1; i < n; i++) { cin >> a >> b; addE(a - 1, b - 1); ...
10
CPP
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { std::cerr << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); std::cerr...
10
CPP
#include <bits/stdc++.h> using namespace std; void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); srand(time(0)); solve(); return 0; } long long max(long long a, long long b) { if (a > b) return a; return b; } long long min(long long a, long long b) { if (a < b) return a; re...
10
CPP
n=int(input()) arr=[0]*n for i in range(0,n-1): x,y=map(int,input().split()) arr[x-1]+=1 arr[y-1]+=1 for i in range(0,n): if arr[i]==2: print("NO") exit() print("YES")
10
PYTHON3
#include <bits/stdc++.h> using namespace std; vector<vector<long long int>> graph; int solve() { long long int n; cin >> n; graph.resize(n + 1); n--; while (n--) { long long int a, b; cin >> a >> b; graph[a].push_back(b); graph[b].push_back(a); } long long int flag = 0; for (auto adj : g...
10
CPP
#include <bits/stdc++.h> using namespace std; int n; vector<int> G[100005]; int main() { scanf("%d", &n); for (int i = 1; i <= n - 1; 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 (G[i].size() == 2) { printf("NO\n"); ...
10
CPP
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename S37, typename... Args> void err(istream_iterator<string> it, S37 a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } const long long N = 200010, mod = 1e9 + 7, mod2 = 1e9 + 9, mod3 = 998...
10
CPP
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y, long long p) { long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } const int N = 1e5 + 7; const int xinc[] = {0, 0, 1, -1}; const int yinc[...
10
CPP
#include <bits/stdc++.h> using namespace std; using namespace std; vector<int> conn[200100]; bool oka = true; void dfs(int u, int par) { if (par == -1 && conn[u].size() == 1) ; else { if (conn[u].size() == 1) return; if (conn[u].size() < 3 || oka == false) { oka = false; return; } } ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 10; int n; vector<int> vs[N]; bool dfs(int node, int par) { if (par != -1 && vs[node].size() == 1) { return false; } int children = 0; bool bad = false; for (int v : vs[node]) if (v != par) { ++children; bad |= dfs(v, n...
10
CPP
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; long long mod = 1000000007; const int MX = 0x3f3f3f; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, i, u, v; cin >> n; vector<int> adj[n]; for (i = 0; i <= n - 2; i++) { cin >> u >> v; adj[u - 1].empl...
10
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int de[maxn]; int main() { ios::sync_with_stdio(false); int n; cin >> n; memset(de, 0, sizeof de); for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; de[u]++; de[v]++; } bool flag = true; for (int i = 1; i <=...
10
CPP
import sys n = int(sys.stdin.readline().strip()) d = [0] * n for i in range (0, n - 1): u, v = sys.stdin.readline().strip().split() u, v = int(u) - 1, int(v) - 1 d[u] = d[u] + 1 d[v] = d[v] + 1 if 2 in d: print("NO") else: print("YES")
10
PYTHON3
n = int(input()) tr = [0] * (n + 1) for i in range(n - 1): u, v = map(int, input().split()) tr[u] += 1 tr[v] += 1 for i in range(1, n + 1): if tr[i] == 2: print('No') break else: print('Yes')
10
PYTHON3
#include <bits/stdc++.h> using namespace std; int const maxn = 1e5 + 5; vector<int> p[maxn]; int main() { int n; scanf("%d", &n); int u, v; for (int i = 1; i < n; i++) { scanf("%d%d", &u, &v); p[u].push_back(v); p[v].push_back(u); } bool flag = 1; for (int i = 1; i <= n; i++) if (p[i].size...
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, i, flag = 0, x, y; cin >> n; long long int a[200005]; for (i = 1; i <= n; i++) { a[i] = 0; } for (i = 1; i < n; i++) { cin >> x >> y; a[x]++; a[y]++; } for (i ...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 7; int d[N]; int main() { int n; scanf("%d", &n); for (int i = 1, u, v; i < n; i++) { scanf("%d%d", &u, &v); d[u]++, d[v]++; } bool flag = true; for (int i = 1; i <= n; i++) { if (d[i] == 2) flag = false; } if (flag) ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int limit = 1000000; int n; vector<int> g[limit]; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } for (int u = 1; u <= n; u++) { vector...
10
CPP
#572_D1 n = int(input()) arr = [0] * n for i in range(0, n - 1): l = [int(j) for j in input().split(" ")] arr[l[0] - 1] += 1 arr[l[1] - 1] += 1 print(["YES", "NO"][2 in arr])
10
PYTHON3
#include <bits/stdc++.h> const double eps = 1e-7; using namespace std; int n; int deg[100010]; int main() { while (~scanf("%d", &n)) { int a = 0, b = 0; memset(deg, 0, sizeof(deg)); for (int i = 0; i < n - 1; ++i) { scanf("%d%d", &a, &b); deg[a] += 1; deg[b] += 1; } bool isOk = 1...
10
CPP
def add(x): global d, d2 if x not in d: d[x] = 0 d[x] += 1 if d[x] == 2: d2[x] = a if d[x] == 3: del d2[x] import sys n = int(sys.stdin.readline()) d = {} d2 = {} for _ in range(n-1): a, b = map(int, sys.stdin.readline().split()) add(a) add(b) res = 'YES' for ...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; int a[100006]; int main(void) { int n, x, y; cin >> n; for (int i = 1; i < n; i++) cin >> x >> y, a[x]++, a[y]++; for (int i = 1; i <= n; i++) if (a[i] == 2) { cout << "NO"; return 0; } cout << "YES"; }
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; unordered_map<int, int> m; for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; m[a]++; m[b]++; } for (int i = 1; i <= n; i++) { if (m[i] == 2) { cout << "NO"; return 0; } } cout << "YES...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long maxN = 2 * 100224; struct BIT { long long data[maxN] = {0}; void update(long long idx, long long val) { while (idx < maxN) { data[idx] += val; idx += idx & -idx; } } void update(long long l, long long r, long long val) { updat...
10
CPP
#include <bits/stdc++.h> using namespace std; int const maxn = 1e6 + 5; long long tree[4 * maxn], lazy[4 * maxn], a[maxn]; int kq[maxn]; int n; void down(int g) { if (lazy[g] != 0) { tree[g << 1] += lazy[g]; lazy[g << 1] += lazy[g]; tree[(g << 1) | 1] += lazy[g]; lazy[(g << 1) | 1] += lazy[g]; laz...
10
CPP
#include <bits/stdc++.h> using namespace std; long long n, a[500001], f[500001], ans[500001], mn; int lowbit(int x) { return x & (-x); } void ins(long long x, long long w) { long long i; for (i = x; i <= n; i += lowbit(i)) f[i] += w; } long long query(long long x) { long long xlh = 0, i; for (i = x; i; i -= low...
10
CPP
#include <bits/stdc++.h> using namespace std; long long int ar[4 * 200005]; void update(int a, int b, int l, int h, int p) { if (a < l || a > h) return; if (l == h) { ar[p] += b; return; } int m = (l + h) / 2; update(a, b, l, m, 2 * p); update(a, b, m + 1, h, 2 * p + 1); ar[p] += b; return; } in...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long MAX = 200100; pair<long long, long long> tree[256 * 1024 * 2]; long long lazy[256 * 1024 * 2]; void updateRangeUtil(long long si, long long ss, long long se, long long us, long long ue, long long diff) { if (lazy[si] != 0) { tree[s...
10
CPP
from sys import stdin,stdout class Tree(object): def __init__(self,n): self.tree=[0]*(4*n+10) self.b=[0]*(n+10) self.a=list(map(int,stdin.readline().split())) self.n=n def update(self,L,C,l,r,rt): if l==r: self.tree[rt]+=C return mid=(l+r)...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; const int maxm = 4e6 + 10; const long long mod = 1e9 + 7; const int inf = 0x3ffffff; const double eps = 1e-5; long long n, s[maxn]; long long a[maxn], ans[maxn << 2], tag[maxn << 2], m; long long res[maxn]; inline void push_up(long long p) { ans[p...
10
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; ll P[200001]; ll sum[200001]; ll fen[200001]; int ans[200001]; void build() { for (int i = 1; i <= 200000; i++) { sum[i] = sum[i - 1] + ll(i - 1); fen[i] = sum[i] - sum[i - (i & -i)]; } } ll query(int l, int r) { if (l != 1LL) return quer...
10
CPP
#include <bits/stdc++.h> using namespace std; long long read() { char ch = getchar(); long long x = 0, ff = 1; while (ch < '0' || ch > '9') { if (ch == '-') ff = -ff; ch = getchar(); } while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); return x * ff; } void write(long long aa) { ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int M = 2e5 + 5; int p[M << 2], res[M]; long long V[M << 2], tag[M << 2]; void push_up(int o) { if (V[o << 1] < V[o << 1 | 1]) { V[o] = V[o << 1]; p[o] = p[o << 1]; } else { V[o] = V[o << 1 | 1]; p[o] = p[o << 1 | 1]; } } void push_down(int o) { ...
10
CPP
import sys input = sys.stdin.readline n=int(input()) A=list(map(int,input().split())) BIT=[0]*(n+1) def update(v,w): while v<=n: BIT[v]+=w v+=(v&(-v)) def getvalue(v): ANS=0 while v!=0: ANS+=BIT[v] v-=(v&(-v)) return ANS for i in range(1,n+1): update(i,i) ANS=[-...
10
PYTHON3
class FTree: def __init__(self, f): self.n = len(f) self.ft = [0] * (self.n + 1) for i in range(1, self.n + 1): self.ft[i] += f[i - 1] if i + self.lsone(i) <= self.n: self.ft[i + self.lsone(i)] += self.ft[i] def lsone(self, s): ...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int ans[maxn]; int n; long long a[maxn]; const int maxnode = maxn << 2; long long sum[maxnode], add[maxnode]; struct Node { int l, r; int mid() { return (l + r) >> 1; } } node[maxnode]; void Pushup(int rt) { sum[rt] = sum[rt << 1] + sum[rt << ...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long MAXN = 2e5 + 10; const long long INF = 0x3f3f3f3f; const long long LLINF = 0x3f3f3f3f3f3f3f3f; const long long MOD = 1e9 + 7; long long segtree[MAXN << 2]; long long lazy[MAXN << 2]; long long arr[MAXN]; long long ans[MAXN]; void pushup(long long rt) { seg...
10
CPP
#include <bits/stdc++.h> using namespace std; long long b[200005]; int n; long long sum(long long x) { if (x == 0) { return 0; } long long pas = 0; while (x > 0) { pas += b[x]; x = x & (x - 1); } return pas; } void update(long long x, long long i) { while (i <= n) { b[i] += x; i += (i ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 200010; int n, p[N]; long long a[N], tr[N << 2]; void build(int k, int l, int r) { if (l == r) { tr[k] = l; return; } int mid = l + r >> 1; build(k << 1, l, mid); build(k << 1 | 1, mid + 1, r); tr[k] = tr[k << 1] + tr[k << 1 | 1]; } void ad...
10
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<int, int>; using ld = long double; using pii = pair<int, int>; using dbl = long double; using vll = vector<int>; #pragma GCC optimize("O2") #pragma GCC optimize("unroll-loops") const ll mod = 1000000007; const ll N = 2e5 + 10; const ll...
10
CPP
#include <bits/stdc++.h> using namespace std; long long int fen[200005]; void upd(long long int x, long long int a) { for (long long int i = x; i < 200005; i += (i & (-i))) { fen[i] += a; } } long long int ret(long long int x) { long long int o = 0; for (long long int i = x; i > 0; i -= (i & (-i))) { o ...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long MAXN = 200100; const long long INF = 2000000100; const long long MOD = 998244353; long long N, S[MAXN], P[MAXN]; long long B[MAXN]; void update(int ind, long long v) { for (int i = ind; i <= N; i += (i & -i)) { B[i] += v; } } long long query(int ind)...
10
CPP
#include <bits/stdc++.h> using namespace std; struct node { int64_t data, lazy; int pos; }; node st[200001 * 4]; int64_t input[200001]; int anw[200001]; void output(int root, int L, int R) { if (L == R) { return; } int mid = (L + R) >> 1; output(root << 1, L, mid); output(root << 1 | 1, mid + 1, R); }...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 10, Max = 101; const int MOD = 1000000007; const long long OO = 2e12 + 5000; const long long Sqrt = 710; const double PI = acos(-1); const double EPS = 1e-9; int n; long long a[N]; pair<long long, long long> seg[4 * N]; long long lazy[8 * N]; void ...
10
CPP
# https://codeforces.com/contest/1208/problem/D from sys import stdin, stdout input = stdin.readline # print = stdout.write # si is the sum of elements before the i-th element that are smaller than the i-th element. # For every i from N to 1, let's say the value of the si is x. # So it means there are k smallest unu...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; class { public: pair<long long, long long> T[200009 << 2]; long long lz[200009 << 2]; long long n, f[200009], ans[200009]; void solve() { cin >> n; for (int i = 1; i <= n; ++i) cin >> f[i]; build(1, 1, n); for (int i =...
10
CPP
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const long long inf = 1000000000000; const int N = 200005; const long long LLMAX = 2e18; const long long MOD = 1000000009ll; const double eps = 1e-8; const int MAXN = 1e6 + 10; int gcd(int a, int b) { return b == 0 ? a :...
10
CPP
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int INF = 2e9; const long long INFLL = 1e18; const int MAX_N = 1; int N; vector<long long> v; struct SEG { struct NODE { int l, r; long long data; }; vector<NODE> seg; int SZ; void add() { seg.push_back((NODE){-1, -1, (lon...
10
CPP
#include <bits/stdc++.h> const int inf = INT_MAX; const int MAX = 3e6 + 9; const long long MOD = 1e9 + 7; const int TOT_PRIMES = 1e6 + 9; const int MAX_A = 71; const int LN = 20; using namespace std; long long bt[MAX]; long long arr[MAX]; void update(int x, long long val) { for (int i = x; i < MAX; i += i & -i) bt[i]...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 200010; long long fen[N]; void modify(int x, long long v) { while (x < N) { fen[x] += v; x |= x + 1; } } long long get(int x) { long long r = 0; while (x >= 0) { r += fen[x]; x = (x & (x + 1)) - 1; } return r; } int main() { ios::...
10
CPP
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! # TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! # TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! from sys import stdin, stdout from collections import defaultdict from collections import deque import math import copy #T = int(input()) N = int(input()) #s1 = input() #s2 = input() #N,Q = [int(x) for...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 9; long long s[maxn]; int p[maxn]; int vis[maxn]; int temp; struct node { int l, r; long long minn, lazy; } tree[maxn << 2]; void BT(int p, int l, int r) { tree[p].l = l, tree[p].r = r; if (l == r) { tree[p].minn = s[l]; tree[p].lazy =...
10
CPP
def sum_number(n,j): j[0]=0 j[1]=0 for i in range(2,n+1): j[i]=j[i-1]+(i-1) return(j) po=int(input()) l=[0]*(po+1) l1=[int(i) for i in input().split()] def getsum(BITTree,i): s = 0 while i > 0: s += BITTree[i] i -= i & (-i) return(s) def updatebit(BITTree , n , i ...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10, eps = 1e-10; int n; long long a[N]; long long tree[N]; int ans[N]; long long sum(int x) { long long res = 0; while (x) { res += tree[x]; x -= (x & (-x)); } return res; } void add(int x, long long sum) { while (x <= n) { tree[x] ...
10
CPP
#include <bits/stdc++.h> using namespace std; int n; long long cl[202020]; long long T[202020]; int chk[202020]; int ans[202020]; void m_Tree(int x, int t) { for (int i = x; i <= n; i += i & (-i)) { T[i] += t; } } long long g_Tree(int x) { long long ret = 0; for (int i = x; i > 0; i -= i & (-i)) ret += T[i]...
10
CPP
#include <bits/stdc++.h> using namespace std; typedef long double ld; const long double PI = 3.141592653589793238462643383279502884197169399375105820974944; const long long mod = 998244353; const long long inf = 1e18; const long long maxn = 1e5 + 5; struct BIT { vector<long long> bit; long long maxn; void ini...
10
CPP
#include <bits/stdc++.h> using namespace std; vector<unsigned long long> t, lazy; void build(unsigned long long a[], int v, int tl, int tr) { if (tl == tr) { t[v] = a[tl]; } else { int tm = (tl + tr) / 2; build(a, v * 2 + 1, tl, tm); build(a, v * 2 + 2, tm + 1, tr); t[v] = min(t[v * 2 + 1], t[v ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int MAXN = 2e5 + 5; const int inf = 0x3f3f3f3f; long long s[MAXN]; struct node { int l, r; long long sum; } node[MAXN << 2]; void build(int l, int r, int num) { node[num].l = l; node[num].r = r; if (l == r) { node[num].sum = l; ...
10
CPP
#include <bits/stdc++.h> using namespace std; int n; long long a[300000], b[300000], C[300000]; int lowbit(int x) { return x & (-x); } long long getSum(int x) { long long sum = 0; for (int i = x; i > 0; i -= lowbit(i)) sum += C[i]; return sum; } void add(int x, int val) { for (int i = x; i < n; i += lowbit(i)) ...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; struct node { long long w, change; int in; }; vector<long long> a; vector<node> t; const long long INF = 1e18; node combine(node a, node b, long long change) { a.w += a.change; b.w += b.change; node res; if (a.w != b.w) res = (...
10
CPP
#include <bits/stdc++.h> using namespace std; int dx[8] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy[8] = {1, -1, -1, 0, 1, -1, 0, 1}; long long tree[4 * 200005], lazy[4 * 200005], ans[4 * 200005], a[200005]; void build(long long int start, long long int last, long long int node) { if (start == last) { tree[node] = a[st...
10
CPP
import sys input = sys.stdin.readline nn = 18 bit=[0]*(2**nn+1) def addbit(i, x): while i <= 2**nn: bit[i] += x i += i & (-i) def getsum(i): ret = 0 while i != 0: ret += bit[i] i -= i&(-i) return ret def searchbit(x): l, sl = 0, 0 d = 2**(nn-1) while d:...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5; long long n, m, s[N], a[N], C[N], vis[N]; long long lowbit(long long x) { return (x & (-x)); } long long sum(long long x) { long long res = 0; while (x > 0) { res += C[x]; x -= lowbit(x); } return res; } void add(long long x, lon...
10
CPP
#include <bits/stdc++.h> using namespace std; template <class T> bool mini(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool maxi(T &a, T b) { return a < b ? (a = b, true) : false; } const int N = 2e5 + 5; int n, ans[N]; long long bit[N], p[N]; void up(int i) { assert(i > 0); for (lon...
10
CPP
#include <bits/stdc++.h> using namespace std; int n, lo[(long long)(2e5 + 5) * 4], hi[(long long)(2e5 + 5) * 4], ans[(long long)(2e5 + 5)]; long long base[(long long)(2e5 + 5)], delta[(long long)(2e5 + 5) * 4]; pair<long long, int> mn[(long long)(2e5 + 5) * 4]; void update(int i); void ini(int i, int a, int b) { ...
10
CPP
#include <bits/stdc++.h> using namespace std; long int n; long long int tree[200001 * 10]; long int a[200002]; void build(long int node, long int start, long int end) { if (start == end) { tree[node] = a[start]; } else { long int mid = (start + end) / 2; build(2 * node + 1, start, mid); build(2 * no...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long Nmax = 2e6 + 5; long long v[Nmax]; long long ans[Nmax]; long long lazy[4 * Nmax]; pair<long long, long long> all[4 * Nmax]; long long p, q, val; void add(long long &first, long long val) { if (first != LLONG_MAX) first += val; } void propagate(long long no...
10
CPP
#include <bits/stdc++.h> using namespace std; int n; int z[200020]; long long a[200020]; long long c[200020]; void R(int x, int y) { for (; x <= n; x += x & -x) { c[x] += y; } } int A(long long x) { int re = 0; for (int i = 1 << 20; i > 0; i >>= 1) { if (re + i <= n && c[re + i] <= x) { x -= c[re ...
10
CPP
#include <bits/stdc++.h> using namespace std; long long t[200025 * 4], lz[200025 * 4], n, a[200025]; void build(int l, int r, int i) { t[i] = 1ll * l * (l - 1) / 2; if (l == r) return; build(l, (l + r) / 2, i * 2 + 1); build((l + r) / 2 + 1, r, i * 2 + 2); t[i] = max(t[i * 2 + 1], t[i * 2 + 2]); } void down(i...
10
CPP
#include <bits/stdc++.h> const int MAXN = 2e5 + 10; const long long inf = 1e17 + 10; using namespace std; struct Seg { long long v[MAXN * 4], lazy[MAXN * 4]; int m(int l, int r) { return (l + r) / 2; } void updPoint(int pos, int l, int r, int x, long long val) { if (l == r) { v[pos] = val; return;...
10
CPP