solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 9;
int dep[N], ver[N << 1], nxt[N << 1], h[N], tot;
int n, dfn[N], fa[N][23], top, pos[N];
long long g[N];
vector<int> vec[N];
pair<int, int> stk[N];
inline void add(int x, int y) { ver[++tot] = y, nxt[tot] = h[x], h[x] = tot; }
void dfs(int u, int f) {
... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e6 + 10;
int a[MAX_N];
int b[MAX_N];
int res;
const int BUFSIZE = MAX_N;
char buf[BUFSIZE + 1];
string nextString() {
scanf("%s", buf);
return buf;
}
int main() {
int n;
cin >> n;
map<int, int> m;
size_t mx = 0;
size_t cnt = 0;
for (int i ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const long long INF = 1e16 + 69;
int n, q;
long long a[N], d[N], f[N];
void update(int p, long long v) {
while (p < N) f[p] += v, p += p & -p;
}
long long get(int p) {
long long ret = 0;
while (p) ret += f[p], p -= p & -p;
return ret;
}
long lo... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long n, m;
cin >> n >> m;
unsigned long long a, b, s = 0, s1[n], s2[m], c = 0;
for (unsigned long long i = 0; i < n; i++) {
cin >> a;
s += a;
s1[i] = s;
}
s = 0;
for (unsigned long long i = 0; i < m; i++) {
cin >> b;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, e;
string s, t;
while (cin >> a >> s) {
c = 0;
for (b = 0; b < a; b++) {
if (s[b] == '-') {
if (c >= 1) {
c--;
}
} else {
c++;
}
}
cout << c << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 1e3 + 4;
const int maxm = 1e6 + 4;
const double pi = acos(-1.0);
int n, m, limit;
int w[maxn], b[maxn];
int f[maxn];
int find(int a) {
if (a == f[a]) return a;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 3 * 1e5 + 10, mod = 1e9 + 7;
long long fact[N], inv[N], cnt[N], psum[N], comb[N], n;
bool npr[N];
vector<int> prime[N];
long long power(long long a, long long b) {
if (b == 0) return 1LL;
long long ret = power(a, b / 2);
ret *= ret;
ret %= mod;
... | 23 |
#include <bits/stdc++.h>
using namespace std;
void Debug() { cout << '\n'; }
template <class FIRST, class... REST>
void Debug(FIRST arg, REST... rest) {
cout << arg << " ";
Debug(rest...);
}
template <class T>
ostream& operator<<(ostream& out, const vector<T>& v) {
out << "[";
if (!v.empty()) {
for (int i =... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.14159265359;
const long long MAXN = 1e6 + 9;
const long long mdl = 1000000007LL;
int v[1000000], f[1000000];
int main() {
double x, y, x1, y1, r, ln = 0;
cin >> r >> x >> y >> x1 >> y1;
ln = sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y));
c... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e9 + 1;
const int N = (int)1e5 + 77;
const long long mod = (long long)1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, a[N], k = (int)1e6;
cin >> n;
for (int i = 0; i < (int)(n); ++i) cin >> a[i... | 3 |
#include <bits/stdc++.h>
inline long long Power(int b, int p) {
long long ret = 1;
for (int i = 1; i <= p; i++) ret *= b;
return ret;
}
using namespace std;
struct comp {
bool operator()(const pair<int, int> &a, const pair<int, int> &b) {
return a.second > b.second;
}
};
int gcd(int a, int b) {
if (b ==... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const int mod = 1e9 + 7;
const int Lim = 1e5 + 1e3;
const double eps = 1e-15;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
int n;
cin >> n;
int temp = n / 2;
for (int i = (int)temp, _a = (int)1; i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[102], i, j, f[102], max = -1, flip = 200, ans = 0, d;
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d", &a[i]);
f[0] = a[0] ? -1 : 1;
for (i = 1; i < n; i++) f[i] = a[i] ? f[i - 1] - 1 : f[i - 1] + 1;
for (i = 0; i < n; i++)
for (j =... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
int n, m;
char a[105][105];
bool del[105];
int main() {
int ans = 0;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf(" %s", a[i] + 1);
}
for (int i = 1; i < n; i++) {
for (int j = 1; j <= m; j++) {
if (del[j])... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, base = 2, carry = 0;
vector<int> x, y;
cin >> a >> b;
while (a > 0) {
if (a % 10 >= base) base = a % 10 + 1;
x.push_back(a % 10);
a /= 10;
}
while (b > 0) {
if (b % 10 >= base) base = b % 10 + 1;
y.push_back(b % 10);
... | 7 |
#include <bits/stdc++.h>
int n;
int a[1500 + 1];
int Q;
bool ans;
void read() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
}
void chief() {
ans = 0;
for (int i = 2; i <= n; ++i)
for (int j = 1; j < i; ++j)
if (a[j] > a[i]) ans ^= 1;
scanf("%d", &Q);
for (int q = 1; q <= Q; +... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long b, q, l, m;
int bad[101010];
int cnt;
int main() {
cin >> b >> q >> l >> m;
for (int i = 0; i < m; i++) scanf("%d", &bad[i]);
sort(bad, bad + m);
long long first_b = b;
long long tmp = 0;
bool zcheck = false;
while (1) {
if (abs(b) > l) break;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
multiset<pair<int, int>> lr, rl, cp;
for (int i = 0; i < n; ++i) {
int l, r;
scanf("%d %d", &l, &r);
lr.insert({l, r});
rl.insert({r, l});
}
cp = lr;
int res = 0;
for (auto p : cp) {
pair<int, int> pp = {p.se... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, q;
vector<int> v[60];
inline int ch(char c) { return (c - 'a' + 1); }
int dfs(int depth, int s) {
if (depth == n) return s == 1;
int res = 0;
for (int i = 1; i <= 6; ++i) {
int p = s * 6 + i;
if (v[p].size() == 0) continue;
res += dfs(depth + 1, v[p... | 5 |
#include <bits/stdc++.h>
using namespace std;
string s;
int a[30];
int main() {
cin >> s;
int l = s.length();
for (int i = 0; i < l; i++) a[s[i] - 'a']++;
for (int i = 25; i >= 0; i--)
if (a[i] > 0) {
for (int j = 0; j < a[i]; j++) cout << char(i + 'a');
return 0;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int mxn = 64;
int bits[mxn + 2];
long long solve(long long n) {
long long ret = 0;
for (int i = 0, idx; i < mxn; ++i) {
if (n >> i & 1) {
for (idx = i; idx < mxn && bits[idx] == 0; ++idx)
;
if (idx == mxn) return -1;
for (; idx > i; -... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int i, c = 0;
int a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 1; i < (n - 1); i++) {
if (a[i] > a[i - 1] && a[i] > a[i + 1]) {
c++;
}
if (a[i] < a[i - 1] && a[i] < a[i + 1]) {
c++;
}
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100007;
struct edge {
int c;
int *p;
} e[maxn];
int vis[maxn][3];
int color[maxn];
bool rch[maxn];
bool is_DAG = 1;
void dfs(int u, int st) {
for (int i = 1; i <= e[u].c; i++) {
if (!vis[e[u].p[i]][(st + 1) % 2]) {
vis[e[u].p[i]][(st + 1) % ... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long a[1000];
int main() {
int n, k, m;
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
int m1[200], m2[200];
for (int l = 0; l < 200; l++) m1[l] = m2[l] = 0;
for (int l = 0... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const double EPS = 1e-9;
const int N = 2e5 + 9;
int n, a[N], sum[N][205];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
cin >> n;
map<int, int> m;
set<int> s;
int mx = 0;
for (i... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int NL = 26;
void init_nr(int v[]) {
for (int i = 0; i < NL; i++) {
v[i] = 0;
}
}
int maxim(int v[]) {
int r = v[0];
for (int i = 1; i < NL; i++) {
r = max(r, v[i]);
}
return r;
}
int calcul(int n, int k, string s) {
int nr[NL];
int rez = 0;
... | 7 |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
int n, m, q;
int a[505][505];
int b[505][505];
char s[505][505];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
scanf("%d%d", &n, &m);
for (... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 3 * 1000 * 100 + 300;
const int maxL = 26;
pair<int, int> a[maxN];
int seg[maxL][maxN];
int n;
inline void makeTree(int xl = 0, int xr = n, int id = 0) {
if (xr - xl == 1) {
seg[id][xl] = a[xl].second;
return;
}
int xm = (xl + xr) >> 1;
make... | 14 |
#include <bits/stdc++.h>
const int maxn = 1000100;
using namespace std;
char s[100100], t[100100];
int main() {
cin >> s >> t;
int len = strlen(s);
int ans = 0;
for (int i = 0; i < len; i++) {
if (s[i] != t[i]) ans++;
}
if (ans % 2)
printf("impossible");
else {
ans /= 2;
for (int i = 0; i ... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct Stupid {};
int leftChildrenMax[101];
int leftChildrenMin[101];
int rightChildrenMax[101];
int rightChildrenMin[101];
vector<int> output;
void print(int i) {
if (leftChildrenMin[i] < i + 1) throw Stupid();
leftChildrenMin[i] = i + 1;
if (leftChildrenMin[i] <= le... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long n, sum;
int k, x;
int main() {
cin >> n >> k;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
bool f = true;
sort(a, a + n);
x = a[0] % k;
for (int i = 1; i < n; i++) {
if (a[i] % k != x) f = false;
}
if (f == false)
cout << "-1";
el... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long ax, ay, bx, by, xs, ys, t, n;
long long x[75], y[75], sum, ans = 0;
int main() {
scanf("%lld%lld%lld%lld%lld%lld", &x[0], &y[0], &ax, &ay, &bx, &by);
scanf("%lld%lld%lld", &xs, &ys, &t);
while (++n) {
x[n] = ax * x[n - 1] + bx, y[n] = ay * y[n - 1] + by;... | 9 |
#include <bits/stdc++.h>
using namespace std;
int q, x, y[500010], num[500010], ans;
int main() {
scanf("%d%d", &q, &x);
int p = 0;
for (int i = 1; i <= q; ++i) {
scanf("%d", &y[i]);
++num[y[i] % x];
while (num[ans % x]) {
--num[ans % x];
++ans;
}
printf("%d\n", ans);
}
return ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, x, V[1005], len, A[1005], F[1005];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> V[i];
for (int i = 1; i <= m; i++) {
cin >> A[i];
len += A[i];
}
for (int i = 1; i + len - 1 <= n; i++) {
for (int j = 1; j <= m; j++) F[j] = A... | 7 |
#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = 1 << 29;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int& n, int b) { n |= two(b); }
inline void unset_bit(int& n, int b... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int max_n = 100111;
const int p1 = 31, mod1 = 1000000007;
const int p2 = 41, mod2 = 1000000123;
const char min_c = '?';
int n, ans, H1[2], H2[2];
string s, t;
int h1_h[2][max_n], h1_pw[2][max_n], Mod1[2];
int h2_h[2][max_n], h2_pw[2][max_n], Mod2[2];
void Hash_1_0(str... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e5 + 10;
const long long INF = 0x3f3f3f3f3f3f3f3f;
int n;
struct point {
long long x, y;
} ps[MAXN];
long long a[MAXN], sum[MAXN], ans;
inline void init() {}
inline void input() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%lld", &a[i]... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
printf("YES\n");
scanf("%d", &n);
while (n--) {
int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d);
if ((a & 1) && (b & 1))
printf("1\n");
else if (!(a & 1) && (b & 1))
printf("2\n");
else if ((a & 1) && !(b & 1))
... | 13 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
char ch = getchar();
int nega = 1;
while (!isdigit(ch)) {
if (ch == '-') nega = -1;
ch = getchar();
}
int ans = 0;
while (isdigit(ch)) {
ans = ans * 10 + ch - 48;
ch = getchar();
}
if (nega == -1) return -ans;
return ans... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[7], j = 0;
cin >> n;
for (int i = 0; i < 7; i++) cin >> a[i];
while (n > 0) {
if (j > 6) j = 0;
if (a[j] >= n)
break;
else
n -= a[j++];
}
cout << j + 1;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265;
void mysolution() {
int n;
cin >> n;
if (n == 1) {
cout << "a" << '\n';
return;
}
for (int i = 0; i < n / 2; i++) {
cout << "a";
}
cout << "b";
for (int i = 0; i < (n / 2) - 1; i++) {
cout << "a";
}
if (n % 2... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5002;
int n, m, fn[maxn], wh[maxn], ti = 1, dp[maxn], dg[maxn], ans, dis[maxn];
bool vis[maxn], inst[maxn];
stack<int> st;
vector<int> graph[maxn];
vector<pair<int, int>> comp[maxn];
queue<int> q;
void bfs(int s) {
for (int i = 1; i <= n; i++) dis[i] = ma... | 21 |
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007, LIM = 4294967295;
long long int n, m, a, b, c, d, q, k, tr, summ, ans, minx, maxx, l, r, mid, l1,
r1, mid1, res, mass1[1000000], mass2[1000000], mass[1000000];
string s, trs, str, ss;
set<long long int> g, bb, all;
set<long long int... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int power_mod(long long int a, long long int x) {
if (x == 0) return 1;
long long int y = power_mod(a, x / 2);
long long int ans = (y * y) % 1000000007;
if (x % 2) ans = (ans * a) % 1000000007;
return ans;
}
long long int inv(long long int a) { return po... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long fact[20];
long long calc_simple(const vector<int>& cnt) {
long long sum = 0;
for (auto& x : cnt) {
sum += x;
}
long long ret = fact[sum];
for (auto x : cnt) {
ret /= fact[x];
}
return ret;
}
long long calc(vector<int> cnt) {
if (cnt[0] == 0... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, m, p, dp[305][305];
vector<pair<int, int> > a[90005];
template <class T>
inline void RD(T &a) {
register int ch = getchar();
bool ng = 0;
for (; ch < '0' || ch > '9'; ch = getchar())
if (ch == '-') ng = 1;
for (a = 0; ch >= '0' && ch <= '9'; ch = getchar(... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long max_n = 2e5 + 5;
const long long log_n = 20;
const long long inf = 1e17 + 6;
const long long K = 1000;
std::mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
struct node {
long long tag = -1, sum = 0, mn = ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxl = 2 * 1000 * 10 + 5;
const int maxm = 10 + 5;
bool adj[maxl][maxm];
int n, m, k;
int grp[maxm], node[maxl];
int main() {
cin >> n >> m >> k;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) cin >> adj[i][j];
for (int i = 0; i < k; i++) {
... | 5 |
#include <bits/stdc++.h>
int main() {
long long int min;
long long int n, a, b, c;
scanf("%I64d%I64d%I64d%I64d", &n, &a, &b, &c);
if (n % 4 == 1) {
min = a * 3;
if (a + b < min) {
min = a + b;
}
if (c < min) {
min = c;
}
printf("%I64d\n", min);
} else if (n % 4 == 2) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0;
char ch = getchar();
bool d = 1;
for (; !isdigit(ch); ch = getchar())
if (ch == '-') d = 0;
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
return d ? x : -x;
}
inline unsigned long long rnd() {
return ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, ans(0);
cin >> n >> m;
for (int i = 0; i <= n; i++) {
int cur = i, leftn = n - i, leftm = m - 2 * i;
if (leftm >= 0) {
cur += min(leftm, leftn / 2);
ans = max(ans, cur);
}
}
cout << ans;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
long long t[200005], nt[200005], cost[200005], r[200005];
int main() {
int n, k;
long long b, c;
cin >> n >> k >> b >> c;
b = min(b, 5 * c);
for (int i = 0; i < n; i++) cin >> t[i];
sort(t, t + n);
for (int i = 0; i < n; i++) r[i] = (t[i] % 5 + 5) % 5;
long ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, p, q, c, i, j, sum = 0, cnt = 0, ans, res;
cin >> n >> m;
vector<long long> a(105, 0);
for (i = 1; i <= m * 2; i += 2) {
cin >> p >> q;
for (j = p; j <= q; j++) a[j]++;
}
for (i = 1; i <= n; i++) {
if (a[i] != 1) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct Node {
using pnode = Node *;
T val;
int prior, size, id;
pnode l, r;
int pairings_including_me;
int pairings_excluding_me;
Node(int _val, int pri, int idx)
: val(_val), id(idx), prior(pri), size(1), l(nullptr), r(nullptr) {
... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
float pi = 3.14159265358979323846;
int n, r;
cin >> n >> r;
cout << fixed << setprecision(std::numeric_limits<long double>::digits10 + 1)
<< r * (sin((2 * pi) / n)) /
((2 * (sin((n - 2) * pi / (2 * n))) - sin((2 * pi) / n)));
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2111;
const int mod = 1e9 + 7;
const int mod2 = 998244353;
const int base = 443;
inline void add(int& x, int y) {
x += y;
if (x >= mod) x -= mod;
}
namespace HS {
int pw[maxn], pw2[maxn];
void prework() {
pw[0] = pw2[0] = 1;
for (int i = 1; i < maxn... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e3 + 5;
int n, k;
int a[MAX];
int best[MAX];
bool ok(long long limit) {
for (int i = int(1); i < int(n + 1); i++) {
best[i] = i - 1;
for (int j = int(1); j < int(i); j++) {
long long distance = abs(a[i] - a[j]);
if (distance <= (i - j)... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
long long int num[500005], pre[500005];
int main() {
long long int n, k;
while (cin >> n >> k) {
if (k == 1) {
printf("%d\n", n);
continue;
}
long long int sum = 0;
for (int i = 1; i <= n; i++) pre[i] = 1... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long INF = 1e18 + 10;
long double eps = 1e-9;
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
cout.tie(0);
int n;
cin >> n;
vector<int> v(n);
vector<int> pref1(n, 0), last2(n, 0);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
for (int i = 0; i <... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 10;
struct Item {
int id, value, mValue;
Item() : id(), value(), mValue() {}
Item(int _id, int _value, int _m) : id(_id), value(_value), mValue(_m) {}
bool operator<(const Item &x) const {
return value < x.value || (value == x.value && i... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b;
cin >> a >> b;
long long numa = a / 5;
long long numb = b / 5;
long long rea = a % 5;
long long reb = b % 5;
long sumrem = rea + reb;
if (sumrem >= 5) {
sumrem -= 4;
} else {
sumrem = 0;
}
long long ans = 5 * numa *... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
c b, e;
};
template <class c>
rge<c> range(c i, c j) {
return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
template <class c>
debug& operator<<(const c&... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int money, money1, z, x, y;
while (scanf("%d", &money) != EOF) {
if (money < 0) {
x = abs(money) % 10;
y = abs(money / 10) % 10;
money1 = money / 100;
z = min(x, y);
cout << money1 * 10 - z << endl;
} else
cout <<... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int NUM = 1e5 + 5;
const int mod = 1e9 + 7;
long long INF = 1e12;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
long long n, k;
cin >> n >> k;
long long ans = 8 * n / k + min(1ll, 8 * n % k);
ans += 5 * n / k + min(1ll, 5 * n % k);
ans += 2 *... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 200000 + 5;
char s[SIZE];
int ex, ey;
int xSum[SIZE];
int ySum[SIZE];
int dx[200], dy[200];
bool judge(int n, int len, int ex, int ey) {
for (int i = 1; i + len - 1 <= n; ++i) {
int curx = xSum[i - 1] + xSum[n] - xSum[i + len - 1];
int cury = ySum... | 10 |
#include <bits/stdc++.h>
int main() {
long p, n;
scanf("%ld %ld\n", &p, &n);
std::vector<bool> taken(p, 0);
long output(-1);
for (int k = 1; k <= n; k++) {
long temp;
scanf("%ld\n", &temp);
if (taken[temp % p]) {
output = k;
break;
} else {
taken[temp % p] = 1;
}
}
pr... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000,100000000")
using namespace std;
const long long inf = 1e18 + 7;
const long long mod = 1e9 + 7;
const double eps = 1e-9;
const double PI = 2 * acos(0.0);
const double E = 2.71828;
long long ans = -inf;
long long n, u, r;
long long a[105][105], b[100005]... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
;
int i;
long long int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
int p, q, r, second;
bool flag = false;
for (i = 0; i < n; i++) {
cin >> p >> q >> r >> second;
if (q == r && fl... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline bool vowel(char c) {
return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y';
}
int main() {
int n;
scanf("%d", &n);
vector<int> p;
for (int i = 0; i < n; ++i) {
int a;
scanf("%d", &a);
p.push_back(a);
}
getchar();
for ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int K, n, ans, tim, cur, vis[maxn], ax[7], ay[7], p[7], bx[maxn], by[maxn];
vector<int> V[7][maxn];
int main() {
scanf("%d %d", &K, &n);
for (int i = 0; i < K; i++) {
scanf("%d %d", &ax[i], &ay[i]);
}
for (int i = 0; i < n; i++) {
scan... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 3e5 + 10;
long long n, t, a[maxn];
signed main() {
cin >> t;
while (t--) {
cin >> n;
for (long long i = 1; i <= n; i++) cin >> a[i];
long long flag = 1;
for (long long i = 1; i <= n; i++) {
long long ok = 0;
for (long l... | 5 |
#include <bits/stdc++.h>
using namespace std;
int dp[105][3];
int day[105];
int main() {
int n;
while (cin >> n) {
for (int i = 1; i <= n; i++) {
cin >> day[i];
}
memset(dp, 19961209, sizeof(dp));
dp[0][0] = 0;
dp[0][1] = 0;
dp[0][2] = 0;
for (int i = 1; i <= n; i++) {
dp[i][... | 6 |
#include <bits/stdc++.h>
using namespace std;
int row[1010];
int main() {
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
memset(row, 0x3f3f3f3f, sizeof row);
long long ans = 0;
for (int i = (0); i < (n); ++i) {
int r, c;
scanf("%d %d", &r, &c);
row[r] = min(c, row[r]);
}
for (int i = 1; i <= m; +... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mx = 3e5 + 5;
const int mod = 998244353;
int n, t1, t2;
int dp1[mx], dp2[mx], dp3[mx];
int pd1, pd2, pd3;
vector<int> adj[mx];
void dfs(int v, int p = -1) {
dp2[v] = 1, dp3[v] = 1;
for (auto u : adj[v]) {
if (u != p) {
dfs(u, v);
pd1 = (pd1 + (... | 16 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
t = 1;
while (t--) {
long long x, y;
cin >> x >> y;
if (y == 0 && x >= 0 && x <= 1) {
cout << "0";
} else if (x - y < 0 && x + y >= 0) {
cout << (... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353LL;
const int N = 2e5 + 10;
vector<int> L[N], R[N];
vector<int> kol;
vector<pair<int, int> > graf[N];
long long przed[N], po[N], gora[N], nie[N];
long long turn(long long a) {
int k = mod - 2;
long long ret = 1;
a %= mod;
while (k > 0)... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m1, m2;
bool vis[N];
struct UFS {
int fa[N], siz[N];
void init() {
for (int i = 1; i <= n; i++) fa[i] = i, siz[i] = 1;
}
int getFa(int x) {
int px = x, tmp;
while (fa[x] != x) x = fa[x];
while (px != x) tmp = px, px = fa... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int* a = new int[n];
for (int i = 0; i < n; i++) cin >> a[i];
bool swapped = false;
while (swapped == false) {
swapped = true;
for (int i = 1; i < n; i++) {
if (a[i - 1] > a[i]) {
swap(a[i - 1], a[i]);
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, sum, n, kl1 = 0, kl0 = 0;
cin >> t;
while (t--) {
cin >> n;
int* a = new int[n];
int* b = new int[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = 1;
}
if (n % 2 == 0) {
for (int i = 0; i < n - 1; i = ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, f[210][210];
int main() {
scanf("%d", &n);
f[1][1] = f[2][1] = 1;
for (int i = 3; i <= n + 1; i++)
for (int j = 1; j <= i; j++) {
if (j == 1)
f[i][j] = f[i - 1][j];
else
f[i][j] = (f[i - 1][j] + f[i - 2][j - 2]) & 1;
}
prin... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m;
cin >> n >> m;
long long int x = (n + 1) / 2;
if (m > x)
cout << 2 * (m - x) << endl;
else
cout << 2 * m - 1 << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int a[200005], b[200005], len, n;
long long c[200005];
long long ask(int x) {
long long ans = 0;
for (; x; x -= (x & -x)) {
ans += c[x];
}
return ans;
}
void add(int x) {
for (; x <= n; x += x & (-x)) {
c[x] += 1;
}
}
int main() {
int t;
scanf("%d", ... | 9 |
#include <bits/stdc++.h>
int main() {
int N, K;
scanf("%d %d", &N, &K);
if (N == 1) {
if (K == 0)
puts("1");
else
puts("-1");
return 0;
}
if (N / 2 > K)
puts("-1");
else {
int x = 1e9;
K -= (N - 2) / 2;
printf("%d %d", K, K * 2);
for (int i = 3; i <= N; i += 2) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct nide {
int x, y;
} b[1001];
int main() {
int n, m, k, i, j, sum = 0;
int a[1001];
scanf("%d", &n);
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
scanf("%d", &m);
for (j = 1; j <= m; j++) scanf("%d%d", &b[j].x, &b[j].y);
for (i = 1; i <= n; i++) sum += ... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int res = 0;
bool zf = 0;
char c;
while (((c = getchar()) < '0' || c > '9') && c != '-')
;
if (c == '-')
zf = 1;
else
res = c - '0';
while ((c = getchar()) >= '0' && c <= '9')
res = (res << 3) + (res << 1) + c - '0';
retur... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (auto &i : a) cin >> i;
vector<int> f(n + 1, -1);
for (int i = 0; i < n; ++i) f[a[i]] = i;
vector<int> who(n + 1, -1);
for (int i = 0; i <= n; ++i)
if (f[i] !... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int P = 1000 * 1000 * 1000 + 7;
int power(int n, long long k) {
int ans = 1;
for (int i = 60; ~i; i--) {
ans = 1LL * ans * ans % P;
if (k & (1LL << i)) ans = 1LL * ans * n % P;
}
return ans;
}
int main() {
ios_base ::sync_with_stdio(false), cin.tie(N... | 8 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const long double PI = 3.1415926535897932384626433832795;
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i < (int)(k); i++) {
for (int x = 1; x <= (int)(n - 1); x++) {
if ((n - x - 1) & (1 << i)) {
pr... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000, mod = 1000000007;
int n, num, ans;
int u[300010], prime[300010], mp[300010], a[300010], fac[300010],
inv_fac[300010], c[300010];
vector<int> w[300010];
int fpow(int i, int j) {
int ret = 1;
for (; j; i = (long long)i * i % mod, j /= 2)
i... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long jie[100000 + 100];
long long inv[100000 + 100];
long long poww(long long a, long long b) {
long long base = a;
long long res = 1;
while (b) {
if (b & 1) {
res *= base;
res %= mod;
}
base *= base;
base %= m... | 18 |
#include <bits/stdc++.h>
template <class T>
T gcd(T a, T b) {
T r;
while (b != 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
template <class T>
T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
template <class T>
T sqr(T x) {
return x * x;
}
template <class T>
T cube(T x) {
return x * x * x;
}
using... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300005, M = 998244353, L = 20;
int l[N], r[N], num[41][1 << L | 1], x[L], y[L], ans, vis[N], fac[N], inv[N],
cnt[N], n, m;
inline int ksm(int x, int y) {
int ans = 1;
for (; y; y >>= 1, x = (long long)x * x % M)
if (y & 1) ans = (long long)ans * x ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int MAXN = 100005;
int f[MAXN][205][2];
int a[MAXN];
int n;
inline void add(int &x, int y) { x = ((x + y) % MOD + MOD) % MOD; }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
f[0][0][0] = 1;
for (int i... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5;
int n, ans, x, a[N], was[N];
array<int, 2> c[N];
int main() {
cin >> n;
for (int i = 1; i < n + 1; ++i) {
cin >> a[i];
c[a[i]][0]--;
c[i][1] = i;
}
sort(c + 1, c + n + 1);
random_shuffle(c + min(n, 400), c + n + 1);
for (int i = 2;... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int N = (1e6);
int T[N << 2], A[N];
void update(int l, int r, int x, int y, int val, int p) {
if (x > r || y < l) return;
if (x <= l && y >= r) {
if (T[p] == -1) T[p] = val;
return;
}
if (T[p] != -1) {
if (T[p << 1] == -1) T[p << 1] = T[p];
if ... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long al[100005], dep[100005], col[100005], n, a, b, c, d, q, val0;
vector<long long> fen[100005], v[100005];
void upd(long long x, long long v) {
for (; x <= n; x += x & -x) al[x] += v;
}
long long que(long long x) {
long long ret = 0;
for (; x; x -= x & -x) ret ... | 13 |
#include <bits/stdc++.h>
const int inf = 1e9;
int T, ans, dir[4];
struct Point {
int x, y;
} a[4], b[4], sol[4];
bool operator<(const Point &u, const Point &v) {
return u.x == v.x ? u.y < v.y : u.x < v.x;
}
void update(int xl, int xr, int yl, int yr) {
if (xl > xr) {
std::swap(xl, xr);
}
if (yl > yr) {
... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int const N = 5005;
vector<int> gr[N];
vector<pair<long long, long long> > market[N];
int depth[N];
int n, m, w;
void insert(map<long long, long long> &setik, pair<long long, long long> m,
long long &tot, long long &cnt, int &k) {
setik[m.... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 7, NS = 5e3 + 7, lg = 20, sq = 550, inf = 1e9 + 7,
mod = 1e9 + 7;
const long double eps = 1e-7;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
vector<long long> c[N], t;
signed main() {
ios_base::sync_with_st... | 12 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int w = 1, s = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') w = -1;
ch = getchar();
}
while (isdigit(ch)) {
s = s * 10 + ch - '0';
ch = getchar();
}
return w * s;
}
struct node {
int next, to, w1, w2;
} e[... | 20 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.