solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e4 + 5;
int sum[55][maxn], d[55][maxn];
int dp[55][maxn];
int tree[maxn << 2], tag[maxn << 2];
int n, m, k, lim;
inline void up(int t) { tree[t] = max(tree[t << 1], tree[t << 1 | 1]); }
inline void down(int t) {
if (tag[t]) {
tag[t << 1] += tag[t], t... | 16 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, e, f;
int main() {
int i, j, k;
while (scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f) != EOF) {
if (d == 0) {
printf("Hermione\n");
continue;
}
if (c == 0) {
printf("Ron\n");
continue;
}
if (b == 0) {
prin... | 10 |
#include <bits/stdc++.h>
const double eps = 1e-9;
const int int_inf = 2000000000;
const long long i64_inf = 1000000000000000000LL;
const double pi = acos(-1.0);
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int B = 0;
while (b > 0) {
B = B * 10 + b % 10;
b /= 10;
}
cout << a + B << endl... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXM = 23, MAXN = (1 << MAXM) + 10;
int mark[MAXN], a[MAXM + 10], n, h[MAXM + 5], f[MAXM + 5][MAXM + 5];
inline bool check(int mask, int mx) {
int mask2 = mask | (1 << (mx - 1));
bool is = false;
for (int i = 0; i < mx; i++)
if (mask & (1 << i) and f[i][... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <class TT>
TT abs(TT a) {
if (a < 0) return -a;
return a;
}
template <class ZZ>
ZZ max(ZZ a, ZZ b, ZZ c) {
return max(a, max(b, c));
}
template <class ZZ>
ZZ min(ZZ a, ZZ b, ZZ c) {
return min(a, min(b, c));
}
typedef struct {
int x, y, z;
void print() ... | 6 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast", "unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int inf = numeric_limits<int>::max() / 2;
const long double eps = 1e-9;
const long double pi = acos(... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long Mod = 998244353;
const int Maxn = 250010;
const int maxn = 250010 * 2;
const long long mod = 998244353, G = 3, Gi = 332748118;
long long fac[Maxn];
int n;
long long a[Maxn];
long long aa[maxn], bb[maxn], cc[maxn];
int r[maxn];
int limit = 1, L;
long long ksm... | 18 |
#include <bits/stdc++.h>
template <typename T>
inline void SWAP(T &a, T &b) {
T tmp = a;
a = b;
b = tmp;
}
template <typename T>
inline T ABS(const T &val) {
return val < 0 ? -val : val;
}
template <typename T>
inline T MAX(const T &a, const T &b) {
return a > b ? a : b;
}
template <typename T>
inline T MIN(c... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, i;
int l[200020];
int r[200020];
string s[20020];
string q[20020];
string rel, rs;
vector<int> z_function(string s) {
int n = (int)s.length();
vector<int> z(n);
for (int i = 1, l = 0, r = 0; i < n; ++i) {
if (i <= r) z[i] = min(r - i + 1, z[i - l]);
whi... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 100;
const int L = 30;
const int oo = 1e9;
int N, A[maxn];
int dp[L + 5][maxn];
inline void change(int &ret, int v) {
if (ret > v) ret = v;
}
int solve() {
for (int i = (0), _i = (L + 1); i <= _i; i++)
for (int j = (0), _j = (N); j <= _j; j++)... | 16 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F(i, m, n) for (ll i = m; i < n; i++)
#define Fr(j, n, m) for (ll j = n; j >= m; j--)
#define vll vector<ll>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define vpll vector<pll>
#define tlll tuple<ll, ll, ll>
/*-----------------... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 7;
const long long mod = 1e9 + 7;
int a[N];
void solve() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
int ans = 0;
for (int i = 2; i < n; ++i) {
if (a[i] > a[i - 1] && a[i] > a[i + 1]) ++ans;
if (a[i] < a... | 0 |
#include <bits/stdc++.h>
using namespace std;
FILE *f, *g;
int v[100100];
int nr, i, mx, x, lim;
char p[100000];
int din[100100];
vector<int> con;
int n, pr[10000];
void ciur(int n) {
int i, j;
for (i = 1; ((i * i) << 1) + (i << 1) <= n; i += 1) {
if ((p[i >> 3] & (1 << (i & 7))) == 0) {
for (j = ((i * i)... | 7 |
#include <bits/stdc++.h>
using namespace std;
using int64 = int64_t;
const int64 kInfL = 1e15 + 10;
const int kInf = 1e9 + 10;
const int kMod = 1e9 + 7;
void solve() {
int n;
cin >> n;
string s;
cin >> s;
auto check = [&](const int bit) -> int {
int b = 0, r = 0;
for (int i = 0; i < n; i++) {
if... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 19;
int read() {
int s = 0;
char c = getchar(), lc = '+';
while (c < '0' || '9' < c) lc = c, c = getchar();
while ('0' <= c && c <= '9') s = s * 10 + c - '0', c = getchar();
return lc == '-' ? -s : s;
}
void write(int x) {
if (x < 0) {
put... | 17 |
#include <bits/stdc++.h>
using namespace std;
double a[100010][101];
long long c[1000010][6];
int s[100010];
double b[101];
void doit(int u, int v, int k) {
memset(b, 0, sizeof(b));
for (int i = 0; i <= 100; i++)
for (int j = 0; j <= min(i, k); j++)
b[i - j] += a[u][i] * c[i][j] * c[s[u] - i][k - j] / c[s... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 0x3c3c3c3c;
const long long INFL = 0x3c3c3c3c3c3c3c3c;
long long cntSolved[5];
int N;
int solveTime[2][5];
int calcScore(long long a, long long b) {
for (int i = 1; i <= 5; i++) {
if ((1 << i) * a > b) return 500 * i;
}
ret... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int inf = 2e18 + 5;
int main() {
long long n, m, w, h, mx = 0;
cin >> n;
vector<int> a(n + 1);
for (int i = (1); i < (n + 1); i++) cin >> a[i];
cin >> m;
for (int i = (0); i < (m); i++) {
cin >> w >> h;
mx = mx > a[w] ? mx ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int A[1000001];
int B[1000001];
int E[1000001];
bool C[1000001];
int uf[100001];
int find(int x) {
if (uf[x]) return uf[x] = find(uf[x]);
return x;
}
vector<pair<int, int> > edge[100001];
int dep[100001];
int par[100001][17];
int dis[100001][17];
void dfs(int ... | 13 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
long long ret(long long n) {
long long a = (n * (n - 1)) / 2;
return a;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
v.clear();
long long n;
cin >> n;
long... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = int(1.5 * 1e7);
const int inf = 1e9 + 7;
const long long ll_inf = 1e18 + 420;
const double eps = 1e-4;
const int N = 1e6 + 7;
const int MAX = 2e5 + 9;
const int MOD = 1e9 + 7;
const long double pi = 3.14159265359;
int n, tin[N], tout[N], m, up[N][25], sum[N... | 13 |
#include <bits/stdc++.h>
using namespace std;
int dp[1005][505];
int solve(int i, int j) {
if (j == 0) return 1;
if (i <= 0) return 0;
if (dp[i][j] != -1) return dp[i][j];
dp[i][j] = 0;
for (int k = 0; k <= i - 1; ++k)
dp[i][j] =
(dp[i][j] + (solve(i - 2 - k, j - 1) * 1LL * (k + 1)) % 1000000007) ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 100;
int n, m;
bool cmp(const pair<pair<int, int>, int> &a,
const pair<pair<int, int>, int> &b) {
if (a.first.first != b.first.first) return a.first.first < b.first.first;
return a.first.second > b.first.second;
}
void fail() {
cout << -1 ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
int a1 = a, a2 = b, a3 = c;
if (d == a || d == b) {
cout << -1;
return 0;
}
if (a < d)
a1 = a2 = a3 = d;
else if (b < d)
a2 = a3 = d;
else if (c < d)
a3 = d;
if (2 * a < a1) a1 = 2 *... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5001, INF = 1e7;
const double PI = 3.141592653589793238462643383279502884197, eps = 1e-6;
int st[N][26];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int sz, cnt, cnt2, ans = 0;
string s;
cin >> s;
sz = s.size();
for... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int sum, limit;
vector<int> v[N];
int lowbit(int x) { return x & (-x); }
int main() {
cin >> sum >> limit;
for (int i = 1; i <= limit; i++) {
v[lowbit(i)].push_back(i);
}
vector<int> ans;
for (int i = 0; (1 << i) <= sum; i++) {
int j... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int G[505][505];
vector<int> g[505];
int vis[555];
char s[555];
int dfs(int u, int c) {
if (~vis[u]) return vis[u] == c;
vis[u] = c;
int i;
int ret = 1;
for (i = 0; i < g[u].size(); i++) {
ret &= dfs(g[u][i], c ^ 1);
}
ret... | 10 |
#include <bits/stdc++.h>
using namespace std;
struct Point {
int x, y, at;
Point(int a = 0, int b = 0, int c = 0) : x(a), y(b), at(c) {}
} op[1005];
int n;
vector<Point> v[2][2];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d%d", &op[i].x, &op[i].y);
to:;
for (int i = 0; i < 2; i++) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000000;
int main() {
int n;
scanf("%d", &n);
int a[n];
set<int> ocp;
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n);
int mn = 0;
for (int i = 0; i < n; i++) {
if (ocp.find(a[i] - 1) != ocp.end()) continue;
if (ocp.find(... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long a[300005], b[300005], c[300005], ans[300005];
vector<pair<long long, long long> > v;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long n, m, i, j, k, x;
cin >> n >> m;
for (i = 1; i <= n; i++) cin >> a[i] >> b[i];
for (i = 1; i <= n; i++)... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
int x;
int y;
} data[100];
char s[14];
int Count = 0;
void judge() {
int r, c, i, k, j, len;
len = strlen(s + 1);
for (c = 1; c <= 12; c++) {
if (12 % c != 0) continue;
r = 12 / c;
for (k = 1; k <= c; k++) {
for (j = k; j <= len; j ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int ans[1000005];
vector<int> posU;
vector<int> posD;
long long cumU[1000005];
long long int cumD[1000005];
long long int ans2[1000005];
int main() {
ios::sync_with_stdio(0);
int n;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < s.size(); ++i) {
... | 16 |
#include <bits/stdc++.h>
using namespace std;
inline void solve() {
int n, m;
cin >> n >> m;
vector<pair<int, int>> a;
map<int, multiset<pair<int, int>, greater<pair<int, int>>>> dest;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
x--, y--;
int dist = 0;
if (y >= x)
dist += ... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct PERSON {
int r, a;
friend bool operator<(PERSON a, PERSON b) { return a.r > b.r; }
};
PERSON p[100010], p0[100010];
struct ASK {
int x, y, pos;
friend bool operator<(ASK a, ASK b) { return p0[a.x].r > p0[b.x].r; }
};
ASK ask[100010];
int tree[100010 << 4];
in... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n, c[510], dp[510][510];
int solve(int l, int r) {
int i, j, k, ans = 10000007;
if (l == r) return dp[l][r] = 1;
if (l > r) return 1007;
if (dp[l][r] == -1) {
ans = 1 + solve(l + 1, r);
if (c[l] == c[l + 1]) {
int sm = 1;
if (l + 2 <= r) sm +... | 11 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> renum;
int z[7001], n, m, u, q, t, e, l, r, v, x;
vector<tuple<int, int, int>> y[7001];
int main() {
ios::sync_with_stdio(0);
for (q = 1, cin >> n >> m; cin >> t; ++q)
if (t & 1) {
cin >> v >> l >> r >> x;
y[v].emplace_back(l, r, renum.coun... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, g[4][1500000], co[4][4], inv;
long long m0, m1, m2, m3, mid, ans, ans1, M;
long long mul(long long a, long long b) {
long long ans = 1;
a %= 1000000007;
while (b) {
if (b & 1) ans = ans * a % 1000000007;
a = a * a % 1000000007;
b >>= 1;
}... | 21 |
#include <bits/stdc++.h>
using namespace std;
int n, m, V, d[100005];
bool Volunteer[100005];
vector<int> a[100005];
bool maximize(int &a, int b) {
if (a < b)
a = b;
else
return false;
return true;
}
bool minimize(int &a, int b) {
if (a > b)
a = b;
else
return false;
return true;
}
int bfs(i... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, x, y, cnt;
int arr[200500];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
;
cin >> n;
for (int i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n);
for (int i = 1, j = 0; i <= n; i++) {
while (j < n) {
if (i <= arr[j++]) {
... | 2 |
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int MAXN=100005;
int a[MAXN];
int main(){
int T; scanf("%d",&T);
while(T--){
int n; scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
a[n+1]=2147483647;
int ans=0;
for(int i=n;i>=1;i--){
if(a[i]!=a[i+1]) ans++;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int sg[100010], vis[500];
void init() {
sg[1] = 0, sg[2] = 1;
for (int i = 3; i <= 20; ++i) {
memset(vis, 0, sizeof vis);
for (int j = 1; j < i; ++j) {
vis[sg[j] ^ sg[i - j]] = 1;
}
for (int j = 0; j < 20; ++j) {
if (!vis[j]) {
sg[i] ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
scanf("%lld", &n);
long long main[n + 1], other[n + 1];
main[0] = 1;
other[0] = 0;
for (long long i = 1; i <= n; ++i) {
main[i] = (other[i - 1] * 3) % 1000000007;
other[i] = (2 * other[i - 1] + main[i - 1]) % 1000000007;
}
p... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int c0 = 0, c1 = 0, c2 = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '0')
c0++;
else if (s[i] == '1')
c1++;
else
c2++;
}
int rep = n / 3;
int ans = 0;
if (c0 < rep) {... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500;
int node[N][N], in[N][N];
int a[N];
vector<pair<int, int>> g[N][N];
short ans[N][N], lol, col[200 * N + 1], ten[5];
void fill(int at, int num, int freq) {
if (!at && !freq) {
a[lol] = num;
col[num] = lol++;
return;
}
if (!at) return;
f... | 18 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:640000000")
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int maxn = (int)2e5 + 10;
int n;
vector<int> g[maxn];
int a[maxn];
int cnt[maxn];
int dp[maxn];
int up[maxn];
int res;
bool good[maxn];
void dfs(int v, int p) {
dp[v] ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, s;
int main() {
scanf("%d", &s);
scanf("%d%d%d", &a, &b, &c);
if (!a && !b && !c)
puts("0.0 0.0 0.0");
else
printf("%.10lf %.10lf %.10lf", 1. * a / (a + b + c) * s,
1. * b / (a + b + c) * s, 1. * c / (a + b + c) * s);
}
| 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 50010;
const long long Limit = 0x7fffffffffffffff;
int N, M;
long long G, S;
long long res = Limit;
struct Edge {
int x, y;
long long g, s;
} e[maxn], tmp[maxn];
bool mycomp(const Edge& l, const Edge& r) {
return (l.g == r.g) ? (l.s < r.s) : (l.g < r.... | 14 |
#include <bits/stdc++.h>
inline int read() {
int res = 0;
bool bo = 0;
char c;
while (((c = getchar()) < '0' || c > '9') && c != '-')
;
if (c == '-')
bo = 1;
else
res = c - 48;
while ((c = getchar()) >= '0' && c <= '9')
res = (res << 3) + (res << 1) + (c - 48);
return bo ? ~res + 1 : res... | 20 |
#include <bits/stdc++.h>
using namespace std;
char s[2000000 * 2 + 10];
int n, len[2000000 * 2 + 10], cnt[2000000 + 1], ans, tot;
void read() {
scanf("%d%s", &n, s);
int i;
s[n * 2 + 2] = '$';
s[n * 2 + 1] = '#';
for (i = n - 1; i >= 0; i--) {
s[i * 2 + 2] = s[i];
s[i * 2 + 1] = '#';
}
s[0] = '@';... | 21 |
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::max;
using std::min;
using std::pair;
using std::swap;
using std::vector;
using ll = long long;
void testc() {
int n;
cin >> n;
vector<pair<int, int> > v(n);
for (auto &[first, second] : v) cin >> first >> second;
ll ans = l... | 9 |
#include <bits/stdc++.h>
using namespace std;
int sum, n, m, a, b, ans[300005], flag;
vector<int> v[300005];
int main() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
for (int i = 1; i <= n / 2; i++) {
ans[i] = 1;
}
while (1) {
flag... | 14 |
#include <bits/stdc++.h>
const long long mod = 1000000007;
struct Point {
long long k, b;
} point[300100];
struct Edge {
long long to, nxt, weigh;
} edge[600100];
long long head[300100], deg[300100], n, cnt;
void addedge(long long x, long long y, long long z) {
edge[++cnt].to = y;
edge[cnt].weigh = z;
edge[cn... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int t, n, d[N], b[N];
char a[N];
vector<int> v[N];
vector<int> gao(int sta) {
priority_queue<int> q;
for (int i = 1; i <= n; i++) {
b[i] = d[i];
if (!b[i]) q.push(i * sta);
}
vector<int> ans(n + 1, 0);
int cnt = 0;
while (!q.empty... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int z = 0, x, y, i, n = 0;
cin >> n;
while (n--) {
y = 0;
for (i = 0; i < 3; i++) {
cin >> x;
y += x;
}
if (y > 1) z++;
}
cout << z;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, d[5], a[5], ans, ans1, mix;
vector<pair<int, int> > v = {{1, 1}, {2, 2}, {3, 3}, {1, 3}, {2, 1}, {3, 2}};
bool b[200005];
void solve(int a1) {
if (a1 == 7) {
mix = max(mix, ans);
return;
}
for (int i = 0; i < 6; i++) {
if (b[i] == false) {
b[i... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, i, j, k, x, res = 0, sum = 0;
int a[100007], b[100007];
std::vector<int> v;
int main() {
int c, v, v1, a, l, i;
cin >> c >> v >> v1 >> a >> l;
for (i = 0;; i++) {
c -= min(v1, v + (i * a));
if (i != 0) c += l;
if (c <= 0) {
cout << i ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int main() {
int Begin, End, up, down;
scanf("%d%d%d%d", &Begin, &End, &up, &down);
int day0 = 8 * up;
int day;
if (up - down <= 0) {
if (End - Begin - day0 <= 0)
day = 0;
else
day = -1;
} else {
if (End - Be... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
stack<pair<long double, int> > S;
int a[maxn];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
S.push(make_pair((long double)a[0], 1));
for (int i = 1; i < n; i++) {
pair<long double, int> t = S.top();
if (... | 13 |
#include <bits/stdc++.h>
int n, ans = 0x7fffffff, a[1000 + 5];
int check(int t) {
int r = 0;
for (int i = 1; i <= n; i++) {
if (a[i] < t) r += t - 1 - a[i];
if (a[i] > t) r += a[i] - (t + 1);
}
return r;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, x, i, cnt;
double sum;
vector<pair<int, bool> > v;
int main() {
while (cin >> n) {
for (v.clear(), sum = 0.0, i = 0; i < n; ++i) {
cin >> x;
sum += x;
v.push_back(make_pair(x, false));
}
for (cnt = i = 0; i < n; ++i)
if ((sum - v... | 4 |
#include <bits/stdc++.h>
using namespace std;
void Solve() {
long long l, r, m;
cin >> l >> r >> m;
long long a = 0, b = 0, c = 0;
for (long long i = l; i <= r; i++) {
long long rem = m % i;
long long rem1 = i - rem;
if (rem1 <= r - l) {
a = i;
b = l;
c = rem1 + l;
break;
... | 7 |
#include <bits/stdc++.h>
const int MAXN = 100000;
const int LARGESTN = 1000000;
const int mod = 1000000007;
int num[LARGESTN];
int tree[LARGESTN + 1];
int a[MAXN + 1], val[MAXN + 1], pre[MAXN + 1];
void update(int x, int v) {
for (++x; x <= LARGESTN + 1; x += x & -x) {
tree[x - 1] += v;
if (tree[x - 1] >= mod... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k;
cin >> k;
cout << 2 << " " << 3 << endl;
cout << 131072 + k << " " << 131072 << " " << 0 << endl;
cout << k << " " << 131072 + k << " " << k << endl;
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k1, k2, c1 = 0, c2 = 0, a, b;
queue<int> q1, q2;
cin >> n >> k1;
while (k1--) {
cin >> a;
q1.push(a);
}
cin >> k2;
while (k2--) {
cin >> a;
q2.push(a);
}
while ((!q1.empty()) && (!q2.empty())) {
a = q1.front();
q... | 6 |
#include <bits/stdc++.h>
using namespace std;
#define dbg(x...) \
do { \
cout << #x << " -> "; \
err(x); \
} while (0)
void err() {
cout << endl;
}
template<class T, class... Ts>
void err(const T &arg, const Ts &... args) {
cout << arg <<... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
long long int all = 21;
bool _ok = false;
for (long long int i = 1; i <= 6; ++i) {
if (n == (all - i)) {
_ok = true;
break;
} else {
if (n > ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int ra[8] = {1, 2, 9, 64, 625, 7776, 117649, 2097152}, MD = 1000000007;
int main() {
int n, k;
cin >> n >> k;
long long r = ra[k - 1];
for (int i = 0; i < n - k; ++i) {
r *= n - k;
r %= MD;
}
cout << r << '\n';
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
inline char get(void) {
static char buf[100000], *p1 = buf, *p2 = buf;
if (p1 == p2) {
p2 = (p1 = buf) + fread(buf, 1, 100000, stdin);
if (p1 == p2) return EOF;
}
return *p1++;
}
inline void read(int &x) {
x = 0;
static char c;
for (; !(c >= '0' && c <... | 14 |
#include <bits/stdc++.h>
using namespace std;
char grid1[100][100];
int grid[100][100];
int n, m, k;
int N;
char C;
bool flag;
void incC() {
C++;
if (C > 'z') C = 'a';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tt;
cin >> tt;
while (tt--) {
cin >> n >> m >> k... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename U, typename V>
void Min(U &a, const V &b) {
if (a > b) a = b;
}
template <typename U, typename V>
void Max(U &a, const V &b) {
if (a < b) a = b;
}
template <typename U, typename V>
void add(U &a, const V &b) {
a = (a + b) % 1000000007;
}
template <t... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n;
struct node {
int id, x;
} l[300005], r[300005];
inline bool cmp(node a, node b) { return a.x < b.x; }
int main() {
int i, ans;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d%d", &l[i].x, &r[i].x);
l[i].id = r[i].id = i;
}
sort(l + 1, l + n... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long SIZE = 1e5 + 1;
const long long INF = 1e9;
long long a[7], n, b[SIZE], ctd[SIZE];
signed main() {
for (long long i = 0; i < 6; i++) {
cin >> a[i];
}
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> b[i];
}
vector<pair<long long, long ... | 11 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 0x3f3f3f3f;
const int maxn = 3e5 + 5;
int n;
int a[maxn];
int mn[maxn * 4];
void build(int i, int L, int R) {
if (L == R) {
mn[i] = a[L];
return;
}
int mid = (L + R) >> 1;
build(i << 1, L, mid);
build((i << 1) | 1, mid... | 16 |
#include <bits/stdc++.h>
void print(int i, int j) { printf("%d %d\n", i, j); }
int main() {
int q, b, w;
scanf("%d", &q);
while (q--) {
int b, w;
scanf("%d %d", &b, &w);
if (w > 3 * b + 1 || b > 3 * w + 1) {
printf("NO\n");
continue;
}
printf("YES\n");
if (w <= b) {
for (... | 10 |
#include<iostream>
#include<cstdio>
using namespace std;
#define For(i,l,r) for(int i=l;i<=r;i++)
#define MAXN 101
int T,N,a[MAXN],x,y;
int getc(){char c=getchar();while(c!='0'&&c!='1')c=getchar();return c-'0';}
int main()
{
cin>>T;
while(T--)
{
cin>>N>>x>>y;For(i,1,N)a[i]=getc();
if(y>=0){cout<<N*(x+y)<<endl;co... | 2 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <queue>
#include <set>
using namespace std;
//for coding
typedef long long ll;
typedef long double ld;
#define all(x) x.begin(), x.end()
#define rd(x) for(auto &i : x) cin >> i;
#define rep(i, l, r) fo... | 10 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long get(long long n) {
long long ans = 0;
for (long long i = 2; i * i * i <= n; ++i) ans += n / (1ll * i * i * i);
return ans;
}
int main() {
long long m, n = -1;
cin >> m;
long long l = 0, r = 5e15;
while (l < r) {
long long mid... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int n, i, j, k, m, x, y, flag = 0;
cin >> n >> x >> m;
long long int l = x, r = x;
long long int a, b;
for (i = 0; i < m; i++) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m, h, sum, a[1005];
int main() {
cin >> n >> m >> h;
for (int i = 1; i <= m; ++i) {
cin >> a[i];
sum += a[i];
}
--a[h], --sum;
if (sum < n - 1) {
cout << -1;
return 0;
}
if (sum - a[h] < n - 1) {
cout << 1;
return 0;
}
double... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int x, y, a, b;
cin >> x >> y >> a >> b;
vector<pair<int, int>> ans;
for (int i = a; i <= x; ++i) {
for (int j = b; j <= y; ++j) {
if (i > j) {
ans.push_back(... | 3 |
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
cin >> s;
if (s.length() > 4)
for (int i = 1; i < s.length() - 3; i++) {
if (s[i] == 'd' && s[i + 1] == 'o' && s[i + 2] == 't') {
s[i] = '.';
s[i + 1] = '0';
s[i + 2] = '0';
}
}
if (s.length() > 3)
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, shock = 0;
cin >> n;
string c;
string s;
long long a[26];
for (long long(i) = 0; (i) < (26); (i)++) a[i] = 1;
long long ans = -1;
while (n--) {
cin >> c >> s;
if (... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
const int INF = ~0U >> 1;
int x[maxn];
int n;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &x[i]);
sort(x + 1, x + n + 1);
int l = 1, r = n;
int ans = INF;
for (int i = 1; i + (n - 2) / 2 + 1 <= n; i++) {
if... | 15 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, i, l, k;
int main() {
cin >> a >> b >> c;
for (i = 0; i <= c; i++) {
for (l = 0; l <= c; l++) {
if (a * i + b * l == c) {
cout << "Yes";
return 0;
}
}
}
cout << "No";
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
void solve(int tt, int t) {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
if (n <= 1) {
cout << "Alice" << endl;
return;
}
int lastl = 0, lastr = n - 1;
for (int i = 1; i < n; i++) {
if (a[i] > a[i - 1])
lastl ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long MAX = 1e18;
string s[1111];
long long p[1111];
long long n, m, i, j, g1, g2;
long long get(long long v) {
if (p[v] == v) return v;
p[v] = get(p[v]);
return p[v];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0)... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 51;
int n, m;
bool visa[N][N], visb[N][N];
int match1[N][N], match2[N][N];
int ans, flag;
int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
string alpha = "abcdefghijklmnopqrstuvwxyz";
const long long mod = 1e9 + 7;
const long long inf = 2e18 + 5;
const long long nax = 1010;
vector<unordered_set<long long>> g;
stack<long long> C;
stack<long long> UC;
vector<bool> visited(nax);
void dfs(long long u) {
visited[... | 11 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int n = 0, k = 1;
char ch = getchar();
while ((ch > '9' || ch < '0') && ch != '-') ch = getchar();
if (ch == '-') {
k = -1;
ch = getchar();
}
while (ch <= '9' && ch >= '0') {
n = n * 10 + ch - '0';
ch = getchar();
}
return... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000100;
const int INF = 1000000007;
int n, r;
int wyn = -1;
vector<int> stos;
vector<int> wynikowy;
void readData() { scanf("%d%d", &n, &r); }
void sprawdz(int g, int d, int dep) {
if (dep < 0) return;
int k;
if (dep == 0) {
if ((g == 1) && (d ==... | 13 |
#include <bits/stdc++.h>
using namespace std;
int f[100005], g[100005], h[100005];
map<int, int> maph;
bool vis[100005];
int main() {
int n, cntg;
scanf("%d", &n);
int m, last = 0;
cntg = 1;
for (int i = 1; i <= n; i++) {
scanf("%d", &f[i]);
if (f[i] == i) {
vis[f[i]] = 1;
}
}
m = 0;
f... | 9 |
#include <bits/stdc++.h>
using namespace std;
int break_point() {
char c;
while ((c = getchar()) != '\n')
;
return 0;
}
template <typename T>
void read_integer(T &r) {
bool sign = 0;
r = 0;
char c;
while (1) {
c = getchar();
if (c == '-') {
sign = 1;
break;
}
if (c != ' ' &... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long double PI = acosl(-1);
const long long infl = 1e15;
const int inf = 2e9;
const int nmax = 1e5 + 10;
const int MAXLG = log2(nmax) + 1;
int n, m;
int dp[nmax];
vector<pair<int, int> > renj;
int rec(int pos) {
if (pos > m) return 0;
int ... | 14 |
#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... | 17 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
long long t, n, i, j, k, l, m, a, b;
cin >> n >> m >> a >> b;
cout << a << " " << b << "\n";
for (i = b - 1; i >= 1; i--) {
cout << a << " " << i << "\n";
}
for (i = b + 1; i <= m; i++) cout << a << " " << i << "\n";
for (i = a - 1; i >= 1... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 998244353;
const long double eps = 1e-10;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 ... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void print_vector(vector<T> &_arg_vector) {
int SIZE_VECTOR = _arg_vector.size();
for (int i = 0; i < SIZE_VECTOR; i++) cout << _arg_vector[i] << " ";
;
cout << endl;
;
}
int s[1000];
bool is_prost(int &_arg_number) {
int SQROOT = sqrt(_arg_nu... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long p, q, b;
int n;
cin >> n;
while (n--) {
cin >> p >> q >> b;
long long x = p / gcd(p, q);
long long y = q / ... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
long long ma;
long long ans[10];
typedef struct {
long long t[7];
} PP;
PP a[100005];
PP tree[4 * 100005];
PP build(long long i, long long l, long long r) {
if (l == r) {
tree[i] = a[l];
return tree[i];
}
PP le, ri;
long long mid = (l + ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5555;
const int INF = (1 << 30);
int f[N], b[N], a[N];
int n, m, c[N], v[N], base[N];
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int calc(int c) {
int res = 0;
for (int i = 1; i <= m; i++) {
while (c % b[i] == 0) {
... | 10 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.