solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
struct DisjointSets {
int N;
vector<int> representatives;
DisjointSets(const int N) : N(N), representatives(N) {
iota(begin(representatives), end(representatives), 0);
}
int find(const int n) {
if (representatives[n] != n) representatives[n] = find(represe... | 17 |
#include <bits/stdc++.h>
long long mod = 1e9 + 7;
using namespace std;
void solve() {
int n;
cin >> n;
int a[n][3];
for (int i = 0; i < n; i++) {
cin >> a[i][0];
}
for (int i = 0; i < n; i++) {
cin >> a[i][1];
}
for (int i = 0; i < n; i++) {
cin >> a[i][2];
}
int p[n];
p[0] = a[0][0];
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int dr[] = {2, 2, -2, -2, 1, 1, -1, -1};
const int dc[] = {2, -2, 2, -2, 1, -1, -1, 1};
const double eps = 1e-9;
const int INF = 0x7FFFFFFF;
const long long INFLL = 0x7FFFFFFFFFFFFFFFLL;
const double pi = acos(-1);
template <class T>
T take(queue<T> &O) {
T tmp = O.... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, t;
char s1[100005], s2[100005], s3[100005];
int diff;
int currdiff;
void MakeMin() {
for (int i = 0; i <= n - 1; i++) {
if (currdiff == diff - 1 && diff % 2 == 1) {
if (s1[i] != 'a' && s2[i] != 'a') s3[i] = 'a';
if (s1[i] != 'b' && s2[i] != 'b') s3[... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int d, f;
cin >> d >> f;
if ((d / f) % 2 == 0)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
while (q--) {
long long x;
cin >> x;
if (x < 15) {
cout << "NO\n";
continue;
}
x %= 14;
if (1 <= x && x <= 6)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, K, Q, tot, col;
int a[13][N], id[13];
bitset<5000> b[N];
bool cmp(int x, int y) { return a[x][col] < a[y][col]; }
int main() {
cin >> n >> K >> Q;
for (int i = 1; i <= K; i++) {
for (int j = 1; j <= n; j++) {
scanf("%d", &a[i][j]... | 21 |
#include <bits/stdc++.h>
using namespace std;
int cnt[15];
int main() {
cout.sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
cnt[x]++;
}
if (cnt[0] == 0)
cout << -1 << endl;
else {
int sum = 0;
for (int i = 0; i < 10; i++) sum +... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 3;
int a[N], t[N], x[N];
struct BIT {
map<int, int> bit[N];
BIT() {}
void update(int pos, int val, int val2) {
while (pos < N) {
bit[pos][val] += val2;
pos += pos & -pos;
}
}
int query(int pos, int val) {
int ans = 0;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl '\n'
#define all(v) (v).begin(), (v).end()
template<class A, class B> ostream& operator<<(ostream& os, const pair<A,B>& p) {
return os << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream& os, T&& x) -... | 9 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:36777216")
using namespace std;
const double PI = acos(-1.0);
const long long INF = 1000 * 1000 * 1000 + 7;
const long long LINF = INF * (long long)INF;
const int MOD = 1000 * 1000 * 1000 + 7;
const int MAX = 200 * 1000 + 47;
const int MIN = 57;
double T[MAX];
do... | 16 |
#include <bits/stdc++.h>
using namespace std;
int top(int a, int b) {
if (a % b == 0)
return a / b;
else
return a / b + 1;
}
long long mod(long long x) {
if (x >= 1000000007)
return x - 1000000007;
else
return x;
}
long long binpow(long long a, long long n) {
if (n == 0) return 1;
if (n % 2 ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, sum = 0, sum1 = 0, flag;
cin >> a;
vector<int> v;
for (int i = 0; i < a; i++) {
cin >> b;
v.push_back(b);
}
sort(v.begin(), v.end());
for (int i = 0; i < v.size(); i++) {
if (v[i] != -1) {
sum1++;
}
for (int j =... | 0 |
#include <bits/stdc++.h>
long long ppl[101];
int main() {
long long n, m, i;
scanf("%lld %lld", &n, &m);
for (i = 0; i < m; ++i) {
long long sender, reciever, amt;
scanf("%lld %lld %lld", &sender, &reciever, &amt);
ppl[sender] -= amt;
ppl[reciever] += amt;
}
long long total = 0;
for (i = 0; ... | 5 |
#include <bits/stdc++.h>
int main() {
int n;
int FOO = 0, BAR = 0, BAZ = 0, QUZ = 1;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
FOO += x, BAR++;
if (FOO * QUZ > BAZ * BAR) BAZ = FOO, QUZ = BAR;
}
printf("%.6lf\n", 1.0000 * BAZ / QUZ);
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[100010];
long long tedg[100010], n, m, q, x, y;
int main() {
cin >> n >> m;
for (long long i = 1; i <= m; i++) {
cin >> x >> y;
if (x > y) swap(x, y);
adj[x].push_back(y);
tedg[x]++;
tedg[y]++;
}
long long ans = 0;
for (lo... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int U = 1000000, T[6] = {1, 10, 100, 1000, 10000, 100000};
int n;
long long a[1000005], S[1000005], E[1000005], ans;
const int mo = 1e9 + 7;
int gi() {
int w = 0;
char c = getchar();
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') w = w ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long n;
cin >> n;
long long ar[n];
vector<long long> br;
for (long i = 0; i < n; i++) {
cin >> ar[i];
br.push_back(ar[i]);
}
sort(br.begin(), br.end());
set<long long> a;
a.insert(br.begin(), br.end());
if (a.size() != br.size()) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int dp[2][10001];
signed main() {
cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<vector<int>> a(n);
for (int i = 0; i < n; i++) {
int k;
cin >> k;
a[i].assign(k, 0);
for (int j = 0; j < k; j++) cin >> a[i][j]... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
long long n;
cin >> n;
vector<long long> arr;
map<long long, long long> mapa;
for (int i = 0; i < n; i++) {
long long a;
cin >> a;
mapa[a]++;
}
for (auto p : mapa) {
arr.push_back(p.second);
}
sor... | 10 |
#include <bits/stdc++.h>
using namespace std;
char g_sz[100010];
int g_cnt[4];
int main() {
int i, j, n, m;
scanf("%s", g_sz);
int len = strlen(g_sz);
for (i = 0; g_sz[i]; i++) {
if (g_sz[i] == '0')
g_cnt[0]++;
else if (g_sz[i] == '1')
g_cnt[1]++;
else
g_cnt[2]++;
}
int xqu = (... | 11 |
#include <bits/stdc++.h>
using namespace std;
int gi() {
int a;
scanf("%d", &a);
return a;
}
long long gli() {
long long a;
scanf("%I64d", &a);
return a;
}
int f[100];
int main() {
int p = gi();
int n = gi();
memset(f, 0, sizeof(f));
for (int i = 0; i < n; i++) f[gi() - 1]++;
int l = 1, r = n / p;... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long mod = 998244353;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 1e6 + 5;
const int INF = 0;
template <class T>
class SegmentTree {
public:
T t[4 * maxn];
void update(int p, T x, int ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
long long a, b, c, count1, count2, diff, i, pdiff;
cin >> t;
while (t--) {
count1 = count2 = -1;
cin >> a >> b >> c;
i = 1;
if (a < c) count1 = 1;
pdiff = LLONG_MAX;
if (c < a * b) ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000009;
int rd() {
char c = getchar();
int t = 0, f = 1;
while (!isdigit(c)) f = (c == '-') ? -1 : 1, c = getchar();
while (isdigit(c)) t = t * 10 + c - 48, c = getchar();
return t * f;
}
void wt(int x) {
if (x < 0)
putchar('-'), wt(-x);
... | 7 |
#include <bits/stdc++.h>
long long a[60];
void whatever(void) {
int i = 0;
long long x = 2;
a[i++] = 1;
for (; i < 60; i++) {
x *= 2;
a[i] = x - 1;
}
}
long long f(long long base, long long l, long long r) {
int j;
for (j = 0; r >= base + a[j]; j++)
;
if (base + a[--j] >= l) return (base + a... | 9 |
#include <bits/stdc++.h>
using namespace std;
bool a[1005][1005];
int main() {
int i, j, n, b;
scanf("%d", &n);
if (n == 4) return puts("-1"), 0;
b = n - (~n & 1);
for (i = 0; i < b; i++)
for (j = 1; j + j < b; j++) a[i][(i + j) % b] = 1;
if (~n & 1)
for (i = 0; i < n - 1; i++)
if (i & 1)
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int main() {
map<int, int> mp;
int t;
cin >> t;
while (t--) {
int n;
mp.clear();
cin >> n;
int ans = inf;
for (int i = 0; i < n; i++) {
int val;
cin >> val;
if (mp.count(val) != 0) {
ans = min... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int a, b, m = -1, c, d;
cin >> a >> b;
for (int i = 0; i < a; i++) {
cin >> c >> d;
if (c < b && d > 0) {
if ((100 - d) % 100 > m) m = (100 - d) % 100;
} else if (c <= b && d == 0 && m < 0) {
m = 0;
}
}
if (m >= 0)
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100;
const int MAXL = 3000;
const int MOD = 1e9 + 7;
int DP[2 * MAXN + 1][MAXL + 1];
vector<pair<int, pair<int, int>>> types;
int N, L, a, b;
int dp(int n, int l) {
if (l < 0) return 0;
if (DP[n][l] != -1) return DP[n][l];
int ans = 0;
for (int i = ... | 10 |
#include <bits/stdc++.h>
const int N = 200054, M = N * 2;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
int n, E = 0;
int ord[N];
int p[N], fc[N], nc[N];
int w[N], c[N], fl[N];
long long sum[N];
inline void down(int &x, const int y) { x > y ? x = y : 0; }
inline int min(const int x, const int y) { return x < y ? x : y; }... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 102;
int a[N], b[N], mat[N][N];
int main() {
int n, m, xor_row = 0, xor_col = 0;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d", a + i);
xor_row ^= a[i];
}
for (int i = 0; i < m; i++) {
scanf("%d", b + i);
xor_col ^= ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int nMax = 200010;
const long long inf = 1e18;
int n;
long long k, x;
vector<long long> a(nMax);
int minusCnt() {
int cnt = 0;
for (int i = 1; i <= n; i++)
if (a[i] < 0) cnt++;
return cnt;
}
bool chkminus() {
if (minusCnt() % 2) return true;
for (int i =... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int a[30], n, sum[30][1002], ok[1002][1002];
char s[1002];
long long dp[1002];
int l[1002], t[1002];
int main() {
cin >> n;
scanf("%s", s + 1);
for (int i = 1; i <= 26; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 255;
char maz[N][N];
int n, m, p, Q;
long long ans[N][N];
long long nowval[N][N];
int vis[N][N];
const int dir[] = {1, 0, -1, 0, 0, 1, 0, -1};
void bfs(int i, int j, int cnt) {
queue<pair<int, int> > q;
q.push(pair<int, int>(i, j));
vis[i][j] = cnt;
an... | 11 |
#include <bits/stdc++.h>
const long long MOD = 1e9 + 7, INF = 1e18 + 1;
using namespace std;
long long n, m, banned[200001], p[200001], len[200001], p_m;
long long last[200001], u[200001], ph[200001];
vector<long long> fact[200010];
long long gcd(long long a, long long b) {
if (!b) return a;
return gcd(b, a % b);
}... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
char S[maxn][maxn];
char Ts[maxn][maxn];
static int n, m;
static bool use[5];
void Ck(char ch) {
if (!(ch >= 'a' && ch <= 'd')) return;
use[ch - 'a'] = true;
}
bool Chk() {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
me... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 200005;
long long n;
long long a[N];
long long ans;
long long ch[30 * N][2];
long long cnt = 1;
void insert(long long ind, long long val, long long d) {
if (d < 0) return;
bool v = val & (1 << d);
if (!ch[ind][v]) {
ch[ind][v] = cnt;
cnt++;... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int DIM = 155;
int dp[DIM][DIM][DIM], cst[DIM];
int bst[DIM][DIM], ful[DIM][DIM];
char str[DIM];
int main(void) {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> cst[i];
if (cst[i] == -1) cst[i] = -0x3f3f3f3f;
}
cin >> (str + 1);
memset(dp, ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int a[2005], pre[2005], lst[2005], dp[2005][2];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
for (int i = 1; i <= n; ++i) {
pre[i] = pre[i - 1];
if (a[i] == 1) ++pre[i];
}
for (int i = n; i; --i) {
lst[i] = ls... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
const int M = 1505;
struct line {
int A, B, C;
line() {}
line(int _A, int _B, int _C) : A(_A), B(_B), C(_C) {}
bool operator<(const line& t) const {
if (A != t.A) return A < t.A;
if (B != t.B) return B < t.B;
return C < t.C;
}
};
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
map<int, int> mp;
int lower = 0, upper = 1;
while (t--) {
char ch;
int id;
cin >> ch >> id;
if (ch == 'L') {
mp[id] = lower;
lower--;
} else if (ch == 'R') {
mp[id] = upper;
upper++;
} e... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1010000;
const int maxM = maxN << 1;
const int inf = 2147483647;
int n;
int edgecnt = 0, Head[maxN], Next[maxM], V[maxM];
int MxD[maxN], Hson[maxN], dfncnt, dfn[maxN], Fa[maxN];
int F[maxN], Ans[maxN];
void Add_Edge(int u, int v);
void dfs1(int u);
void dfs... | 15 |
#include <bits/stdc++.h>
using namespace std;
int A[(int)2e5 + 2];
vector<int> adj[(int)2e5 + 2];
int parent[(int)2e5 + 2];
int val[(int)2e5 + 2] = {0};
void rec(int v) {
int res = 2 * A[v] - 1;
for (int u : adj[v]) {
if (u == parent[v]) continue;
parent[u] = v;
rec(u);
res += max(0, val[u]);
}
... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1000000007;
long long int powe(long long int a, long long int b) {
long long int x = 1, y = a;
while (b > 0) {
if (b % 2 == 1) {
x = (x * y);
x %= MOD;
}
y = (y * y);
y %= MOD;
b /= 2;
}
return x;
}
long long int I... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
int a[n];
set<int>::iterator itr;
set<int> s;
for (int i = 0; i <= n - 1; i++) {
cin >> a[i];
s.insert(a[i]);
}
int sum = s.size();
if (sum > k)
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, ans = 0, s, k;
cin >> n >> m;
vector<int> pos(100000, -1);
vector<int> a(n), b(m), t;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
vector<vector<int> > now;
for (int i = 0; i < n; i++) {
for (in... | 13 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 1e5 + 10;
int n, m, k, s[maxn];
bool relaxed[maxn];
ll dp[maxn], y[maxn], cnt[maxn];
vector<pair<int, ll>> adj[maxn];
set<pair<int, ll>> ms;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
memset(dp, 63, sizeof ... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long nod(long long a, long long b) { return b ? nod(b, a % b) : a; }
int main() {
long long n, m, x, y, a, b;
cin >> n >> m >> x >> y >> a >> b;
long long q = nod(a, b);
a /= q;
b /= q;
long long len = n / a, width = m / b;
long long k = min(len, width);
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const int mod = 998244353;
int n, m;
int a[maxn];
int nl[1005], nr[1005];
vector<int> vec;
long long f[1005][1005];
struct ex {
int l, r;
};
ex p[1005];
long long dfs(int l, int r) {
int i, j;
int x = 0, y;
long long L = 0, R = 0;
if (f[l... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
long long int ans = 0;
for (int i = 0; i < a; i++) {
long long int b;
long long int c;
long long int j = 0;
cin >> b >> c;
long long int day = b;
while (true) {
if (day > ans) {
ans = day;
b... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int c, x, y, z, a, b;
cin >> x >> y >> z;
a = (x + y) / z;
cout << a << " ";
c = x / z;
b = y / z;
x -= c * z;
y -= b * z;
if (x < y && (a - c - b) * z - y >= 0) {
cout << (a -... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
const int dir_x[4][3] = {{1, 0, 1}, {0, -1, -1}, {-1, -1, 0}, {1, 1, 0}};
const int dir_y[4][3] = {{0, 1, 1}, {1, 0, 1}, {0, -1, -1}, {0, -1, -1}};
char mat[maxn][maxn];
int n, m;
void input() {
for (int i = 0; i < n; i++) puts(mat[i]);
}
void bfs()... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int base = 1000000000;
const int base_digits = 9;
struct bigint {
vector<int> z;
int sign;
bigint() : sign(1) {}
bigint(long long v) { *this = v; }
bigint(const string &s) { read(s); }
void operator=(const bigint &v) {
sign = v.sign;
z = v.z;
}
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
map<int, vector<int> > roads;
bool volunters[200001];
int visited[200001];
int s, t;
const int INF = 1000000000;
bool reachable(int q) {
for (int i = 0; i <= n; ++i) visited[i] = INF;
queue<int> Q;
Q.push(s);
visited[s] = 0;
while (!Q.empty()) {
i... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
std::istream& operator>>(std::istream& i, pair<T, U>& p) {
i >> p.first >> p.second;
return i;
}
template <typename T>
std::istream& operator>>(std::istream& i, vector<T>& t) {
for (auto& v : t) {
i >> v;
}
return i;
}
templat... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long qpow(long long a, long long n) {
long long r = 1 % P;
for (a %= P; n; a = a * a % P, n >>= 1)
if (n & 1) r = r * a % P;
return r;
}
long long inv(long long x... | 6 |
#include <bits/stdc++.h>
long long int powermod(long long int _a, long long int _b) {
long long int _r = 1;
while (_b) {
if (_b % 2 == 1) _r = (_r * _a);
_b /= 2;
_a = (_a * _a);
}
return _r;
}
using namespace std;
void scan(int& x);
struct node {
node* next[2];
} * root;
int flag = 1;
node* creat... | 10 |
#include <bits/stdc++.h>
int arr[1009][1009];
bool isSafe(int arr[1009][1009], int r, int c, int n, int m) {
int xpos[8] = {-1, 1, 0, 0, 1, -1, -1, 1};
int ypos[8] = {0, 0, 1, -1, 1, 1, -1, -1};
if (r - 1 >= 1 && c - 1 >= 1 && arr[r - 1][c] == 1 &&
arr[r - 1][c - 1] == 1 && arr[r][c - 1] == 1)
return fa... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, a, b;
cin >> n >> m >> a >> b;
int st = a / m + (a % m != 0);
int ed = b / m + (b % m != 0);
if (m == 1) {
cout << 1;
return 0;
}
if (b == n) {
if (a % m == 1 || st == ed)
cout << 1;
else
cout << 2;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
long long M = 1e9 + 9;
map<pair<long long, long long>, long long> mp;
long long cnt[N];
long long pw(long long a, long long b) {
if (b == 0) return 1;
long long t = pw(a, b / 2);
t = (t * t) % M;
if (b % 2) t = (t * a) % M;
return t;
}
long ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, r1, r2, r3, d;
int a[1000010];
long long b[1000010], f[1000010];
int main() {
scanf("%d%d%d%d%d", &n, &r1, &r2, &r3, &d);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}
long long ans = 1LL << 62;
for (int i = 1; i <= n; ++i) {
b[i] = min((long... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005, P = 1000000007;
using ll = long long;
struct Edge {
int v, x, c;
};
vector<Edge> v[N];
int n, sz[N], cc, rt, mn, idx;
ll qpow(ll a, ll b) {
ll ret = 1;
while (b) {
if (b & 1) ret = ret * a % P;
a = a * a % P;
b >>= 1;
}
return ret... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000 + 5;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long la, ra, ta, lb, rb, tb;
long long cal(long long la, long long ra, long long lb, long long rb) {
long long mn = max(la, lb), mx = min(ra, rb);
return max(0ll... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 105;
int parent[maxN], r[maxN];
void build(int n) {
for (int i = 0; i <= n; i++) {
parent[i] = i;
r[i] = 1;
}
}
int find(int n) {
if (parent[n] == n) return n;
return parent[n] = find(parent[n]);
}
int disjoint(int a, int b) {
int v = find... | 9 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(239);
struct T {
long long ch, zn;
int ind;
long long ch2, zn2;
T() : ch(0), zn(0), ind(0), ch2(0), zn2(0) {}
T(long long ch, long long zn, int ind, long long ch2, long long zn2)
: ch(ch), zn(zn), ind(ind), ch2(ch2), zn2(zn2) {}
};
bool kek(long ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int v[4];
int main() {
for (int i = 0; i < 4; ++i) scanf("%d", v + i);
int mn = min(v[2], v[3]);
int mx = max(v[2], v[3]);
int c = mx;
int b = max(v[1], 2 * c + 1);
int a = max(v[0], b + 1);
if (mx <= 2 * mn && v[1] * 2 >= b && v[0] * 2 >= a) {
printf("%d\... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct ST {
struct node {
T sum = 0, lzy = 0;
};
vector<node> t;
ST(int n) : t(vector<node>(n << 2)) {}
void push(int v, int l, int r) {
t[v].sum += t[v].lzy * (r - l + 1);
if (l ^ r) {
t[v * 2].lzy += t[v].lzy;
t[v * ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, an = 0;
cin >> n >> m;
long long a[n + 5], b[n + 5], c[n + 5], d[n + 5], e[n + 5];
for (long long i = 0; i < n; i++) {
cin >> a[i];
d[i] = a[i];
}
sort(d, d + n);
for (long long i = 0; i < n; i++) {
cin >> b[i];
}
w... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long arr[5];
memset(arr, 0, sizeof(arr));
long long brr[5];
memset(brr, 0, sizeof(brr));
long long x, y;
cin >> x >> y;
for (int i = 1; i <= x; i++) {
arr[i % 5]++;
}
for (in... | 3 |
#include <bits/stdc++.h>
using namespace std;
int numx[1000000], numy[1000000], x[1000000], y[1000000];
struct node {
int l, r, pos;
} a[1000000], b[1000000];
int laze[1000000];
int num1[1000000], laze1[1000000];
bool cmp(node a, node b) { return a.l < b.l || (a.l == b.l && a.r < b.r); }
void pushupy(int rt) { numy[r... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 10, MOD = 998244353;
const int OO = 1e6;
long long a, b, c;
long long val = -OO;
bool can(long long number, long long day) {
val = -OO;
long long weeks = number / 7;
long long days = number % 7;
long long aa = a, bb = b, cc = c;
aa -= 3 * weeks... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<int> g;
vector<pair<int, int> > g1;
int main() {
ios_base::sync_with_stdio(false);
int l, r, x;
cin >> l >> r >> x;
bool flag = 0;
int y;
while (1) {
if (x == 0) break;
if (l > r) {
r++;
} else if (r > l) {
l++;
} else {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
if (fopen("input.txt", "r")) {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
int n;
cin >> n;
string s;
cin >> s;
for (int i = n; i >= 1; i--) s[i] = s[i - 1];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
if (k * 3 > n) {
cout << -1;
return 0;
}
int s = n / k;
for (int i = 1; i <= k; i++) {
for (int j = 1; j < s; j++) {
printf("%d ", i);
}
}
for (int i = 1; i <= k; i++) {
cout << i << " ";
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long ara[200005], dif[200005];
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n;
while (cin >> n) {
long long p = 0;
for (long long i = 1; i <= n; i++) {
cin >> ara[i];
if (i > 1) {
dif[i] = a... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, second;
cin >> n >> second;
vector<int> a(n);
long long mini = numeric_limits<int>::max();
long long sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
mini = min(mini, (long... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long infl = 2e18;
const long long infi = 1e9;
const long long mod = 1000000007;
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
auto clk = clock();
long long rng(long long lim) {
uniform_int_distribution<long long> uid(0, lim - 1)... | 17 |
#include <bits/stdc++.h>
using namespace std;
struct point {
int next, to, w;
} ar[290];
struct pi {
int x, y;
inline void print() { printf("%d %d\n", x, y); }
};
vector<pi> a7[10][10];
bool is[290];
char s[10];
int base[10], n, n1, a[10][10], head[290], dep[290], a1[10], a2[10], a3[10][10],
art, tot, ps, pt,... | 24 |
#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
const int N = 1 << 18;
const int M = 125010;
struct base {
double x, y;
base() : x(0), y(0) {}
base(const double &_x, const double &_y) : x(_x), y(_y) {}
};
inline base operator+(const base &a, const base &b) {
return base(a.x + b.x, a.y + b.y)... | 14 |
#include <bits/stdc++.h>
using namespace std;
int x[4];
char c[2];
int s;
int main() {
for (int i = 1; i <= 3; i++) {
cin >> c;
if (c[0] == 'C' && c[1] != '#')
x[i] = 1;
else if (c[0] == 'C' && c[1] == '#')
x[i] = 2;
else if (c[0] == 'D' && c[1] != '#')
x[i] = 3;
else if (c[0] ==... | 4 |
#include <bits/stdc++.h>
char q1[505][505], q2[505][3];
int dp[505][30][30];
int num[505][30][30];
int aaa[505][30][30], bbb[505][30][30];
int n, j, k, i, l, m, aa, bb;
int main() {
scanf("%d %d", &n, &m);
getchar();
for (i = 0; i < n; i++) {
gets(q1[i]);
}
for (i = 0; i < n; i++) {
for (j = 0; j < 26... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1001;
int main() {
double v1, v2, a, p, c, x{}, ans{};
cin >> v2 >> v1 >> a >> p >> c;
a *= v2;
if (v1 - v2 > 0) {
x = a + v2 * a / (v1 - v2);
while (x < c) {
ans++;
a = x + (x / v1 + p) * v2;
x = a + v2 * a / (v1 - v2);
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int ternary(int lo, int hi) {
while (lo < hi) {
int mi = (lo + hi) / 2;
cout << 1 << " " << mi << " " << mi + 1 << endl;
fflush(stdout);
string s;
cin >> s;
if (s == "NIE") {
lo = mi + 1;
} else {
hi = mi;
}
}
return lo;
}
i... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long dp[4005][4005];
long long init(long long n, long long r) {
if (n < r) {
if (n < 0) {
return 0;
}
if (r < 0) {
return 0;
}
return dp[n][r] = 0;
}
if (r == 0) {
return dp[n][r] = 1;
}
if (r == 1) {
return dp[n][r] = ... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long ans[500010], vis[500010];
struct tp {
long long min, idx;
} tree[500010 * 3];
tp combine(tp a, tp b) { return a.min < b.min ? a : b; }
long long arr[500010];
void build(long long at, long long left, long long right) {
if (left == right) {
tree[at].min = ar... | 11 |
#include <bits/stdc++.h>
using namespace std;
clock_t begtime = clock();
unsigned long long int a[32];
void init() {
long long int k = 0;
for (long long int i = 2; k < 31; i = i << 1) {
a[k] = i * (i - 1) / 2;
k++;
}
}
void solve() {
long long int x;
cin >> x;
long long int ans = 0, k = 0;
while (... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
string a, b;
cin >> a >> b;
int n = a.size();
int m = b.size();
char f = a[0];
char h = b[0];
string s = "";
s = s + a[0];
s = s + b[0];
for (int i = 1; i < n; i++) {
string x = "";
x = x + a[0];
... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
double dis(long long x1, long long y1, long long x2, long long y2) {
return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
void solve() {
int a[2], b[2], t[... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5 + 20;
long long p(long long n) {
for (long long i = 2; i * i <= n; ++i) {
if (n % i == 0) return i;
}
return n;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
long long cnt = 0;
whil... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, k, a, m;
set<pair<long long, long long> > xs;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k >> a >> m;
int ships = (n - 1 + 2) / (a + 1);
xs.insert(make_pair(n, 1));
for (long long i = 0; i < m; i++) {
int x;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int lowbit(int x) { return x & (-x); }
int main() {
int n, x;
cin >> n >> x;
int res[100005];
if (n == 2 && x == 0)
cout << "NO" << endl;
else {
cout << "YES" << endl;
if (n == 1)
cout << x << endl;
else if (n == 2)
cout << "0 " << x <<... | 11 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long int dp[2][60];
int main() {
unsigned long long int s, x;
cin >> s >> x;
dp[0][0] = 1;
unsigned long long int ONE = 1;
for (int i = 1; i < 50; i++) {
if ((x & (ONE << (i - 1))) == 0) {
if ((s & (ONE << (i - 1))) == 0) {
dp[0][i]... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, K = 2005;
int n, m, k, x[N], y[N], offer[N];
long long a[N], dp[K];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> k;
for (int i = (1); i < (n + 1); i++) cin >> a[i];
for (int i = (0); i < (m); i++) {
cin >> x[i] ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
double PI = 4 * atan(1);
long long L, R, ans = 0;
vector<int> L1(19), R1(19);
int oc[10], oc1[10], tmp[10];
bool test1(int ind) {
for (int i = 0; i < 10; i++) tmp[i] = oc1[i];
int c = 9;
for (int i = ind; i < 19; i++) {
while (tmp[c] ==... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 100;
const long double pi = acos(-1.0);
inline long long read() {
long long x = 0, f = 1;
char ch = getchar();
while ((ch < '0') || (ch > '9')) {
if (ch == '-') f = -1;
ch = getchar();
}
while ((ch >= '0') && (ch <= '9')) {
x = x... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 101;
int dp[maxn][maxn][30];
int n, m;
struct edge {
int t, w;
};
vector<edge> vec[maxn];
int gc(char x) { return x - 'a' + 1; }
int sg(int a, int b, int w) {
if (dp[a][b][w] != -1) return dp[a][b][w];
int flag = 0;
int siz = vec[a].size();
for (i... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long MX = (1 << 20);
struct node {
node *child[2];
long long cnt;
node() {
memset(child, 0, sizeof(child));
cnt = 0;
}
} * head;
string convert_(long long x) {
string ret;
while (x > 0) {
ret.push_back((x % 2) + '0');
x /= 2;
}
whi... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long a[100005], b[100005];
int main() {
long long i, j, k;
long long n, m;
cin >> n >> k;
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < n; i++) {
cin >> b[i];
}
long long high, low, mid, ans;
high = 2000000005, low = 0, ans = 0;
l... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
vector<pair<pair<long long int, long long int>, long long int>> v;
long long int i, j, q, r, t;
long long int n;
i = 0;
cin >> n;
long long int m = n;
long long int a[n + 5];
while (... | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.