solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 55, P = 998244353;
int n, T, x[maxn], y[maxn], tag[maxn << 1];
vector<pair<int, int>> V[maxn << 1];
int qp(int x, int y) {
int z = 1;
for (; y; y >>= 1, x = 1LL * x * x % P) {
if (y & 1) z = 1LL * z * x % P;
}
return z;
}
int main() {
scanf("%... | 27 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
return x * x;
}
int f[110000][110], c[110000][110];
int a[110000];
int n, m;
inline void add(int &x, int y) { x = (x + y) % 1000000007; }
int main() {
int i, j, l, r, k;
for (i = 0; i < 110000; i++) {
c[i][0] = 1;
for (j = 1; j ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int modulo = 1000000007;
struct int128 {
unsigned long long high, low;
int128() { high = low = 0; }
void set(int x, bool y) {
if (x < 64) {
if (y)
low |= 1ULL << x;
else
low &= ~(1ULL << x);
} else {
x -= 64;
if (y... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int maxn = 1e5 + 1;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int n, m, cnt = 0, f = 1, F[maxn], A[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 0, a; i < m && cin >>... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 1;
const int sz = 707;
int a[maxn], d[sz][sz];
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int q;
cin >> q;
while (q--) {
int t, x, y;
cin >> t >> x >> y;
if (t == 1) {
a[x] += y;
for (int i = 1... | 13 |
#include <bits/stdc++.h>
const int MAXPOS = 21, MAXCNT = 5;
long long bit[MAXPOS], f[MAXPOS][MAXCNT];
long long dfs(int pos, int cnt, bool lim) {
if (pos == -1) return 1;
if (!lim and ~f[pos][cnt]) return f[pos][cnt];
long long ans = 0, hi = lim ? bit[pos] : 9;
for (int i = 0; i <= hi; i++) {
if (!i)
... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long N;
void solve() {
cin >> N;
long long arr[N];
set<int> s;
for (int i = 0; i < N; i++) {
cin >> arr[i];
s.insert(((i + arr[i]) % N + N) % N);
}
if (s.size() == N)
cout << "YES"
<< "\n";
else
cout << "NO"
<< "\n";
}
in... | 8 |
#include <bits/stdc++.h>
using namespace std;
int size[55], father[55];
int findroot(int x) {
int root;
for (root = x; father[root] != -1; root = father[root])
;
int i;
for (; father[x] != -1;) {
i = father[x];
father[x] = root;
x = i;
}
return root;
}
void u(int x, int y) {
int xx = findr... | 7 |
#include <bits/stdc++.h>
using namespace std;
int Ones(long long a) {
int res = 0;
long long k = 1;
for (int i = 0; i < 60; i++) {
if (a & k) res++;
k *= 2;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, m;
cin >> n >> m;
map<int,... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long t[444444], p[444444];
void push(long long v) {
if (p[v] == 0) return;
p[v] = 0;
p[v * 2] = 1;
p[v * 2 + 1] = 1;
t[v] = 0;
t[v * 2] = 0;
t[v * 2 + 1] = 0;
}
void mt(long long v, long long tl, long long tr, long long i, l... | 15 |
#include <bits/stdc++.h>
using namespace std;
char a[11][11];
int ch_hor(int x, int y) {
int cell = 0, t = 5;
int i = x, j = y;
while (t--) {
if (j >= 10) cell = 2;
if (a[i][j] == 'O') cell = 2;
if (a[i][j] == '.') cell++;
j++;
}
if (cell <= 1) return cell + 1;
cell = 0, t = 5;
i = x, j = ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 7;
int n, m, tot, top, num, cnt, ind;
bool instack[N * 10];
int sta[N * 10], head[N * 10], bl[N * 10], dfn[N * 10], low[N * 10],
nxt[N * 23], to[N * 23];
vector<int> ve[N], pre[N], suf[N], Pre[N], Suf[N];
struct Edge {
int u, v, c, w;
} e[N];
void ... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
bool check = false;
int n, s, hh = 0, mm = 0, h, m;
map<pair<int, int>, bool> mp;
cin >> n >> s;
while (n--) {
cin >> h >> m;
mp[{h, m}] = true;
}
while (!check) {
check = true;
h = hh;
m = mm;
for (int i = 0; i <= s && che... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> tree[100001];
vector<long long> ch2[100001];
vector<long long> vch2[100001];
vector<bool> vis(100001, 0);
vector<bool> v(100001, 0);
vector<int> parent(100001);
vector<int> p(100001);
vector<int> num(100001);
vector<int> l;
vector<int> r;
vector<double> ans;
vec... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long fa[200010], c[200010], n, m, ans;
struct Node {
int x, y, z;
} a[200010];
bool cmp1(const Node &s1, const Node &s2) { return s1.z > s2.z; }
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -f;... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char b[2][2];
char e[2][2];
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
cin >> b[i][j];
}
}
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
cin >> e[i][j];
}
}
string sb, se;
for (int i = 0... | 4 |
#include <bits/stdc++.h>
typedef long long ll ;
#define int ll
const int MAX=1e3+10;
const int modn=1e9+7;
const int INF=0x3f3f3f3f3f3f;
#define endl '\n'
#define cwk freopen("D:\\workplace\\CLion\\in.in","r",stdin),freopen("D:\\workplace\\CLion\\out.out","w",stdout)
using namespace std;
typedef pair<int, int> PII;... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
deque<int> cur[320];
int freq[320][N];
int n, q, Z, lastAns = 0, a[N], type, l, r, k;
void fix(int l, int r) {
if (l == r) return;
int myL = l / Z;
int myR = r / Z;
if (myL == myR) {
vector<int> tmp;
while (cur[myL].size()) {
tmp.... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int di, d, a, b;
cin >> di >> d >> a >> b;
long long int cp1, cp2;
long long int am1, am2;
am1 = am2 = 0;
if (di < d) {
am1 = (d - di) * a;
am2 = (di)*b;
di = d;
} else if (di % d != 0 && di > d) {
long long int x = (di) ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
vector<char> t;
int main(void) {
int n, ans1 = 0, ans2 = 0;
cin >> n;
string s1, s2;
cin >> s1 >> s2;
for (char ch : s2) t.push_back(ch);
sort(t.begin(), t.end());
for (auto ch : s1) {... | 5 |
#include <bits/stdc++.h>
using namespace std;
void read(int a = 0) {
freopen("in", "r", stdin);
if (a) freopen("out", "w", stdout);
}
struct dsu {
vector<int> p, rank, sum;
dsu(int n) {
p.assign(n, 0);
rank.assign(n, 0);
sum.assign(n, 1);
for (int i = 0; i < n; i++) p[i] = i;
}
int find_set(... | 9 |
#include <bits/stdc++.h>
//v.erase(unique(v.begin(),v.end()),v.end());
#define ff first
#define ss second
#define pb push_back
#define sz(v) (ll)v.size()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
typedef double ld;
typedef long long ll;
const ll N = 1e+5 + 100;
const ll INF = 1e+18;
const ll RT = 5;... | 12 |
#include <bits/stdc++.h>
using namespace std;
struct ModResidue {
constexpr static long long P = 998244353;
long long x;
ModResidue() = default;
ModResidue(long long _x) : x(_x % P) {}
};
ModResidue operator*(const ModResidue a, const ModResidue b) {
return a.x * b.x;
}
ModResidue& operator*=(ModResidue& a, c... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1002;
int i, j, d, x, y, s, a[4], tmp, f[N][1 << 12], n, st[N];
char s1[4][N];
vector<int> v[4];
inline void M(int &x, int y) {
if (y < x) x = y;
}
int main() {
scanf("%d", &n);
for (i = 0; i < 4; i++) scanf("%d", &a[i]);
for (i = 0; i < 4; i++) scanf(... | 14 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> compute_range(int x, pair<int, int> prev_range) {
int prev_l, prev_r;
tie(prev_l, prev_r) = prev_range;
int r = x + prev_r - 2;
if (x > prev_r) {
return make_pair(x - prev_r + 2, r);
} else if (x < prev_l) {
return make_pair(prev_l - x + 2, ... | 24 |
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).be... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 2e18;
int n, m, k;
char s[1005][1005];
int dx[5] = {0, 0, 1, -1};
int dy[5] = {1, -1, 0, 0};
long long dis[1005][1005];
queue<pair<int, int>> q;
bool valid(int x, int y) { return (1 <= x && x <= n && 1 <= y && y <= m); }
int main() {
scanf("%d%d%d", ... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long a = 0, b = getchar(), c = 1;
while (!isdigit(b)) c = b == '-' ? -1 : 1, b = getchar();
while (isdigit(b)) a = a * 10 + b - '0', b = getchar();
return a * c;
}
int n, m, ab, ac, ad, res, a[2005], b[2005], c[2005];
vector<int> e[2005], g[2... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 100010, MLT = 29221, MOD1 = 666013, MOD2 = 838751;
int N, M, K;
int p1[NMAX], p2[NMAX], s[NMAX];
char S[NMAX];
struct Node {
int h1, h2, lazy;
} T[4 * NMAX];
struct QueryRet {
int h1, h2, dim;
QueryRet(int h1, int h2, int dim) {
this->h1 = h1;
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, lg;
string S;
cin >> S;
lg = S.length();
for (i = 0; i < lg; i++) {
if (S[i] == 'H' || S[i] == 'Q' || S[i] == '9') {
cout << "YES";
return 0;
}
}
cout << "NO";
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long inf = 1e14;
long long s_inf = 3e6;
bool Q = false;
struct line {
long long x, k;
mutable long long bg, nd;
line() {
x = inf;
k = 0;
bg = -s_inf;
nd = s_inf;
}
line(long long x, long long k) : x(x), k(k), bg(-s_inf), nd(s_inf) {}
const l... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, w, h, g[maxn], p[maxn], t[maxn];
pair<int, int> ans[maxn];
vector<int> xv, yv, res, v[2 * maxn];
bool cmp(const int u, int v) {
if (g[u] != g[v])
return g[u] == 2;
else
return g[u] == 2 ? p[u] > p[v] : p[u] < p[v];
}
int main() ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300;
vector<vector<pair<long long, long long>>> g(MAXN), f(MAXN);
vector<long long> d(MAXN), ind(MAXN), used(MAXN);
long long n, m;
long long solve2(long long v, long long flow, long long p, long long ptr) {
used[v] = true;
if (v == n - 1) {
f[p][pt... | 15 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> has;
vector<pair<int, int> > vec;
void calc(int &n, int fg) {
scanf("%d", &n);
has.clear();
for (int i = 0, t; i < n; ++i) scanf("%d", &t), has[t]++;
for (__typeof(has.begin()) it = has.begin(); it != has.end(); ++it)
vec.push_back(make_pair(it->fi... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x1, y1, x2, y2, x3, y3;
cin >> n >> x2 >> y2 >> x1 >> y1 >> x3 >> y3;
if (x1 > x2 && x2 > x3 || x1 < x2 && x2 < x3 || y1 > y2 && y2 > y3 ||
y1 < y2 && y2 < y3) {
cout << "NO";
return 0;
}
cout << "YES";
return 0;
}
| 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 1e5 + 10;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<pair<int, int> > v(n);
for (int i = 0; i < n; i++) {
int m = 0, ret = 0;
cin >> m;
for (int i = 0; i < m; i++) {
i... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int sc = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') sc = sc * 10 + ch - '0', ch = getchar();
return sc * f;
}
const int MAXN = 500005;
int n, t... | 22 |
#include <bits/stdc++.h>
using namespace std;
int n, m, ans[110][110];
int main() {
ios_base::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
cin >> n >> m;
if (n == 1 and m == 2) {
cout << "3 4\n";
return 0;
} else if (n == 2 and m == 1) {
cout << "3\n4\n";
return 0;
}
int a = 2 * m - 4, b... | 16 |
#include <bits/stdc++.h>
int main() {
char a[100000], c;
int i;
i = 0;
int d, e, f;
while (1) {
scanf("%c", &c);
if (c == '\n') {
break;
} else {
a[i] = c;
i++;
}
}
if (i >= 2) {
d = a[i - 2] - 48;
e = a[i - 1] - 48;
f = d * 10 + e;
} else {
f = a[i - 1]... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 505;
const int OFF = 0;
const int ON_NOT_VISITED = 1;
const int ON_VISITED = 2;
vector<char> actions;
int n;
int mat[MAXN][MAXN];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
char dir[] = {'U', 'R', 'D', 'L'};
int is_in(int x, int y) { return 1 <= x ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int mpow(long long first, long long second);
bool isPalindrone(string s);
void in_arr(int arr[], int n);
void findPrime();
long long _mod(long long a);
int prime[1];
void solve() {
int n;
cin >> n;
int arr[n];
in_arr(arr, n);
string s;
cin >> s;
vector<int> v1... | 2 |
#include <bits/stdc++.h>
using namespace std;
double dp[3000][3000];
int main() {
long long n, t, i, j;
double p;
cin >> n >> p >> t;
dp[1][1] = p;
dp[1][0] = 1 - p;
for (i = 2; i <= t; i++) {
for (j = 0; j <= min(n, i); j++) {
if (j == n)
dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1] * p;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int m, p;
int slv(int m, int p) {
if (m == 0) return p;
if (p == 1)
p = m % 2 ? 0 : 2;
else if (p == 0 and m % 2)
p = 1;
else if (p == 2 and !(m % 2))
p = 1;
return slv(m - 1, p);
}
int main() {
scanf("%d%d", &m, &p);
printf("%d\n", slv(m % 6, p));... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int a, b;
vector<int> vect(100009);
for (int i = 1; i <= n; ++i) {
scanf("%d %d", &a, &b);
int sol = 0;
int sq = sqrt(a);
for (int j = 1; j <= sq; j++) {
if (a % j == 0) {
if (vect[j] < i - b) sol+... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, l, r, x, n, h, m, cnt = 0, sum = 0, a[1000];
memset(a, -1, sizeof(a));
cin >> n >> h >> m;
for (i = 0; i < m; i++) {
cin >> l >> r >> x;
for (j = l; j <= r; j++) {
if (a[j] != -1)
a[j] = min(a[j], x);
else
a... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
int mat[n][n];
memset(mat, 0, sizeof(mat));
if (k % n == 0) {
cout << "0"
<< "\n";
} else
cout << "2"
... | 8 |
#include <bits/stdc++.h>
using namespace std;
char mp[2][505][505];
int cant[2][2][505][505] = {0};
int sum[2][505][505];
int can[2][505][505];
inline int calc(int x1, int y1, int x2, int y2, int p) {
int a, b, c, d;
a = sum[p][x2][y2];
if (x1)
b = sum[p][x1 - 1][y2];
else
b = 0;
if (y1)
c = sum[p... | 12 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int f = 1, x = 0;
char c = getchar();
while (c < '0' || '9' < c) {
if (c == '-') f = -1;
c = getchar();
}
while ('0' <= c && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return f * x;
}
int a[100000 + 5];
bool cmp(int x, int ... | 2 |
#include <bits/stdc++.h>
int main() {
int a, b, c = 0;
scanf("%d%d", &a, &b);
int s = 0;
while (a > 0) {
s = s + a;
int xx = a;
a = (xx + c) / b;
c = (xx + c) % b;
}
printf("%d\n", s);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 10, M = 1e5 + 10, mod = 998244353;
const double eps = 1e-5;
int rd() {
int x = 0, w = 1;
char ch = 0;
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%d%d", &n, &k);
vector<int> v(n);
map<int, int> f;
int M = (1 << k) - 1;
f[0] = 1;
long long res = 0;
int cs = 0;
for (int i = 0; i < n; ++i) {
scanf("%d", &v[i]);
cs ^= v[i];
if (f[cs] > f[cs ^ M]) cs ^= M;
re... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
for (int i = 0; i < q; i++) {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int j = 0; j < n; j++) cin >> a[j];
int b = *max_element(a.begin(), a.end());
int l = *min_element(a.begin(), a.end());
if (b - 2 * ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int max_n = 200222, max_x = 1001111, sz = 555, inf = 1000000007;
int n, a[max_n], q, f[max_x], rv[max_x], res[max_n], lastt[max_x], qq[max_n];
vector<int> v[max_n];
pair<int, pair<int, int> > p[max_n];
int power(int a, int b) {
if (b == 0) {
return 1;
}
if (... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, i = 0;
string x, a = "", b = "";
cin >> n >> x;
while ((i < n) && ((x[i] - '0') != 1)) {
if (x[i] - '0' == 0) {
a += '0';
b += '0';
} else {
a += '1';
b += '... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int K = 4;
const int Base = 27;
const int Sqrt = 200;
const int N = 550100;
const int Inf = 1e9;
int n;
int Len[N];
char Buffer[N];
int a[N][K + 1];
vector<int> Idx[N];
vector<int> Adj[N];
vector<int> Ans[N];
void min_self(int& x, int y) {
if (x > y) x = y;
}
string... | 17 |
#include <bits/stdc++.h>
struct {
inline operator int() {
int x;
return scanf("%d", &x), x;
}
template <class T>
inline void operator()(T &x) {
x = *this;
}
} read;
const int maxn = 16, maxk = 2048;
int a[maxn], b[maxn];
std::bitset<maxk> f[1 << maxn], g[1 << maxn];
int main() {
int n = read, k ... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
vector<int> g[N];
int a[N], pai[N];
int soma[N];
int paridade, dist[N];
void dfs(int u, int d) {
paridade = d;
dist[u] = d;
for (auto v : g[u]) dfs(v, d + 1);
}
int main(void) {
int n;
scanf("%d", &n);
set<int> s;
for (int i = 1; i <= n; ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int cmp(pair<int, int> p1, pair<int, int> p2) {
if (p1.first > p2.first)
return 1;
else
return 0;
}
int ans(int arr[], int n) {
for (int i = 1; i < n; i++) {
if (arr[i] != 0) return 1;
}
return 0;
}
int main() {
ios_base::sync_with_stdio(false);
ci... | 9 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > vv;
vector<long long> v;
set<long long> st;
map<long long, long long> mp;
long long i, j, ans, flg, mx = -1, mn, cnt, res, sm, m, n, r, t, p, q, l, a, b,
k;
long long br[200005];
string s;
char ch;
char ar[105][1... | 0 |
#include <bits/stdc++.h>
const long long SZ = 1e5 + 7;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
const long long MOD = 998244353;
long long opnmbr = 1;
using namespace std;
long long powermod(long long a, long long b) {
long long ans = 1;
while (b) {
if (b & 1) ans = (ans * a) % MOD;
b = b ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int i, j, k, z, x = 1e18, y = -1, sum = 1e18, p, q, l, T, m,
ans = 0;
long long int n;
double xx, yy;
bool f = false;
string s;
cin >> n >> k;
if (k... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const long long int inf = 1e14 + 7;
long long int a[maxn];
int main() {
long long int tp;
long long int n;
scanf("%lld", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
}
if (n == 1) {
printf("1 1\n0\n");
printf("1... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, max = INT_MIN, x;
vector<int> a;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> x;
if (x > max) max = x;
a.push_back(x);
}
int count = 0;
int y = 2 * k;
sort(a.begin(), a.end());
for (int i = 0; i < n; i++) {
if ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b;
vector<pair<int, int> > points;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a >> b;
points.push_back(make_pair(a, b));
}
if (n == 1) {
cout << -1;
return 0;
}
sort(points.begin(), points.end());
if (n == 2 && (p... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1005;
const int MOD = 1e9 + 7;
int n, m, k, tot;
int maxi, rest, aux, sum;
bool vis[M], gob[M];
vector<int> vec[M], cantgob;
void dfs(int v) {
vis[v] = 1;
aux++;
for (int i = 0; i < vec[v].size(); i++) {
int &y = vec[v][i];
if (!vis[y]) dfs(y);
... | 7 |
#include <bits/stdc++.h>
long long gi() {
long long x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) f ^= ch == '-', ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return f ? x : -x;
}
long long ans = 2;
struct SAM {
int trans[200010][26], fa[200010], len[200010], cnt, lst... | 26 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double PI = acos(-1);
template <class T, class S>
inline void add(T& a, S b) {
a += b;
if (a >= mod) a -= mod;
}
template... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int S = 1e6;
int n, a[S], b[S], arr[S];
int is[S];
deque<int> dq, sum, ans;
int main() {
cin >> n;
sum.resize(S);
dq.resize(S);
ans.resize(S);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 0; i < n; i++) scanf("%d", &b[i]);
for (int i = 0;... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 22 + 9;
int n, a[N], b[N], r[N];
bool cmp(const int &i, const int &j) { return a[i] < a[j]; }
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
r[i] = i;
}
sort(r, r + n, cmp);
for (int i = 0; i < n; i++) {
b... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long aa[200005];
long long dp[200005][2];
int main() {
long long t;
cin >> t;
while (t--) {
long long n, p, k;
cin >> n >> p >> k;
for (long long i = 1; i <= n; i++) {
cin >> aa[i];
dp[i][0] = dp[i][1] = 0;
}
sort(aa + 1, aa + 1 + ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000005;
const long long INFLL = 1000000000000000002ll;
const long long MOD = 1000000007;
inline long long min(long long a, long long b, long long c) {
return min(min(a, b), c);
}
inline long long min(long long a, long long b, long long c, long long d) ... | 7 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize(1)
#pragma GCC optimize(2)
long long gcd(long long a, long long b) {
while (b ^= a ^= b ^= a %= b)
;
return a;
}
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 4e5 + 10;
const int maxn = 1e9;
int T, n, m;
int vis[N];
int k, x... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e9 + 17;
void self_max(ll &a, ll b) { a = max(a, b); }
void self_min(ll &a, ll b) { a = min(a, b); }
int n, m, d, s;
queue<int> Q;
bool ok = true;
int v[1001];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
set<int> g[300];
vector<pair<int, int> > ans;
void dfs(int u) {
while (g[u].size()) {
int v = (*g[u].begin());
ans.push_back(make_pair(u, v));
g[u].erase(v);
g[v].erase(u);
dfs(v);
}
}
int main() {
int t, u, v;
cin >> t;
while (t--) {... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 2 * 1000000000;
int n, x, y, x_max, y_max, x_min, y_min;
long long a;
int main() {
scanf("%d", &n);
x_max = -oo;
y_max = -oo;
x_min = +oo;
y_min = +oo;
for (int i = 0; i < n; i++) {
scanf("%d%d", &x, &y);
x_max = max(x_max, x);
y_max =... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, d, h, i;
int main() {
scanf("%d", &n);
scanf("%d", &d);
scanf("%d", &h);
if (d == h) {
if (d == 1) {
if (n == 2)
printf("1 2\n");
else
printf("-1\n");
return 0;
}
if (d + 1 <= n) {
for (i = 2; i <= h; ++i) p... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T& x) {
T res = 0, f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
res = (res << 3) + (res << 1) + c - '0';
c = getchar();
}
x = res * f;
}
const long lon... | 15 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
std::istream& operator>>(std::istream& in, pair<T1, T2>& a) {
in >> a.first >> a.second;
return in;
}
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& out, pair<T1, T2>& a) {
out << a.first << " " << a.seco... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, num, flag = 0;
cin >> n;
for (int i = 0;; i++) {
num = (i * (i - 1)) / 2;
if (num == n) {
flag = 1;
break;
}
if (num > n) break;
}
if (flag == 1)
cout << "YES"
<< "\n";
else
cout << "NO";
return ... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x;
char c;
while ((c = getchar()) < '0' || c > '9')
;
for (x = c - '0'; (c = getchar()) >= '0' && c <= '9';) x = x * 10 + c - '0';
return x;
}
vector<pair<int, int> > v[20000 + 5];
int l[20000 + 5], r[20000 + 5], cnt;
struct data {
in... | 19 |
#include <bits/stdc++.h>
using namespace std;
void Read(int &v) {
char c;
while ((c = getchar()) < '0' || c > '9')
;
v = c & 15;
while ((c = getchar()) >= '0' && c <= '9') v = v * 10 + (c & 15);
}
const int N = 200100, M = 400100, Q = 200100;
int n, m, q;
int lb[25][35];
int cnt_lb;
int anc[N], siz[N], dis[... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
long long a, b, c, d;
cin >> a >> b >> c >> d;
cout << b << " " << c << " " << c << '\n';
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int cnt[2];
int num[2];
int main() {
int Q;
int n;
string str;
int len;
int tmp;
cin >> Q;
while (Q--) {
cnt[0] = cnt[1] = num[0] = num[1] = 0;
cin >> n;
tmp = n;
while (n--) {
cin >> str;
num[str.length() % 2]++;
for (int i =... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long int maxn = 201001;
vector<long long int> z_func(string s) {
long long int n = (long long int)(s.length());
vector<long long int> z(n);
for (long long int i = 1, l = 0, r = 0; i < n; ++i) {
if (i <= r) z[i] = min(r - i + 1, z[i - l]);
while (i +... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
char c = getchar();
long long fla = 1, k = 0;
while (c < '0' || c > '9') {
if (c == '-') fla = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
k = (k << 3) + (k << 1) + (c & 15);
c = getchar();
}
return fla * k;
}
... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
x = 0;
T flag = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') flag = -1;
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
x *= flag;
}
int n, m, head[100001], tot, dfn[100001... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e2 + 5;
int per[maxn][maxn];
int a[maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
ch... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int arr[maxn];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
long long n;
while (t--) {
cin >> n;
if (n == 0) {
cout << "1 1" << endl;
continue;
}
long long a = 0, b = 0;
for (l... | 9 |
#include <bits/stdc++.h>
int main(void) {
long long int n, k, x;
scanf("%lli %lli", &n, &k);
x = n / 2;
x = x / (k + 1);
printf("%lli %lli %lli", x, x * k, n - x * (k + 1));
}
| 0 |
#include <bits/stdc++.h>
const long long inf = 0x3f3f3f3f3f3f3f3LL;
const long long mod = (long long)1e9 + 7;
using namespace std;
template <class T>
void smin(T& a, T val) {
if (a > val) a = val;
}
template <class T>
void smax(T& a, T val) {
if (a < val) a = val;
}
const long long N = 1e3 + 50;
long long power(lon... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, x, pos[200000], dif[200000];
int main() {
while (cin >> n) {
for (int ii = 0; ii < (200000); ii++) pos[ii] = -1;
;
set<int> st;
for (int i = 0; i < n; i++) {
scanf("%d", &x);
st.insert(x);
if (pos[x] == -1)
pos[x] = i, dif[... | 5 |
#include <bits/stdc++.h>
using namespace std;
int tab[200010];
int ans = 0, maxx = -1;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> tab[i];
if (tab[i] == 1)
ans++;
else {
if (ans > maxx) {
maxx = ans... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long f(int count) {
long long fac{1};
while (count) fac *= count--;
return fac;
}
int main() {
int n;
cin >> n;
string str;
vector<int> counter(26);
while (n--) {
cin >> str;
counter[str[0] - 'a']++;
}
long long answer{0};
for (auto count ... | 1 |
#include <bits/stdc++.h>
using namespace std;
string s;
int n, a[200100], i, x, mini = 2000001000, j;
int main() {
std::ios::sync_with_stdio(false);
cin >> n;
cin >> s;
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < n; i++) {
if (s[i] == 'R') {
for (j = i + 1; i < n; j++) {
i... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0;
bool t = false;
char ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') t = true, ch = getchar();
while (ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar();
return t ? -x : x;
}
m... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, m;
int ans[maxn];
int to[maxn];
int have[maxn];
int main() {
scanf("%d%d", &n, &m);
int x, y;
memset(to, 0, sizeof(to));
memset(have, 0, sizeof(have));
for (int i = 1; i <= m; i++) {
scanf("%d%d", &x, &y);
have[x]++;
i... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long f(long long pre, long long k) {
if (pre < 0)
return -pre / k + (pre % k != 0);
else
return -pre / k;
}
int main() {
long long p, k;
cin >> p >> k;
vector<long long> q;
q.push_back(f(p, k));
while (q.back() != 0) {
q.push_back(f(q.back(), ... | 12 |
#include <bits/stdc++.h>
using namespace std;
priority_queue<long long, vector<long long>, less<long long> > q;
const long long N = 200005;
struct node {
long long a, t;
} op[N];
long long n, a[N], t[N], sum = 0, ans = 0;
bool oppp(node R, node T) {
if (R.a == T.a) return R.t > T.t;
return R.a < T.a;
}
int main()... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, p, maxm = INT_MIN;
map<string, int> m, mm;
map<string, int>::iterator it;
string s, ansstr;
cin >> n;
vector<string> name;
vector<int> points;
while (n--) {
cin >> s >> p;
m[s] += p;
name.push_back(s);
points.push_back(p);... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100, MX = 12;
long long int dp[N][MX], ch[N][MX];
int mxm(int x) {
if (x == 0) return 0;
return max(x % 10, mxm(x / 10));
}
int main() {
long long int n;
cin >> n;
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 1e6; j++) {
if (i =... | 16 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.