func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const long long INF = 1000000000; template <class T> T read(T &x) { char c; int flag = 1; while ((c = getchar()) < 0 || c > 9 ) if (c == - ) flag *= -1; x = c - 0 ; while ((c = getchar()) >= 0 && c... |
#include <bits/stdc++.h> using namespace std; int dp[1003][1003], a[1003]; pair<pair<int, int>, int> from[1003][1003]; vector<pair<int, int> > sol; int main() { int N; cin >> N; for (int i = 1; i <= N; i++) cin >> a[i]; if (N % 2 == 0) { N++; a[N] = 0; } memset(dp, 0x3f3f3f... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; int bit[MAXN + 100], ans[MAXN], _pos[MAXN]; vector<pair<int, int> > _query[MAXN]; vector<int> d[MAXN]; void upd(int id) { for (; id <= MAXN; id += id & (-id)) bit[id]++; return; } int get(int id) { int now = 0; for ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int q, n; cin >> q; while (q--) { cin >> n; vector<int> a(1 + n), answer(1 + n, 0); map<int, unordered_set<int> > m; vector<bool> vis(n + 1, false); for (int i = 1; i <= n; ++i) { ... |
#include <bits/stdc++.h> #include<unordered_set> using namespace std; #define ll long long int #define f1(i,n) for(i=0;i<n;i++) #define f2(i,a,n) for(i=n-1;i>=a;i--) #define f3(i,a,n) for(i=a;i<n;i++) #define vl vector<long long int> #define um unordered_map<ll,ll> #define us unordered_set<ll> #defi... |
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { long long n, m, k, l; scanf( %lld%lld%lld%lld , &n, &m, &k, &l); n /= m; m = (m + k + l - 1) / m; printf( %lld n , (n >= m) ? m : -1); return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { vector<int> even_bag, odd_bag; int n, all, x; cin >> n; for (int i = 0; i < n; i++) { cin >> x; all += x; if (x & 1) odd_bag.push_back(x); else even_bag.push_back(x); } cout << ((all & 1) ? odd... |
#include <bits/stdc++.h> using namespace std; const int NMAX = 1e5 + 7; long long n, a[NMAX], b[NMAX]; long long dp[NMAX]; struct linija { long long a, b; }; linija c[NMAX]; int sz, cur; double prijesek_x(int i, int j) { return (double)(c[i].b - c[j].b) / (c[j].a - c[i].a); } void dodaj(li... |
#include <bits/stdc++.h> using namespace std; long long power(long long x, long long y, long long m); long long modInverse(long long n, long long m); long long nCr(long long n, long long r, long long m); long long ceiling(long long x, long long y); bool sortbyth(const tuple<long long, int, int>& a, ... |
#include <bits/stdc++.h> using namespace std; long long n, m; const long long inf = 0x3f3f3f3f; const long long size = 100000; struct data { long long id, step; long long x, y, z; data(){}; data(long long u, long long v) : id(u), step(v){}; data(long long a, long long b, long long c) : x(a... |
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v; int main(void) { int n, m, a, b; scanf( %d%d , &n, &m); for (int i = 0; i < m; i++) { scanf( %d%d , &a, &b); v.push_back(make_pair(b, a)); } sort(v.rbegin(), v.rend()); long long ans = 0; int i = 0; ... |
#include <bits/stdc++.h> using namespace std; long long read() { long long x = 0, F = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) F = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { x = (x << 3) + (x << 1) + c - 0 ; c = getchar(); } retu... |
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T &x) { char ch; bool flag = false; while (!isdigit(ch = getchar())) flag |= ch == - ; for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48)) ; if (flag) x = -x; } inline int input() { ... |
#include <bits/stdc++.h> using namespace std; int n; pair<int, int> s[300100]; pair<int, int> r[300100]; int res[300300]; int s1[300300]; int r1[300300]; map<pair<int, int>, int> rep; int dp[94040]; void add(int a, int b, int x, int l = 1, int h = 1e4 + 2, int p = 1) { if (a == l && b == h) { ... |
#include <bits/stdc++.h> using namespace std; void solve(long long cno) { long long n, i, j, k; cin >> n; long long arr[n]; for (i = 0; i < n; i++) { cin >> arr[i]; } if (n < 3) { cout << 0 << endl; for (auto x : arr) { cout << x << ; } return; } ... |
#include <bits/stdc++.h> double A[200000], B[200000]; int i, j, n, m; double p; int main() { scanf( %d , &n); for (i = 1; i <= n; i++) { scanf( %lf , &p); B[i] = p * (B[i - 1] + 1); A[i] = (A[i - 1] + 2 * B[i - 1] + 1) * p + (1 - p) * A[i - 1]; } printf( %.9lf n , A[n]); } |
//#include<ext/pb_ds/assoc_container.hpp> //#include<ext/pb_ds/hash_policy.hpp> #include<bits/stdc++.h> #define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define multiCase int T;cin>>T;for(int t=1;t<=T;t++) #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define repp(i,a,b) for(int i=(a);i<(b);i... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline T read(register T& t) { register T f = 1; register char ch = getchar(); t = 0; while (ch < 0 || ch > 9 ) { if (ch == - ) f = -f; ch = getchar(); } while (ch >= 0 && ch <= 9 ) t = t * 10 + ch - 0 ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int array[n]; for (int i = 0; i < n; i++) { cin >> array[i]; } if (n == 1) { cout << 1 << endl; return 0; } int Count = 1; vector<int> vec; for (int i = 0; i < n - 1; i++) { if... |
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; string inp; cin >> inp; bool found = false; for (int i = 0; (i < n - 1) && k; ++i) { if (inp[i] == 4 && inp[i + 1] == 7 ) { if (((i + 1) & 1) && (i < n - 2) && (inp[i + 2] == 7 )) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, y; cin >> n; set<int> t; for (int i = 0; i < n; i++) { cin >> y; if (y != 0) t.insert(y); } cout << t.size() << endl; } |
#include <bits/stdc++.h> using namespace std; const int N = (1 << 20) + 69; int heap[N], idx[N], val[N]; int g, h; void dream(int curr) { while (curr < ((1 << (h - 1)) - 1) && heap[curr] > min(heap[2 * curr + 1], heap[2 * curr + 2])) { int& left = heap[2 * curr + 1]; int& right = he... |
#include <bits/stdc++.h> using namespace std; struct node { vector<int> adj; } graf[5 * 10010]; bool mark[5 * 10010]; int last[5 * 10010]; void DFS(int u, int lst) { last[u] = lst; mark[u] = true; for (int i = 0; i < graf[u].adj.size(); i++) if (!mark[graf[u].adj[i]]) DFS(graf[u].adj[i... |
#include <bits/stdc++.h> using namespace std; vector<int> cyc; vector<int> path; void dfs(vector<int> *graph, int node, vector<bool> vis, int pnode) { if (vis[node] == true) { path.pop_back(); for (int i = path.size() - 1; i >= 0; i--) { if (path[i] != node) { cyc.push_back(pat... |
#include <bits/stdc++.h> using namespace std; int n; int a[200009], b[200009]; bool k[200009]; int mx; int main() { scanf( %d , &n); for (int j = 1; j <= n; j++) scanf( %d , &a[j]); for (int j = 1; j <= n; j++) scanf( %d , &b[j]); for (int j = 1; j <= n; j++) k[a[j]] = 1; if (!k[1]) { ... |
#include <bits/stdc++.h> using namespace std; string s; int n; int ok = 0; int main() { ios::sync_with_stdio(false); cin >> n; cin >> s; for (int i = 0; i <= n - 5; i++) { if (s[i] == * ) { for (int j = 1; j <= n; j++) { int now = i, total = 0; while (now < n... |
#include <bits/stdc++.h> using namespace std; const int MAX = 500500, MOD = 1e9 + 7; long long Norm(long long x) { return ((x % MOD + MOD) % MOD); } int n; long long prefsumx[2 * MAX], prefsumy[2 * MAX]; long long prefpov[2 * MAX]; long long prefob[2 * MAX], prefprav[2 * MAX]; pair<int, int> tocke[2 * M... |
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, /stack:200000000 ) #pragma GCC optimize( Ofast ) #pragma GCC optimize(3) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) #pragma GCC target( sse3 , sse2 , sse ) #pragma GCC target( avx , sse4 , sse4.1 ... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline int Chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; } template <typename T> inline int Chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; } template <typename T> inline T read() { T sum = 0, fl = 1; char ch = get... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, m; cin >> n >> k >> m; vector<string> words; words.push_back( ____jj ); long long cost[n + 1]; unordered_map<string, long long> u; for (int i = 0; i < n; ++i) { string h; cin >> h; words.push_bac... |
#include <bits/stdc++.h> using namespace std; const long long sz = 2 * 1e5 + 5, mod = 1e9 + 7; vector<long long> adj[sz]; long long dp[sz][2], x[sz]; void dfs(long long v, long long p) { dp[v][x[v]] = 1; for (auto u : adj[v]) { if (u == p) continue; dfs(u, v); dp[v][1] = (d... |
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; map<tuple<unsigned long, int, int>, pair<long long, long long> > m; pair<long long, long long> zml(long long x, bitset<10> s, int p, int k, bool limit) { if (int(s.count()) > k) return {0, 0}; ... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:102400000,102400000 ) using namespace std; const int maxn = 1e3 + 10; const int inf = 0x7fffffff; const long long INF = 9E18; const int mod = 1e9 + 7; const long long mod2 = 1e9 + 9; const double eps = 1e-7; const double pi = acos(-1.0); templ... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { bool b = 0; char c; while (!isdigit(c = getchar()) && c != - ) ; if (c == - ) c = getchar(), b = 1; x = c - 48; while (isdigit(c = getchar())) x = (x << 3) + (x << 1) + c - 48; if (b) x... |
#include <bits/stdc++.h> #pragma comment(linker, /stack:640000000 ) using namespace std; int fx[] = {0, 0, -1, 1, -1, 1, 1, -1}; int fy[] = {1, -1, 0, 0, 1, 1, -1, -1}; struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << ; return *this; } } dbg;... |
#include <bits/stdc++.h> using namespace std; string proc(char *a) { int n = strlen(a); char s[100]; int i = 0, j = 0; while (i < n) { if (a[i] == u ) s[j++] = o , s[j++] = o ; else s[j++] = a[i]; i++; } s[j] = 0 ; strcpy(a, s); n = j; i = j... |
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int INF = (int)1e9; const long long LINF = (long long)1e18; const long double PI = acos((long double)-1); const long double EPS = 1e-9; inline long long gcd(long long a, long long b) { long long r; while (b) { ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 3000 + 10; int ans[maxn][maxn]; int N, M, K; set<pair<pair<int, int>, int> > seti; queue<pair<int, int> > qu; vector<int> ve[maxn]; pair<int, int> prv[maxn][maxn]; void BFS() { ans[0][0] = 1; prv[0][0] = make_pair(0, 0); qu.pus... |
#include <bits/stdc++.h> const int inf = 1e9 + 7; const int mod = 1e9 + 7; using namespace std; int main() { long long N; cin >> N; long long cnt = 1; long long now = 10; while (now <= N) { now *= 10; cnt++; } long long ans = (cnt - 1) * 9; long long n = cnt - 1; ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long int n; char c; cin >> n >> c; n--; if (n % 4 >= 2) n -= 2; long long int ans = n / 4 * 16; n %= 4; ans += n * 7; n %= 2; if (c >= d ) ans += g -... |
#include <bits/stdc++.h> using namespace std; int ar[100001]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, cur = 0; string s; cin >> n; cin >> s; for (int i = 0; i < n; i++) { cin >> ar[i]; } for (int i = 0; i < 10000000; i++) { if (s[cur]... |
#include <bits/stdc++.h> using namespace std; vector<int> adj[200005]; vector<int> toposort; bool color[200005]; bool visit[200005]; bool flag; int mp[200005]; void topo(int index) { color[index] = true; for (int i = 0; i < adj[index].size(); i++) { int next = adj[index][i]; if (colo... |
#include <bits/stdc++.h> using namespace std; int ch[42][42][42][42], qs[42][42], ans[42][42][42][42]; int b[42][42], cou[42][42]; char a[42]; int main() { int n, m, q, i, j, ii, jj; scanf( %d %d %d , &n, &m, &q); for (i = 1; i <= n; i++) { scanf( %s , a + 1); for (j = 1; j <= m; j++)... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; const int MOD = 1000000007; vector<pii> ree; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = (0); i < (n); i++) { int x, v; cin >> x >> ... |
#include <bits/stdc++.h> using namespace std; template <typename T> ostream& operator<<(ostream& stream, const pair<T, T>& p) { return stream << ( << p.first << , << p.second << ) ; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int T; cin >> T; while (T--) { ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int a[maxn]; vector<int> b; int n; void get_input() { cin >> n; } void solve() { for (int i = 0; i < n; i++) { cin >> a[i]; b.push_back(a[i]); } sort(b.begin(), b.begin() + n); int cnt = 0; for (int i ... |
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == - ) f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - 48; ch = getchar(); } return x * f; } int n, m, W; ... |
#include <bits/stdc++.h> using namespace std; long long int power(long long int base, long long int exp) { long long int res = 1; base = base % 1000000007; while (exp) { if (exp & 1) res = (res * base) % 1000000007; base = (base * base) % 1000000007; exp >>= 1; } return res; ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; ; vector<int> a(n); int m = 1000; for (__typeof(0) i = 0; i < n; i++) { cin >> a[i]; m = min(a[i], m); } int minc = 0; for (__typeof(0) i ... |
#include <bits/stdc++.h> char now[100], s[20][100]; int ans, n, m, a[20]; bool check() { for (int i = 1; i <= m; i++) { int sum = 0; for (int j = 0; j < n; j++) sum += now[j] != s[i][j]; if (sum != a[i]) return (false); } return (true); } void dfs(int x, int y) { if (y == a[1... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; inline int yes(int x) { return x * 2; } inline int no(int x) { return x * 2 + 1; } vector<int> E1[210], E2[210]; inline void build(int x, int y) { E1[x].push_back(y); E2[y].push_back(x); } bool vis[... |
#include <bits/stdc++.h> using namespace std; int mo[10]; int main() { int n; scanf( %d , &n); int a[n + 1]; for (int i = int(0); i <= int(n - 1); i++) { scanf( %d , a + i); } sort(a, a + n); a[0] = 1; for (int i = int(1); i <= int(n - 1); i++) { if (a[i] > a[i - 1]) ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 15; const int maxe = 1086 * 1086 * 4; const int mod = 1000000007; const double eps = 1e-6; char s[maxn][maxn]; int n = 10; bool is_x(int x, int y) { if (x < 0 || x >= n || y < 0 || y >= n) return false; return s[x][y] == X ; } b... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, l = 1; cin >> n; for (long long int i = 1; i < n; i++) { l += i; if (l > n) { l -= n; } cout << l << ; } } |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, i, j, k, l, p = 0, q, x, y, z; scanf( %lld %lld %lld %lld , &n, &m, &k, &l); x = l * 2; x = min(x, n); i = x / 2; for (; i >= 0; i--) { x = i * 2; x = n - x; x = min(x, k); for (j = x; j >=... |
#include <bits/stdc++.h> using namespace std; int f[305][305][305]; int p[305][305]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) scanf( %d , &p[i][j]); f[0][0][0] = p[0][0]; for (int x1 = 0; x1 < n; x1++) for (int y1 = 0; y1 < n; y... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 5100; int n, T; int pr[MAXN], t[MAXN]; double rest[MAXN]; double dp[MAXN][MAXN]; double pw[MAXN]; int main() { ios_base::sync_with_stdio(false); cin >> n >> T; for (int i = 1; i <= n; ++i) { cin >> pr[i] >> t[i]; doub... |
#include <bits/stdc++.h> #pragma comment(linker, /stack:67108864 ) using namespace std; template <class T> T abs(T a) { return (a) > 0 ? (a) : -(a); } template <class T> T sqr(T a) { return (a) * (a); } const long double PI = 3.1415926535897932, EPS = 1E-9; const int INF = 1000 * 1000 * 100... |
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 9; int n, vl, ans, tmp[110000], ret[110000]; void redo(vector<int>& a) { int i, j, s, p, q, nn = 0; for (i = 0; i < a.size(); i++) { if (nn == 0 || a[nn - 1] < a[i]) a[nn++] = a[i]; } a.resize(nn); } void dfs(int id, v... |
#include <bits/stdc++.h> int main() { int T; scanf( %d , &T); while (T--) { int n; scanf( %d , &n); int sum = 0; for (int i = 0; i < n; i++) { int t; scanf( %d , &t); if (t <= 2048) { sum += t; } } printf( %s n , sum >= 2048 ? ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; string colours; cin >> n >> colours; string collec[] = { RGB , RBG , BRG , BGR , GRB , GBR }; int index; int max = INT_MAX; for (int i = 0; i < 6; i++) { int count = 0; for (int j = 0; j < n; j++) { ... |
#include <bits/stdc++.h> using namespace std; string s[51]; int main() { int tot = 1; cin >> s[1]; int len = s[1].size(); for (int i = 2; i <= s[1].size(); i += 1) { s[i] = s[i - 1]; string ss; ss.resize(1); ss[0] = s[i][len - 1]; s[i].insert(0, ss); s[i].erase(... |
/** * created: 05/04/2021, 13:22:49 **/ #include <bits/stdc++.h> using namespace std; const int max_n = 6066, inf = 1000111222; template<typename T> ostream& operator << (ostream &os, const vector<T> &v) { os << [ ; for (int i = 0; i < v.size(); ++i) { if (i) { ... |
#include <bits/stdc++.h> using namespace std; int a[100000]; int b[100000]; int main() { int n, m, y0, y1; cin >> n >> m >> y0 >> y1; for (int x = 0; x < n; ++x) { cin >> a[x]; } for (int x = 0; x < m; ++x) { cin >> b[x]; } int i = 0, j = 0, pp = -1; int kk = 0; f... |
#include <bits/stdc++.h> using namespace std; int n; char a[1005], b[1005]; int minn, maxx; int main() { scanf( %d , &n); scanf( %s%s , a, b); sort(a, a + n); sort(b, b + n); for (int i = 0, j = 0; i < n; i++) { while (j < n && b[j] < a[i]) j++; if (j < n) j++; el... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int t; cin >> t; while (t--) { int n; cin >> n; vector<int> arr(n); map<int, int> mp; for (int i = 0; i < n; i++) { cin >> arr[i];... |
#include <bits/stdc++.h> using namespace std; int n, p; int sum[200000]; int main() { scanf( %d %d , &n, &p); for (int i = 1; i <= n; ++i) { scanf( %d , &sum[i]); sum[i] = (sum[i - 1] + sum[i]) % p; } int ans = 0; int l, r; for (int i = 1; i < n; ++i) { l = sum[i]; ... |
#include <bits/stdc++.h> using namespace std; const int order[3][4] = {{0, 1, 2, 3}, {0, 2, 3, 1}, {0, 3, 1, 2}}; long long solve(long long n) { long long four = 1; while (four * 4 <= n) { four *= 4; } int part = (n - 1) % 3; n -= four; n /= 3; long long res = four * (part + 1); ... |
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; long long google_itr = 1; const long long mod = 1e9 + 7; const long long inf = 1e18; void virus() { long long len, k; cin >> len >> k; string seq; cin >> seq; long long zero = 0, one = 0; for (auto i = 0; i < ... |
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 3, M = 1e5 + 3; const double eps = 1e-7; int n, m, k, u[M], v[M], id[M]; double w[M]; bool vis[M]; struct dsu { int fa[N]; inline void init(int range) { for (register int i = (1); i <= (range); ++i) fa[i] = i; } int Fn... |
#include <bits/stdc++.h> using namespace std; const int Max_N = 55; const int dx[] = {233, 0, 0, 1, -1}; const int dy[] = {233, 1, -1, 0, 0}; namespace Disjoint_set { int fa[Max_N * Max_N], siz[Max_N * Max_N]; int getf(int u) { return fa[u] == u ? u : fa[u] = getf(fa[u]); } void init(int n) { for (i... |
#include <bits/stdc++.h> using namespace std; int conv[1000000]; int a[1000000]; int b[1000000]; int n; int best = 0; int d[1000000]; int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; } for (int i = 0; i < n; i++) { ... |
#include <bits/stdc++.h> using namespace std; int a[1000]; int main() { long long p; int k; cin >> p >> k; int kol = 0; while (p > 0) { a[kol] = kol % 2 ? (k - p % k) % k : p % k; p = (kol % 2 ? (p + k - 1) : p) / k; kol++; } if (kol % 2 == 0) { a[kol++] = 1; ... |
#include <bits/stdc++.h> using namespace std; map<int, int> mp; const int N = 1e5 + 3, M = 2e5 + 3; int b[N], st[N], tp, he[N], to[M], ne[M], d[N], a[N]; bool f[N]; void dfs(int x) { for (int i, j; i = he[x];) if (he[x] = ne[i], !f[j = i >> 1]) f[j] = 1, dfs(to[i]), st[++tp] = i; } int main() ... |
#include <bits/stdc++.h> using namespace std; const double PI{3.1415926535897932384626433832795}; const int MOD{static_cast<int>(1e9 + 7)}; const double EPS{1e-9}; template <typename T> T ModAdd(const T &a, const T &b, const int &mod = MOD) { return ((a) % mod + (a) % mod) % mod; } template <typenam... |
#include <bits/stdc++.h> using namespace std; int r[100005], t, n, m, ans = 0; vector<int> id[100005]; set<int> v; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= m; i++) { scanf( %d , &t); v.insert(t); id[t].push_back(i); r[t] = max(r[t], i); } for (auto it : ... |
#include <bits/stdc++.h> using namespace std; int n, m; int cnt; int dfn[300005], low[300005], bel[300005], tot, scc; bool vis[300005], ins[300005]; string ori[100005]; stack<int> s; map<string, int> hashh; vector<int> g[300005], dag[300005]; pair<long long, long long> a[300005]; pair<long long, l... |
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const long long LINF = 1e17; const double PI = 3.141592653589793238; const int mod = 1000000007; const double eps = 0.000001; template <typename T, typename TT> ostream &operator<<(ostream &s, pair<T, TT> t) { return s << ( ... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, sum = 0, k; cin >> n; char a[n]; cin >> a; for (int i = 0; i < n; i++) { k = int(a[i]); if (k % 2 == 0) { sum = sum + (i + 1); } } cout << sum; return 0; } |
#include <bits/stdc++.h> using namespace std; int arr[200005]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); int now = arr[0], cnt = 1; set<int> sup; stack<int> sdown; sup.insert(now); ... |
#include <bits/stdc++.h> using namespace std; struct __timestamper {}; int main() { int n; scanf( %d , &n); vector<int> l(n), r(n); for (int i = 0; i < n; i++) scanf( %d%d , &l[i], &r[i]); double ans = 0; for (int i = 1; i <= 10000; i++) { double prob[3]; prob[0] = 1; pro... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007LL; const int lmt = 1005; const long long inf = 1LL << 62; long long dp[lmt][lmt], a[lmt], req[lmt]; int n; long long solve(int idx, int left) { if (idx > n) return 0; if (dp[idx][left] != -1) return dp[idx][left]; l... |
#include <bits/stdc++.h> using namespace std; mt19937 rng( (unsigned int)chrono::steady_clock::now().time_since_epoch().count()); const int MAGIC = 239; const int N = 100010; vector<int> g[N]; bool in_st[N]; bool was[N]; bool dfs(int v) { was[v] = true; in_st[v] = true; for (int u : g[... |
#include <bits/stdc++.h> using namespace std; int gems[30050], maxi = INT_MIN; int dp[30005][600], kood; int solve(int i, int d) { int change = 300 + (d - kood); if (i > maxi) return 0; if (dp[i][change] != -1) return dp[i][change]; if (d == 1) { return dp[i][change] = gem... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; struct node { int a, b, id; bool operator<(const node& tem) const { return a > tem.a; } } vec[maxn]; bool used[maxn]; int n; int main() { scanf( %d , &n); for (int i = 1; i <= n; i++) scanf( %d , &vec[i].a); for (... |
#include <bits/stdc++.h> const int long long N = 10e8 + 7; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int arr[n]; vector<int> odd, even; for (int i = 0; i < n; i+... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; set<int> st; set<int>::iterator it; int n, m, used[N], hmm[N]; vector<int> graph[N], vec, b[N]; void lmao() { if (st.size() == 0) { return; } it = st.begin(); int u = *it; for (int i = 0; i < graph[u].size(); i+... |
#include <bits/stdc++.h> using namespace std; void sort_vec(vector<int> x, vector<int> b, int cnt) { int index; int max = 101; for (; cnt > 0; cnt--) { for (int j = 0; j < x.size(); j++) { if (x[j] < max) { index = j; max = x[j]; } } cout << x[index]... |
#include <bits/stdc++.h> using namespace std; const int maxn = 410; int cl[maxn * maxn]; int po[maxn * maxn]; int pre[maxn * maxn * 2]; int cnt[maxn * maxn * 2]; short cc[maxn * maxn * 2]; short F[maxn][maxn]; short g[maxn][maxn]; int a[maxn][maxn]; int b[maxn][maxn]; int pos[maxn][maxn]; int ... |
#include <bits/stdc++.h> using namespace std; int N; int mov[2][4] = {{-1, 0, 0, 1}, {0, -1, 1, 0}}; long long X[31], Y[31]; vector<int> graph[31]; void BuildTree(int node, int parent, int dir, long long dist) { if (graph[node].size() > 4) { cout << NO n ; exit(0); } for (int i = 0,... |
#include <bits/stdc++.h> using namespace std; pair<int, int> a[2 * (int)(1e5 + 51)], b[2 * (int)(1e5 + 51)]; bool visited[2 * (int)(1e5 + 51)]; vector<int> g[2 * (int)(1e5 + 51)]; void dfs(int x) { visited[x] = 1; for (auto v : g[x]) { if (!visited[v]) dfs(v); } } int main() { ios_ba... |
#include <bits/stdc++.h> using namespace std; long long po(long long x, long long y) { if (y == 0) return 1; else return x * po(x, y - 1); } vector<long long> a[7], b[7]; void solve(long long l, long long r, long long d) { if (l == r) return; long long m = (l + r) >> 1; for (lo... |
#include <bits/stdc++.h> using namespace std; int main() { long long x, y, n; cin >> x >> y >> n; long long a = -1, b = -1; for (int i = 1; i <= n; i++) { int t = x * i * 1.0 / y; if (abs(t * y - i * x) > abs((t + 1) * y - i * x)) t++; if (a == -1 || (abs(t * y - i * x) * b < abs(a... |
#include <bits/stdc++.h> using namespace std; long long n, i; void input() { cin >> n; return; } void output() { return; } void lolicon() { n = abs(n); while (!(i * (i + 1) / 2 >= n && (i * (i + 1) / 2 - n) % 2 == 0)) i++; cout << i; } int main() { ios_base::sync_with_stdio(false... |
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; const long long INF = LLONG_MAX / 2; const long long N = 1e4; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long n, k; cin >> n >> k... |
#include <bits/stdc++.h> using namespace std; long double PI = acosl(-1); bool compare_int(int a, int b) { return (a > b); } bool compare_string(string a, string b) { return a.size() < b.size(); } bool compare_pair(const pair<int, int> &a, const pair<int, int> &b) { if (a.second == b.second) return ... |
#include <bits/stdc++.h> using namespace std; int n, n1, n2, mn, mx; int A[100001]; int main() { cin >> n >> n1 >> n2; for (int i = 0; i < n; i++) { cin >> A[i]; } sort(A, A + n); mn = min(n1, n2); mx = max(n1, n2); double s1 = 0; double s2 = 0; int nr = 0; int k = ... |
#include <bits/stdc++.h> using namespace std; double res; long long n, m, k, i, j, x = 1, y, t, a[1000001], b[1000001]; int main() { cin >> n; for (i = 1; i <= n; i++) { cin >> t; if (t == 1) { cin >> k >> m; a[k] += m; y += k * m; printf( %.10f , (double)y / ... |
#include <bits/stdc++.h> using namespace std; const signed long long int INF = 1e9; int main() { int n; cin >> n; vector<signed long long int> a(n); for (int i(0); i < n; i++) { scanf( %lld , &a[i]); } int s, f; scanf( %d %d , &s, &f); vector<signed long long int> d(n + 1); ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n; if (n % 2 == 0) { x = n / 2; cout << x * (x + 1); } else { x = (n + 1) / 2; cout << (x - 1) * x + x; } return 0; } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.