solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long mod = 1e17 + 7;
const long long N = 1e5 + 5;
long long a[N], b[N], n, k;
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> k;
for (long long i = 0; i < (n); ++i) cin >> a[i];
for (long long i = 0; i < (n); ++i) ci... | 7 |
#include <bits/stdc++.h>
using namespace std;
namespace {}
int main() {
int n;
cin >> n;
long long sum = 0;
for (int i = 9; n > 0; i *= 10) {
sum += n;
n -= i;
}
cout << sum;
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
stack<long long> S;
bool vis[222222];
long long n, R[222222], L[222222], H[222222], PA[222222], SA[222222],
PL[222222], SL[222222], tot;
long long TOT, LA[222222], NE[444444], EN[444444], LE[444444], d;
long long GM(long long x, long long y, long long z) {
if (x >= y ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
const long long M = 1000000007;
const long long dx[4] = {1, 0, -1, 0};
const long long dy[4] = {0, 1, 0, -1};
string s[1000];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m;
cin >> n >> m;
for (long... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<int> a;
vector<long long> x;
int n, m;
bool solve(long long maxn) {
for (int i = 0; i < n; ++i) x[i] = a[i];
x[n - 1] = min(m - 1LL, x[n - 1] + maxn);
for (int i = n - 2; i >= 0; --i) {
if (x[i] <= x[i + 1])
x[i] += min(x[i + 1] - x[i], maxn);
els... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 5;
const long long mo = 998244353;
int n, m, k;
int a[maxn], c[maxn];
int ans, tmp, cnt;
int flag;
long long dp[maxn][maxn];
template <typename T>
inline void read(T &X) {
X = 0;
int w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long f[2][1000051], ff[1000051], fac[1000051], invfac[1000051];
const int mod = 1e9 + 7;
inline long long qpow(long long x, int p) {
long long res = 1;
while (p) {
if (p & 1) res = res * x % mod;
x = x * x % mod;
p >>= 1;
}
return res;
}
inline long... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = (1 << 18) + 100;
int n, a[N], lim, fa[N], g[N], h[N], size[N];
pair<int, int> f[N];
priority_queue<pair<int, int> > que;
template <class T>
inline void read(T &x) {
x = 0;
char ch = getchar(), w = 0;
while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
... | 27 |
#include <bits/stdc++.h>
using namespace std;
int h;
long long n, ans;
bool move(int height, long long &q) {
int cnt = 0;
long long tmp = q;
while (tmp) {
cnt++;
tmp >>= 1;
}
tmp = q >> (cnt - 2);
if (tmp == 2) {
q -= 1ll << cnt - 2;
return true;
} else {
q -= 1ll << cnt - 1;
retur... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int a, b, c, d, e, f, dummy;
cin >> dummy >> a >> b;
cin >> c >> dummy >> d;
cin >> e >> f >> dummy;
int x = (d + f) / 2;
int y = b - f + x;
int z = a + x - d;
cout << x << " " << a << " " << b << endl;
cout << c << " " << y << " " << d <<... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int TESTS = 1;
while (TESTS--) {
int n;
cin >> n;
vector<long long int> a(n);
for (long long int i = 0; i < n; i++) cin >> a[i];
int m;
cin >> m;
vector<long long i... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 150005, M = 150005, LOG = 21;
template <class T>
void read(T &x) {
int sgn = 1;
char ch;
x = 0;
for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar())
;
if (ch == '-') ch = getchar(), sgn = -1;
for (; '0' <= ch && ch <= '9'; ... | 27 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
int a, b, c;
cin >> n >> a >> b >> c;
n *= 2;
long long ans = 0;
for (int i = 0; i <= a; i++) {
for (int j = 0; j <= b; j++) {
int nn = n - i * 1 - j * 2;
if (nn < 0) continue;
if (nn % 4 == 0) {
if (nn / 4 <= c) a... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, k, cnt, bo[130];
char nam[110], s[110], ans[11000];
bool check() {
int maxx = 0, len = strlen(nam), jilu = 0;
cnt = -1;
char ch;
memset(bo, 0, sizeof(bo));
bo[(int)nam[0]] = false;
for (int i = 1; i <= len - 1; i++) {
if (nam[i] == nam[i - 1]) jilu++;... | 13 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const double PI = acos(-1.0);
const double EPS = 1e-6;
struct Point {
LL x, y;
};
struct Vec {
LL x, y;
double rad;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<Point> x(n);
for (int i = 0; i < n; +... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, l, r;
cin >> n >> a >> b;
int ans[n + 1];
for (int i = 1; i <= n; i++) ans[i] = 2;
for (int i = 0; i < a; i++) {
cin >> r;
ans[r] = 1;
}
for (int i = 0; i < b; i++) cin >> l;
for (int i = 1; i <= n; i++) cout << ans[i] << " ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 200000;
struct Res {
int len1, a1, common2, len2, a2, b2, common3, len3, a3, b3, c3, common4, len4,
a4, b4, c4, d4;
Res() { len1 = common2 = len2 = common3 = len3 = common4 = len4 = 0; }... | 17 |
#include <bits/stdc++.h>
using namespace std;
int sqrt_ceil(int n) {
int temp = int(sqrt(n));
while (temp * temp < n) temp++;
return temp;
}
int main() {
int a, b;
cin >> a >> b;
bool found = false;
for (int x_1 = 1; x_1 < a; x_1++) {
int y_1 = sqrt_ceil(a * a - x_1 * x_1);
if (x_1 * x_1 + y_1 * y... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
if (s == "0") {
cout << "0\n";
return 0;
}
int cnt1 = 0;
for (int i = 0; i < s.length(); ++i) {
if (s[i] == '1') cnt1++;
}
int cnt0 = n - cnt1;
cout << 1;
for (int i = 1; i <= cnt0; ++i) cout << ... | 0 |
#include <bits/stdc++.h>
using namespace std;
void freac() {}
const int DX[] = {+1, 0, -1, 0, +1, +1, -1, -1};
const int DY[] = {0, +1, 0, -1, +1, -1, +1, -1};
const int INF = (int)1e9 + 123;
const long long INFL = (long long)1e18 + 123;
const double EPS = 1e-9;
int main() {
freac();
ios_base ::sync_with_stdio(0);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> p[110000];
int N;
long long rmax[110000], rmin[110000], bmax[110000], bmin[110000];
bool possible(long long d) {
int i, j;
long long ma, mi;
for (i = 0; i < N; i++) {
j = upper_bound(p, p + N,
pair<long long, long lon... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
string number;
cin >> number;
long long count = 0;
if (number[0] % 4 == 0) {
count++;
}
for (unsigned i = 1; i < number.length(); i++) {
if (number[i] % 4 == 0) {
count++;
}
string str = number.su... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long SIZE = 100000;
const int INF = 0x3f3f3f3f;
const long long ll_INF = 0x3f3f3f3f3f3f3f3f;
const long double PI = acos(-1);
const long long MAXN = numeric_limits<long long>::max();
const long long MAX = 2000000;
void solve() {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, i, x, d, h, y = 2, val = -1, ans = 0;
cin >> n >> d >> h;
x = d - h;
if (d > 2 * h || (d == h && h == 1 && n > 2)) {
cout << -1 << "\n";
return 0;
}
while (h--) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct cnt {
string cn;
int pn, gs, gm;
int nm;
} cc[4];
bool myop(const cnt &c1, const cnt &c2) {
if (c1.pn != c2.pn) return (c1.pn > c2.pn);
int gd1 = c1.gs - c1.gm, gd2 = c2.gs - c2.gm;
if (gd1 != gd2) return (gd1 > gd2);
if (c1.gs != c2.gs) return (c1.gs >... | 10 |
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using pll = pair<ll, ll>;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
auto solv... | 14 |
#include <bits/stdc++.h>
using namespace std;
char s[200000];
long long al[27];
long long nu[15];
int main() {
scanf("%s", s);
int len = strlen(s);
memset(nu, 0, sizeof(nu));
memset(al, 0, sizeof(al));
for (int i = 0; i < len; i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
al[s[i] - 'a']++;
} else {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int mat[105][105];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) scanf("%d", &mat[i][j]);
int k = 2;
while (n % k == 0) {
int flag = 1;
for (int j = 1; j <= m; j++)
for (int i = 1; i <= n / k; i++... | 5 |
#include <bits/stdc++.h>
using namespace std;
stack<time_t> time_stack;
void startTimer() { time_stack.push(clock()); }
double stopTimer() {
double time = clock() - time_stack.top();
time_stack.pop();
return time / double(CLOCKS_PER_SEC);
}
double sqr(double x) { return x * x; }
set<int> solve(vector<int> a, vect... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int pre[int(2e5) + 10], num[(int(2e5)) + 10];
int main() {
istream& in = cin;
in >> n >> k;
int p = n - 1 - k;
if (p == 0) {
cout << 2 << endl;
for (int i = 2; i <= n; ++i) cout << 1 << " " << i << endl;
} else {
if (p == 1) {
cout << 3... | 10 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 200005;
int n;
int a[N];
char s[N];
pair<int, char> ans[N];
void solv() {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
cin >> (s + 1);
sort(a + 1, a + n + 1)... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n, k, a[100010];
int main() {
scanf("%d %d", &n, &k);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
int c2;
c2 = n - k;
if (c2 < 0) {
c2 = 0;
}
int ans = 0;
for (int i = 0; i < c2; ++i) {
ans = max(ans, a[i] + a[c2 * 2 - i - 1]);
}
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (~scanf("%d", &n)) {
printf("%d\n", 2 * n - n / 2);
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int MAXV = 1e7 + 5;
int n, q, qn, a[MAXN];
int hd[MAXN], nxt[MAXN << 1], to[MAXN << 1], ec = 0;
void adde(int u, int v) {
to[++ec] = v;
nxt[ec] = hd[u];
hd[u] = ec;
}
int fa[MAXN][22], dep[MAXN];
void dfs(int x,... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e4 + 10;
int a[MAX_N];
int check(int p) {
int ans = 0;
for (int i = 0; i < MAX_N; i++) ans += a[i] * abs(i - p);
return ans;
}
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n, m, d;
cin >> n >> m >> d;
for (int i = 0... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool ckmax(T& x, T y) {
return x < y ? x = y, 1 : 0;
}
template <class T>
bool ckmin(T& x, T y) {
return x > y ? x = y, 1 : 0;
}
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = 0;
ch =... | 18 |
#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 d, m;
cin >> d >> m;
long long ans = 1, i = 0;
while ((1 << i + 1) <= d) ans = (ans * (1 + (1 << i++))) % m;
ans = (ans * (1 + (d - (1 << i) + 1))) ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int fun(int m, int n) {
int cnt = 0;
for (int i = 1; i * i <= m; i++) {
if (i * i == m) {
if (i > n) cnt++;
} else if (m % i == 0) {
if (i > n) cnt++;
if (m / i > n) cnt++;
}
}
return cnt;
}
int main() {
int a, b;
scanf("%d%d", &a, ... | 8 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int maxn = 200000 + 10;
int col[2][maxn];
int row[2][maxn];
vector<pair<int, int> > G[maxn];
int p[2][maxn];
int co[maxn];
int vis[maxn];
stack<int> S;
int n;
int dfs(int u, int c) {
co[u] = c;
S.push(u);
for (auto e : G[u]) {
int nc = c... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 222222;
int a[N], f[N];
int main() {
int n, i, x, ans;
scanf("%d", &n);
for (i = 1; i <= n; i = i + 1) scanf("%d", a + i);
ans = 0;
for (i = n; i >= 1; i = i - 1) {
if (!f[i]) {
ans++;
x = i;
while (x) {
f[x] = 1;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1000000009;
int z[2][35][35][35][35], u[2][35][35][35][35];
int us, p[4], up[4], np[4];
int n, h;
int main() {
scanf("%d%d", &n, &h);
z[1][0][0][0][0] = 1;
us++;
u[1][0][0][0][0] = us;
for (int i = 1; i <= n; i++) {
int now = i % 2;
int nxt... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6, big = 1e18;
long long val[maxn], t[4 * maxn + 5], sum[4 * maxn + 5];
void build(long long v, long long l, long long r) {
if (l == r - 1) {
sum[v] = 0;
t[v] = val[l];
return;
}
long long m = (l + r) / 2;
build(2 * v, l, m);
b... | 14 |
#include <bits/stdc++.h>
namespace IO {
template <typename T>
inline void read(T &x) {
x = 0;
int f = 1;
char ch = getchar();
while (ch > '9' || ch < '0') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
x *= f;
ret... | 9 |
#include <bits/stdc++.h>
int get(char ch) {
if (ch >= '0' && ch <= '9')
return ch - '0';
else
return ch - 'a' + 10;
}
char str[15];
int num[15], now[15], sum[1048576];
long long Pow[15];
long long f[1048576];
signed main() {
scanf("%s", str + 1);
int n = strlen(str + 1);
int Cnt = 0;
for (int i = 1;... | 25 |
#include <bits/stdc++.h>
using namespace std;
struct node {
string str;
int l;
int r;
} a[15];
int main() {
string s;
int n;
cin >> s;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i].str >> a[i].l >> a[i].r;
int ans = 0;
map<string, int> mp;
for (int i = 0; i < s.size(); i++)
for (int j = 1;... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = int(1e5 + 5);
int a[N];
pair<int, int> b[N];
bool used[N];
int main() {
ios_base::sync_with_stdio(0);
int k, n;
cin >> n >> k;
long long B;
cin >> B;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n - 1; i++) {
b[i] = make_pair(... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, b, d, i, sum = 0, count = 0;
cin >> n >> b >> d;
int x[n];
for (i = 0; i < n; i++) {
cin >> x[i];
}
for (i = 0; i < n; i++) {
if (x[i] > b)
continue;
else
sum += x[i];
if (sum > d) {
sum = 0;
count++;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, x;
cin >> n >> a;
if (a % 2 == 1)
x = (a - 1) / 2 + 1;
else
x = (n - a) / 2 + 1;
cout << x << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
int read() {
static int ch, x;
while ((ch = getchar()) < 48) {
}
x = ch ^ 48;
while ((ch = getchar()) >= 48) x = (((x << 2) + x) << 1) + (ch ^ 48);
return x;
}
const int INF = 0x3f3f3f3f;
struct edge {
int next, to;
} e[100010 << 1];
int ei;
int l[100010], r[100010], head[100010];... | 24 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-12;
int a, b, c, d;
double ans, g[2];
int main() {
scanf("%d%d%d%d", &a, &b, &c, &d);
g[0] = 1.0 * a / b, g[1] = 1.0 * (d - c) / d;
double tmp = 1;
while (tmp > eps) {
ans += tmp * g[0];
tmp *= (1 - g[0]) * g[1];
}
printf("%.12lf\n"... | 5 |
#include <bits/stdc++.h>
using namespace std;
long double ans = 0;
vector<int> v;
int n, u, tmp, ek = -1, ei, ej, pti;
int main() {
ios::sync_with_stdio(false);
cin >> n >> u;
for (int i = 0; i < n; i++) {
cin >> tmp;
v.push_back(tmp);
}
pti = n - 2;
for (int i = n - 1; i > 1; i--) {
pti = min(p... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int LEN = 200005;
char STR[LEN], *ST = STR, *ED = STR;
inline char gc() {
if (ST == ED) {
ED = (ST = STR) + fread(STR, 1, LEN, stdin);
if (ST == ED) return EOF;
}
return *ST++;
}
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a, b;
pair<int, pair<int, int> > A[400001];
pair<int, pair<int, int> > B[400001];
map<int, int> T;
map<int, int> P;
set<int> TT;
set<int> PP;
vector<pair<pair<int, int>, int> > Q[400001];
vector<pair<pair<int, int>, int> > W[400001];
int R[400001];
int F[800000];
... | 16 |
#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
x = 0;
int f = 1;
char ch = getchar();
while (ch != 45 && (ch > '9' || ch < '0')) ch = getchar();
if (ch == 45) {
f = -1, ch = getchar();
}
while (ch <= '9' && ch >= '0') {
x = x * 10 + ch - 48;
ch = getchar();
}
x *=... | 18 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
long long int ans = 0;
map<long long int, long long int> mp, ml;
long long int n, m;
cin >> n >> m;
for (long long int i = 1; i <= n; i++) {
mp[i % 5]++;
}
for (long long int i = 1; i <= m; i++) {
ml[i % 5]++;
}
for (long long int ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long ans, f[310][2][2];
char s[310];
int n;
long long get(int x, int y) {
memset(f, 0, sizeof f);
f[0][x][y] = 1;
for (int i = 0; i <= n; i++)
for (int j = 0; j < 2; j++)
for (int k = 0; k < 2; k++) {
if ((s[i] == 'A' && (k == 0 || (k == 1 && j ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
struct BIT {
int n, sum;
vector<int> a, c;
inline void init(int _n) {
n = _n;
a = c = vector<int>(n + 1, 0);
}
inline void update(int i, int val) {
val -= a[i];
a[i] += val;
sum += val;
for (++i; i <= n; i += i & -i... | 12 |
#include <bits/stdc++.h>
using namespace std;
int a[10005];
int main() {
int n, m;
cin >> n >> m;
bool ans = true;
while (m--) {
int k;
cin >> k;
bool flag = true;
for (int i = 0; i < k; i++) {
cin >> a[i];
for (int j = 0; j < i; j++) {
if (a[i] == -a[j]) {
flag = f... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 4e18;
const long long N = 2e5 + 10;
void testCase() {
long long n, m, ta, tb, k;
cin >> n >> m >> ta >> tb >> k;
vector<long long> a(n), b(m), c(m);
for (long long &i : a) cin >> i, i += ta;
for (long long i = 0; i < m; i++) cin >> b[i], c[i]... | 8 |
#include <bits/stdc++.h>
using namespace std;
string s[1005];
bool check(char x, char y) {
if (isalpha(x)) x = tolower(x);
if (isalpha(y)) y = tolower(y);
if (x == '0' && y == 'o' || x == 'o' && y == '0') return true;
if (x == '1' && y == 'l' || x == '1' && y == 'i' || x == 'l' && y == 'i' ||
x == 'l' && ... | 4 |
#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, int> m;
int num_x, num_y, res, x_1, x_2, y_1, y_2;
int main() {
for (int i = 1; i <= 4; i++) {
cin >> x_1 >> y_1 >> x_2 >> y_2;
m[make_pair(x_1, y_1)]++;
m[make_pair(x_2, y_2)]++;
if (x_1 != x_2 && y_1 != y_2) {
printf("No");
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
const long long mod = 1e9 + 7;
const long long inf = 1e18 + 10;
int l[N], r[N], v[N], lzy[4 * N], n;
pair<int, int> seg[4 * N];
vector<int> V[N], R[N];
void build(int l = 0, int r = n, int id = 1) {
if (r - l == 1) {
seg[id] = make_pair(0, l);
... | 16 |
#include <bits/stdc++.h>
using namespace std;
bool can_win(long long s, long long e) {
if (s > e) return true;
if (e % 2) return 1 - s % 2;
long long f = e / 2;
long long x = e / 4;
if (s > f) return s % 2;
if (s > x) return 1;
return can_win(s, x);
}
bool can_lose(long long s, long long e) {
if (s * 2 ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
string color = "VIBG";
cout << "YOR";
n -= 3;
for (int i = 0; i < n; i++) {
cout << color[i % 4];
}
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 111111;
char ch[N];
int sum[N];
int main() {
int n, l, r, len;
while (cin >> ch + 1) {
scanf("%d", &n);
sum[0] = 0;
len = strlen(ch + 1);
for (int i = 1; i < len; i++)
if (ch[i] == ch[i + 1])
sum[i] = sum[i - 1] + 1;
els... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
void solve() {
long long a, b;
cin >> a >> b;
long long arr1[6] = {0};
long long arr2[6] = {0};
long long q1 = a ... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool compare(long long int x, long long int y) { return x > y; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int t = 1;
while (t--) {
long long int i = 0, j = 0, k = 0, l = 0, z = 0;
long long int n, m = 0;
cin >> ... | 4 |
#include <bits/stdc++.h>
using namespace std;
char ch[200001];
map<int, int> lozh, prav;
int n, m, x, t, tp, sch = 1, c, a[200001];
bool d[200001];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
cin >> ch[i];
cin >> a[i];
if (ch[i] == '+') {
lozh[a[i]]++;
t++;
} else ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (1 << 17);
int a[maxn], pos[maxn], n, b[maxn];
struct num {
int idx, val;
bool operator<(const num &mtp) const { return val > mtp.val; }
};
priority_queue<num> q1, q2;
int out[maxn];
void read() {
int i;
scanf("%d", &n);
for (i = 1; i <= n; ++i) {... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n;
bool check(int x) {
for (int i = 2; i * i <= x; i++) {
if (x % i == 0) return false;
}
return true;
}
int pw(int a, int b) {
if (b == 0) return 1;
if (b == 1) return a;
int res = pw(a, b / 2);
if (b % 2 == 0)
return (int)(... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-13;
const long double PI = acos(-1);
const int INF = (int)1e9;
const long long INFF = (long long)1e15;
const int mod = 998244353;
const int MXN = (int)5e2 + 7;
vector<int> edge[MXN];
int ck[MXN][10], num[MXN], dep[MXN], cntp;
int dp[MXN][MXN][11];... | 20 |
#include <bits/stdc++.h>
using namespace std;
struct outFloat {
int precision;
long double value;
outFloat(long double v, int p) : precision(p), value(v) {}
};
const int inf = 123456789;
const long long llInf = 123456789012345678;
const long double pi = 3.14159265358979323846;
const int maxN = 2000000;
int init()... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n;
const int MAX_N = 50;
long long answer[MAX_N + 1];
int main() {
answer[2] = 3LL;
answer[3] = 5LL;
answer[4] = 25LL;
answer[5] = 59LL;
answer[6] = 97LL;
answer[7] = 239LL;
answer[8] = 95LL;
answer[9] = 119LL;
answer[10] = 507LL;
answer[11] = 3487LL... | 19 |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[200001];
long long int vis[200001];
void bfs(int i, vector<long long int> &x) {
x[i] = 0;
queue<int> q;
q.push(i);
vis[i] = 1;
while (!q.empty()) {
int j = q.front();
q.pop();
for (int k = 0; k < adj[j].size(); k++) {
if (vis[adj[... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, v;
cin >> n >> v;
long long int i, a, b, cnt = 0, t[3025] = {0};
for (i = 0; i < n; i++) {
cin >> a >> b;
t[a] += b;
}
long long int prev = 0;
cnt = 0;
for (i = 1; i < 3025; i++) {
int t1 = t[i];
if (t1 + prev <=... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long int digits(long long int n) { return floor(log10(double(n))) + 1; }
void faster() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
long long int modularExponentiation(long long int x, long long int n,
long long int M) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int NB = 30;
const string str = "BRY";
int n, N, m, q, i, j, k, e, pos, cnt, w[1010][3], a[4040][1010], b[4040],
c[4040], r[3030];
char op[7];
void setone(int i, int j) { a[i][j / NB] |= (1 << (j % NB)); }
int main() {
scanf("%d%d", &n, &q);
N = (n * 3 - 1) / ... | 24 |
#include <bits/stdc++.h>
int main() {
int i, n, k, a = 0, max = 0;
scanf("%d%d", &n, &k);
int ma[n * 2];
for (i = 0; i < n * 2; i++) {
scanf("%d", &ma[i]);
if (ma[i] == 0) ma[i] = 100;
}
for (i = 0; i < n * 2 - 1; i = i + 2) {
if (k > ma[i] || (k >= ma[i] && ma[i + 1] == 100)) {
a = 1;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
void past_code();
int main() {
int q, x, y, c = 0, l = 0, ans = 100000;
string s, t = "RGB";
cin >> q;
while (q--) {
ans = 1000000;
l = 0, c = 0;
cin >> x >> y;
cin >> s;
for (int i = y - 1; i < s.length(); i++) {
for (int j = i - y + 1; j ... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long x, y, n;
long long geta(long long b) {
if ((b * x * 2) % (y) == 0) return (int(double(b * x) / double(y)));
return (round(double(b * x) / double(y)));
}
pair<long long int, long long int> diff(pair<long long int, long long int> a,
... | 9 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int 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 << 3) + (x << 1) + (ch ^ '0');
ch = getchar();
}
return x * f;
}
vector<i... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1600;
struct point {
int x, y, pos;
};
point a[maxn], Global;
int ans[maxn], cnt[maxn], n;
vector<int> g[maxn];
long long sqr(long long x) { return x * 1ll * x; }
long long vect(point p1, point p2, point p3) {
return (p2.x - p1.x) * 1ll * (p3.y - p1.y) ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int arr[26] = {}, arr2[26] = {}, ans = 0;
string s, s2;
cin >> s >> s2;
for (int i = 0; i < max(s.size(), s2.size()); i++) {
if (i < s.size()) arr[s[i] - 'a']++;
if (i < s2.size()) arr2[s2[i] - 'a']++;
}
for (int i = 0; i < 26; i++) {
if... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 10;
struct TnT {
int a, b, num;
} T[M];
bool cmp(TnT x, TnT y) { return x.a > y.a; }
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> T[i].a;
T[i].num = i + 1;
}
for (int i = 0; i < n; i++) {
cin >> T[i].b;
}
... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, n, ans, cn1, cn2, cn3, t;
string s, s1, s2;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
long long u1, d1, u2, d2, w, h;
cin >> w >> h >> u1 >> d1 >> u2 >> d2;
if (d2 > d1) {
swap(d1, d2);
swap(u1, u2);
}
ans... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
map<unsigned long long int, unsigned long long int> m;
unsigned long long int n, k, x, y;
cin >> n;
for (unsigned long long int i = 0; i < n; i++) {
cin >> x >> y;
m[x] = max(m[x], y);
}
cin >> k;
for (unsigned long long int i = 0; i < k; ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 28;
const double INF = 1e12, EPS = 1e-9;
void run() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cout << (i ? i : n) << (i == n - 1 ? "\n" : " ");
}
int main() { run(); }
| 9 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
int arr[n], brr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
brr[i] = arr[i];
}
sort(brr, brr + n);
int min = brr[0];
for (int i = 0; i < n; i++) {
if (arr[i] % min) {
if (arr[i] != brr[i]) {
cout... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, i, j, k, l, m, n;
long long have[100005], need[100005], temp[100005];
bool valid(long long cur) {
long long sum = 0;
for (i = 0; i < n; i++) {
temp[i] = max(0ll, (cur * need[i]) - have[i]);
sum += temp[i];
if (temp[i] > k or sum > k) re... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, x[100001], c[100001], hl[100001], ans;
int main() {
cin >> n >> m >> k;
for (int i = 1; i <= m; i++) hl[i] = 1e9;
for (int i = 1; i <= n; i++) {
cin >> x[i] >> c[i];
hl[x[i]] = min(c[i], hl[x[i]]);
}
for (int i = 1; i <= m; i++) ans += hl[i];
... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int X = 0, w = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') w = -1;
c = getchar();
}
while (c >= '0' && c <= '9') X = (X << 3) + (X << 1) + c - '0', c = getchar();
return X * w;
}
int h[20];
int a, b;
int n;
int a... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string second;
cin >> second;
long long int i = 0, n, a = 0, b = 0, count = 0, c = 0, d = 0, k = 0, p = 0;
p = second.size();
n = second.size();
if (n < 4) {
cout << "-1";
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int bnd = 128;
const int P = (int)5e4 + 10;
pair<bool, vector<int> > work(const vector<int> &a, int p) {
const int n = (int)(a).size();
int mcan[bnd][p], prev[bnd][p];
int current[bnd][p];
memset(mcan, -1, sizeof mcan);
memset(prev, -1, sizeof prev);
mcan[... | 21 |
#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
const int INF = 2000000000;
const long long LINF = 2000000000000000000;
const long double LDINF = 2e18;
template <typename T... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7, INF = 1e9 + 7;
int n, h, a, b, k;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> h >> a >> b >> k;
for (int i = 0; i < k; ++i) {
int ta, fa, tb, fb;
cin >> ta >> fa >> tb >> fb;
if (ta == tb... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, ans = 0;
cin >> a >> b;
for (int i = 1; i <= a; i++) {
if (i % 2 == 1)
for (int j = 0; j < b; j++) cout << '#';
if (i % 2 == 0) {
if (ans == 0) {
for (int j = 0; j < b - 1; j++) cout << '.';
cout << '#';
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e18;
long long int mul(long long int a, long long int b) {
return ((a % mod) * (b % mod)) % mod;
}
long long int add(long long int a, long long int b) {
return ((a % mod) + (b % mod)) % mod;
}
long long int sub(long long int a, long long int b) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int x[55];
bool can[500002];
int steps[5000002];
int main() {
int N, K;
scanf("%d%d", &N, &K);
for (int i = 1; i <= N; ++i) scanf("%d", &x[i]);
sort(x + 1, x + N + 1);
int bestSum = 0;
for (int i = 1; i <= N; ++i)
if (bestSum + K >= x[i])
bestSum += x[... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long ar[200009];
set<long long> ss, st;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
for (long long i = 1; i <= n; i++) cin >> ar[i];
for (long long i = 1; i < n; i++) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long mul(long long a, long long b) {
a %= mod;
b %= mod;
return (a * b) % mod;
}
struct vertex {
long long S[6];
public:
vertex() {
S[0] = 1;
fill(S + 1, S + 6, 0);
}
vertex(long long p, long long v) {
S[0] = v... | 17 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.