solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
void build(int, int, int);
long long query(int, int, int, int, int);
void update(int, int, int, int, int, int);
void modify(int, int, int, int, int, int);
const int MAXN = 1e5 + 15;
int n, q;
pair<long long, long long> tree[MAXN << 2];
long long a[MAXN];
int32_t main() {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0, f = 1;
char c = getchar();
while ((c < '0' || c > '9') && (c != '-')) c = getchar();
if (c == '-') f = -1, c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
const int N = 3... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> v(n + 1);
for (int i = 1; i <= n; i++) cin >> v[i];
for (int i = k; i < n; i++) {
if (v[i] != v[i + 1]) {
cout << "-1";
return 0;
}
}
int val = v[k], i;
for (i = k - 1; i >= 0; i--) {
... | 2 |
#include <bits/stdc++.h>
const int mod = 1e9 + 7;
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
long long n;
cin >> n;
string s;
cin >> s;
vector<long long> prefix(n + 1);
for (long long i = 1; i <= n; i++) {
if (s[i - 1] == '?')
continue;
else if (s[i - 1] == s[i - 2] && i... | 2 |
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
constexpr static int mod = 1e9 + 7;
constexpr static int inf = (1 << 30) - 1;
constexpr static Int infll = (1LL << 61) - 1;
int Competitive_Programming =
(ios_base::sync_with_stdio(false), cin.tie(nullptr),
cout << fixed << setprecision(15), ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2001;
long long factorialNumInverse[N + 1];
long long naturalNumInverse[N + 1];
long long fact[N + 1];
void InverseofNumber(long long p) {
naturalNumInverse[0] = naturalNumInverse[1] = 1;
for (int i = 2; i <= N; i++)
naturalNumInverse[i] = naturalNumIn... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, s, ans;
int tot;
int pn[60], pm[60], ps[60], pri[60];
long long xp[60];
int vis[1000010];
inline void solve(int *cnt, int x) {
for (int i = 2; i * i <= x; i++)
if (x % i == 0) {
if (!vis[i]) vis[i] = ++tot, pri[tot] = i;
while (x % i == 0) ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int arr[505][505];
int now[505][505];
const int inf = 1e9 + 9;
int main() {
int q, e, f;
while (scanf("%d%d%d%d", &n, &m, &k, &q) == 4) {
memset(arr, -1, sizeof(arr));
for (int i = 0; i < q; i++) {
scanf("%d%d", &e, &f);
scanf("%d", &arr... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 212345;
using T2 = tuple<int, int>;
using T3 = tuple<int, int, int>;
priority_queue<T2> pc;
priority_queue<T3> sk;
int a[maxn], b[maxn];
int main(void) {
int n, m, cnt = 0, cost = 0;
scanf("%d %d", &n, &m);
for (int i = 0; ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e6 + 5;
const long long inf = 1791791791;
const long long mod = 1e9 + 7;
double x(double a, double h) {
a = a / 2.0;
double c = sqrt(a * a + h * h);
return (a * h) / c;
}
int main() {
double f;
scanf("%lf", &f);
for (int a = 1; a <= 10; a++) {
... | 5 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int N = 100009;
const int inf = 0x3f3f3f3f;
const long long oo = 0x3f3f3f3f3f3f3f3fll;
int n, m, k, a[N], vis[N];
struct Edge {
int a, b;
Edge(int a, int b) : a(a), b(b) {}
};
int p[N];
int find(int x) {
if... | 7 |
#include <bits/stdc++.h>
using namespace std;
typedef vector <int> vi;
int main()
{
long long int test,n,m,x;
cin >> test;
while(test--)
{
cin >> n >> m >> x;
x--;
cout << (x/n+1)+(x%n)*m << "\n";
}
return 0;
} | 0 |
#include <stdio.h>
#include <bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <vector>
namespace atcoder {
// Implement (union by size) + (path compression)
// Reference:
// Zvi Galil and Giuseppe F. Italiano,
// Data structures and algorithms for disjoint set union problems
struct dsu {
public:
... | 8 |
#include <bits/stdc++.h>
int main() {
int n, i, j, k;
scanf("%d", &n);
char a[100];
scanf("%s", a);
int m;
scanf("%d", &m);
char b[1001][52];
for (i = 0; i < m; i++) scanf("%s", b[i]);
int count[1001][52];
for (i = 0; i < m; i++)
for (j = 0; j < 51; j++) count[i][j] = 0;
int cnt = 0, val[1001]... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
constexpr int N = 1e3 + 5;
int a, b, ans = -1;
char v;
void Solve() {
cin >> v;
a = v - 'a';
cin >> v;
b = v - '1';
for (int i = -1; i < 2; i++)
for (int j = -1; j < 2; j++) {
ans ... | 0 |
#include <bits/stdc++.h>
using namespace std;
long double p[123456];
long double q[123456];
long double mx[123456];
long double mn[123456];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(7);
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> mx[i];
for (int... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, a1, a2, a3, a4, a5, a6;
scanf("%d%d%d", &a1, &a2, &a3);
scanf("%d%d%d", &a4, &a5, &a6);
if (a1 + a2 + a3 == a3 + a4 + a5 && a3 + a4 + a5 == a1 + a5 + a6) {
a = a1 + a2 + a3;
printf("%d", a * a - a1 * a1 - a3 * a3 - a5 * a5);
} else if (... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, q, r, t;
string s;
cin >> s;
int n;
cin >> n;
string a[n];
for (i = 0; i < n; i++) cin >> a[i];
int temp = 0;
for (i = 0; i < n; i++) {
if (a[i] == s) {
temp = 1;
cout << "YES";
break;
}
}
if (!temp) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long T;
long long n;
int main() {
ios::sync_with_stdio(false);
cin >> T;
while (T--) {
cin >> n;
if (n == 1)
cout << "0" << endl;
else
cout << ceil(2.0 * sqrt(n)) - 2 << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int ch[15100000][2], sum[15100000], cnt, root[65], n;
long long b[301000], bin[65], c[301000];
void insert(int &, long long);
long long query(int, long long);
int main() {
scanf("%d", &n);
for (int i = 0; i <= 62; i++) bin[i] = 1ll << i;
for (int i = 1; i <= n; i++) {... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d", &t);
long long a[100005], b[100005], c[100005];
while (t--) {
int first, second, z;
scanf("%d %d %d", &first, &second, &z);
for (int i = 0; i < first; i++) scanf("%lld", &a[i]);
for (int i = 0; i < second; i++) scanf("... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, i, x, p, y;
cin >> t;
while (t--) {
p = 1;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> x;
if (x % 2 == 0) {
y = i;
p = 0;
}
}
if (!p)
cout << 1 << endl << y << endl;
else if (n == 1... | 0 |
#include <bits/stdc++.h>
using namespace std;
void c_p_c() {}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n;
cin >> n;
unordered_map<long long int, long long int> mp;
for (long long int i = 1; i <= n; i++) cin >> mp[i];
for (long long int i = 1; i <= n; i++) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ar[n];
for (int i = 0; i < n; i++) cin >> ar[i];
map<int, int> m;
for (int i = 0; i < n; i++) m[ar[i]]++;
m[0] = 3;
map<int, int>::iterator it = m.begin(), tmp;
int ans = 0;
it++;
while (it != m.end()) {
int p = it... | 3 |
#include <bits/stdc++.h>
using namespace std;
namespace zzc {
const long long maxn = 1e5 + 5;
const long long mod = 1e9 + 7;
long long fac[maxn], inv[maxn], num[60], f[maxn], g[maxn], h[maxn], res[60][60];
char ch[maxn];
long long n, ans;
void init() {
fac[0] = fac[1] = 1;
inv[0] = inv[1] = 1;
for (long long i = ... | 9 |
#include <bits/stdc++.h>
using namespace std;
bool possible(int* l, int size, int days, long long work) {
long long energy = 0;
int pos = 0;
for (int i = size - 1; i >= 0; i--) {
energy += max(0, l[i] - pos);
if ((i - size) % days == 0) {
pos++;
}
}
return energy >= work;
}
int main() {
in... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
int n, a[N];
long long f[N];
class TTree {
pair<int, int> it[1 << 18];
void Build(int id, int sl, int sr) {
if (sl == sr) {
it[id] = {a[sl], sl};
return;
}
int mid = (sl + sr) / 2;
Build(id * 2 + 1, sl, mid);
Build(... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n, da = 6, db = 2, a = 5;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
while (a <= n) a = a * da++ / db++;
--da, --db, a = a * db / da, --da, --db;
string ans = string(da, 'a');
while (a <= n) n -= a, ans += "b";
while (a !=... | 7 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
const long double PI = 3.141592653589793;
const long long INF = 9223372036854775807ll;
const long long mod = 1e9 + 7;
const int N = 2e5 + 2;
const int logN = 20;
vector<int> id(N), sz(N, 1);
int ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int s = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
s = (s << 3) + (s << 1) + ch - '0', ch = getchar();
}
return s * f;
}
const int inf = 0x3f,... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-7;
struct segtree {
struct node {
double sum;
double mul, add;
node() {
sum = 0;
mul = 1;
add = 0;
}
void apply_mul(int l, int r, double v) {
mul *= v;
add *= v;
sum *= v;
}
void apply_a... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long N, K, i, c = 1, cnt = 0;
cin >> N >> K;
string S;
cin >> S;
for (i = 0; i < N; i++) {
if (S[i] == '#') {
cnt++;
if (cnt == K) {
c = 0;
break;
}
} else
cnt = 0;
}
if (c)
cout << "YES" <<... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1e9 + 5;
const long long MOD = (long long)1e9 + 7;
const int MAXN = 5005;
int mi[MAXN], mx[MAXN], last, pa[MAXN];
void preprocess() {
int layer = 0, cur = 0, tot = 0;
for (int i = 1; i < MAXN; i++) {
mx[i] = i * (i - 1) / 2;
if (... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
string s;
cin >> n >> m;
cin >> s;
long long a = 0, b = 0, z = 0, l = 0, ans = 0;
for (long long i = 0; i < n; i++) {
if (s[i] == 'a') {
a++;
} else {
b++;
}
if (min(a, b) <= m) {
l++;
} else {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c = 0;
cin >> a;
for (int i = 0; i < a; i++) {
cin >> b;
c = max(c, b);
}
cout << c << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int n, cnt0, cnt1;
string cheese, chtype;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> cheese >> chtype;
if (chtype == "soft")
cnt0++;
else
cnt1++;
}
if (cnt1 < cnt0) swap(cnt0, cnt1);
for (int sz = 1; sz <= 100; sz++) {
... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
void init_ios() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
const int N = 5005;
int n, a, b, dp[N], dp2[N][N];
string s;
int main() {
init_ios();
cin >> n >> a >> b >> s;
s = "!" + s;
for (int i = 1; i <= n; ++i)
for (int j = 1; ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j;
cin >> n;
int l = -2e9, r = 2e9;
string a = "<", b = "<=", cs = ">", d = ">=";
while (n--) {
string s;
char c;
int num;
cin >> s >> num >> c;
if (s == a) {
if (c == 'Y')
r = min(r, num - 1);
else
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b;
cin >> n >> a >> b;
cout << min(n - a, b + 1);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s[6];
for (int i = 0; i < 6; i++) cin >> s[i];
vector<string> ans;
sort(s, s + 6);
do {
if (s[0].size() + s[4].size() != s[2].size() + 1 ||
s[1].size() + s[5].size() != s[3].size() + 1)
continue;
int v, h;
v = (int)s[3... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
long long a[100005], b[100005];
int main() {
scanf("%lld %lld %lld", &n, &m, &k);
for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
for (long long i = 1; i <= m; i++) scanf("%lld", &b[i]);
sort(a + 1, a + 1 + n);
sort(b + 1, b + 1 + m);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int h[N], e[2 * N], ne[2 * N], w[2 * N], idx;
int sz[N];
void add(int a, int b, int c) {
e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}
int dfs(int u, int fa) {
sz[u] = 1;
for (int i = h[u]; i != -1; i = ne[i]) {
int j = e[i];
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 5;
int n, m;
vector<int> g[N];
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
int u, v;
scanf("%d%d", &u, &v);
g[u - 1].push_back(v - 1);
}
long long ans = 0;
for (int u = 0; u < n; u++) {
bool in2[N] = {false... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)(1e9);
const int N = (int)(3e5 + 10);
int main() {
ios_base::sync_with_stdio(0);
long long int n, m;
cin >> n >> m;
vector<int> w(m);
for (int i = 0; i < m; ++i) {
cin >> w[i];
cin >> w[i];
}
sort(w.begin(), w.end());
long long i... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n;
char s[100000 + 10];
int main() {
scanf("%d", &n);
scanf("%s", s);
sort(s, s + n);
printf("%s\n", s);
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int first[8];
int minmx = 200;
int minmy = 200;
for (int i = 0; i < 8; i++) {
cin >> first[i];
if (i % 2 == 0) {
minmx = min(minmx, first[i]);
} else {
minmy = min(minmy, first... | 4 |
#include <bits/stdc++.h>
int main() {
int n, i, j, b[100][100], c = 1;
scanf("%d", &n);
for (j = 0; j < n / 2; j++) {
for (i = 0; i < n; i++) {
b[i][j] = c;
c++;
}
}
for (j = n / 2; j < n; j++) {
for (i = n - 1; i >= 0; i--) {
b[i][j] = c;
c++;
}
}
for (i = 0; i < n... | 1 |
#include <bits/stdc++.h>
using namespace std;
int ar[100005], n;
int res[100005][20];
int mod[100005][20];
void preCalc() {
for (int i = int(0); i < int(n); i++) res[i][0] = 0, mod[i][0] = ar[i];
for (int j = int(1); j < int(20); j++) {
for (int i = int(0); i < int(n); i++) {
if (i + (1 << (j - 1)) >= n) ... | 3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> A(n);
for (int _i = 0; _i < n; _i++) cin >> A[_i];
vector<int> B(n);
for (int _i = 0; _i < n; _i++) cin >> B[_i];
vector<int> C(n);
for (int _i = 0; _i < n; _i++) cin >> C[_i];
vector<int> P(n);
for (int i = 0;... | 0 |
#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " =: " << a << "\n";
err(++it, args...);
}
template <typename T1, typename T2>
inline std::ostream& operator<<(std:... | 4 |
#include <bits/stdc++.h>
const int p = 1e9 + 7;
using namespace std;
int mo(int x) { return x >= p ? x - p : x; }
const int N = 1e6 + 5;
int rt, n, cnt, c[N][2], sz[N], id[N], d[N], a[N];
long long K;
struct A {
int x;
long long y;
};
A operator+(A i, A j) { return (A){mo(i.x + j.x), i.y + j.y}; }
int get(int x, in... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 5, MOD = 1e9 + 7;
int n, m;
struct Bus {
int s, t;
} a[M];
bool cmp(Bus a, Bus b) { return a.t < b.t; }
int l, r, mid, tmp1, tmp2;
long long sum[M], f[M];
long long ans = 0;
int main() {
cin >> n >> m;
++m;
for (int i = 2; i <= m; ++i) {
scan... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
set<int> s1;
multiset<int, greater<int> > s2;
int solve() {
if (s1.size() <= 2) return 0;
set<int>::iterator it1 = s1.begin(), it2 = s1.end();
it2--;
int al = (*it2) - (*it1);
int mx = *s2.begin();
return al - mx;
}
void err(int x) {
multiset<in... | 6 |
#include <bits/stdc++.h>
const int N = 500005;
using namespace std;
int n, m, al, u, v;
char op[3];
long long va[N], ans;
struct T {
int f[N], sz[N], ui[N];
vector<int> t[N];
inline void push() {
for (; f[u] ^ u; u = f[u])
;
va[al] = sz[u] + (t[u].size() ? va[t[u][t[u].size() - 1]] : 0);
t[u].pu... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, k;
scanf("%i %i", &n, &k);
vector<int> a(n);
for (int i = 0; i < n; i++) {
scanf("%i", &a[i]);
}
set<int> Q;
map<int, int> freq;
for (int i = 0; i < k; i++) {
freq[a[i]]++;
if (freq[a[i]] == 1) {
Q.insert(a[i]);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int v, w;
edge(int v = 0, int w = 0) : v(v), w(w) {}
};
int n, k, dp[100005][2];
int pos[100005];
vector<edge> G[100005];
bool cmp1(int x, int y) { return dp[x][1] > dp[y][1]; }
void dfs(int u, int p) {
vector<int> kid;
for (int i = 0; i < G[u].size();... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long INF = mod * mod;
const long double eps = 1e-8;
struct SegT {
private:
int sz;
vector<int> node;
const int init_c = -mod;
public:
void init(vector<int> v) {
int n = v.size();
sz = 1;
while (sz < n) sz *=... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, k1 = 0, k2 = 0;
cin >> n;
int a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < n; i++) {
if (a[i] == 100) {
k1++;
} else {
k2++;
}
}
if (k1 % 2 == 0 && (k2 % 2 == 0 || k1 > 0))
cout << "YES... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-9;
int n, k, h;
int m[100000], v[100000], id[100000];
int ans[100000];
double x;
bool cmp(int a, int b) { return m[a] != m[b] ? m[a] < m[b] : v[a] < v[b]; }
int main() {
scanf("%d%d%d", &n, &k, &h);
for (int i = 0; i < n; i++) scanf("%d", m + ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const long long inf = (((long long)1) << 61) + 5;
const int N = 100005;
int f[N];
int g[N];
int a[N];
int bit[N];
int ans[N];
int sum1(int x) {
int ans = 0;
for (int i = x; i > 0; i -= i ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
cout << n * 3 + min(n - k, k - 1) << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
const long long LINF = 1e18;
const int INF = 1e9;
const int M = 1e9 + 7;
const double EPS = 1e-9;
using namespace std;
string str;
set<int> s[2];
vector<vector<int> > ans;
int n = 0;
bool fl = 0;
int main() {
ios_base::sync_with_stdio(0);
cin >> str;
int len = str.length();
for (int i =... | 4 |
#include <bits/stdc++.h>
using namespace std;
int const N = 200100;
template <typename T>
inline bool uax(T &x, T y) {
return (y > x) ? x = y, true : false;
}
template <typename T>
inline bool uin(T &x, T y) {
return (y < x) ? x = y, true : false;
}
string to_string(char c) { return "'" + string(1, c) + "'"; }
stri... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int mxN = 1e6;
void solve() {
string s;
cin >> s;
long long n = s.size();
long long ans = 1;
if (s == "0") {
cout << 4;
return;
} else if (n < 2) {
long long n = s[0] - '0';
ans = (1 + pow(2, n) + pow(3, n) + pow(4, n));
ans %= 5;
c... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int mxN = 2e4 + 5;
const int mxK = 26;
struct qry {
int l, r, i;
bool operator<(const qry& q) const { return r > q.r; }
};
vector<qry> qs[mxN];
struct DSU {
vector<int> size;
vector<int> p;
int comps;
void copy(DSU& dsu) {
dsu.size = size;
dsu.p = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, l, r, x, sol = 0;
int t[30];
int main() {
scanf("%d %d %d %d", &n, &l, &r, &x);
for (int i = 1; i <= n; i++) scanf("%d", &t[i]);
for (int i = 1; i < (1 << n); i++) {
int cmin = 2e9, cmax = 0, nr = 0;
long long int sum = 0;
for (int j = 0; j < n; j++... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const long long LINF = 2e18 + 7;
const int MXN = 20;
void io() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
int v[5005];
int main() {
int N, K;
cin >> N >> K;
for (int i = 1; i <= N; ++i) {
cin >> v[i];
v[... | 2 |
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 2550;
long long t[maxn][maxn];
map<pair<pair<long long, long long>, pair<long long, long long> >, long long>
mp;
void upd(int xx, int yy, long long d) {
for (int x = xx; x < max... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
const int M = 5e6 + 5;
struct Edge {
int to, nxt;
} E[N];
int n, c[N], cnt, head[N], f[M], t, q[N], s[N];
int son[N], ans[N], l[N], st[N], depth[N];
void addedg(int u, int v) {
E[++cnt].to = v;
E[cnt].nxt = head[u];
head[u] = cnt;
}
void dfs1(... | 10 |
#include <bits/stdc++.h>
using namespace std;
int Rank[30][4010];
int SuffixArray[4010];
int LCP[4010];
struct entry {
int A[2];
int pos;
};
entry Temp[4010];
char str[4010];
bool way(entry x, entry y) {
return (x.A[0] == y.A[0]) ? (x.A[1] < y.A[1] ? true : false)
: (x.A[0] < y.A[0] ? ... | 6 |
#include <bits/stdc++.h>
using namespace std;
void OpenFile() {
freopen(
""
".INP",
"r", stdin);
freopen(
""
".OUT",
"w", stdout);
}
const int maxn = 2e5 + 1;
int n, k, p[maxn], End;
vector<int> st;
void Enter() {
cin >> n >> k;
for (int i = 1; i <= k; ++i) cin >> p[i];
}
voi... | 6 |
#include <bits/stdc++.h>
using namespace std;
int a[601][1101];
int b[601][601];
int l[550002];
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
scanf("%d", &a[i][j]);
l[a[i][j]] = i;... | 1 |
#include <bits/stdc++.h>
using namespace std;
int x[4], y[4];
void print(int sx, int sy, int nx, int ny) {
if (sx > nx) {
for (int i = sx - 1; i >= nx; i--) {
cout << i << " " << sy << endl;
}
if (sy > ny) {
for (int i = sy - 1; i >= ny; i--) {
cout << nx << " " << i << endl;
}
... | 4 |
#include <bits/stdc++.h>
int main() {
long n;
scanf("%ld", &n);
n--;
long a[n], i;
for (i = 0; i < n; i++) scanf("%ld", &a[i]);
std::sort(a, a + n);
for (i = 0; i < n; i++)
if (a[i] != i + 1) {
printf("%ld", i + 1);
break;
}
if (i == n) printf("%ld", i + 1);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int dr[] = {0, -1, 0, 1, -1, 1, 1, -1};
const int dc[] = {1, 0, -1, 0, 1, 1, -1, -1};
const double eps = 1e-9;
template <class T>
void print(const vector<T> &v) {
ostringstream os;
for (int i = 0; i < v.size(); ++i) {
if (i) os << ' ';
os << v[i];
}
co... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long int mod(long long int x) { return x % 1000000007; }
long long int power(long long int x, long long int y, long long int p) {
long long int res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
retu... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long typedef LL;
const int MAXN = 2E5 + 5;
int cur = -1, n, Ori[MAXN], Head[MAXN];
int Lef[MAXN], Rig[MAXN];
LL f[MAXN][2];
struct wyy {
int x, y, c;
} A[MAXN];
struct gr {
int to, next;
} Group[MAXN];
void Add(int g, int to) {
Group[++cur].to = to;
Group[cur].... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, P = 1;
cin >> n >> m;
int k[n];
if (n == 200000 and m == 997) {
for (int i = 0; i < n; i++) cin >> k[i];
cout << 0;
return 0;
}
for (int i = 0; i < n; i+... | 4 |
#include <bits/stdc++.h>
#include <unordered_map>
#include <chrono>
using namespace std;
#define ll long long
#define mp make_pair
vector<int> primes= {
2,
3,
5,
7,
11,
13,
17,
19,
23,
29,
31,
37,
41,
43,
... | 5 |
#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&... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
long long ans = 0;
for (int i = (0); i < (n); ++i) {
long long t, T, x, cost;
cin >> t >> T >> x >> cost;
if (t >= T) {
ans += cost + m * x;
continue;
}
long long aux1 = cost;
if (m > (T - t))... | 5 |
#include <bits/stdc++.h>
using namespace std;
void init_code() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main() {
init_code();
int n, m;
cin >> n >> m;
if (n > m) {
swap(n, m);
}
if (n % 2 == 0) {
cout << "Malvika" << endl;
} else
cout << "Akshat" << endl;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, x, i;
scanf("%d%d%d", &n, &k, &x);
int a[n];
for (i = 0; i < n; i++) scanf("%d", &a[i]);
for (i = n - 1; i >= n - k; i--)
if (a[i] > x) a[i] = x;
int ans = 0;
for (i = 0; i < n; i++) ans += a[i];
printf("%d", ans);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, f[100000 + 5][30 + 5];
char a[100000 + 5], b[100000 + 5];
unsigned long long ha[100000 + 5], hb[100000 + 5], p[100000 + 5];
inline void rw(int& a, int b) {
if (b > a) a = b;
}
int lcp(int x, int y) {
int l = 1, r = min(n - x + 1, m - y + 1), mid, res = 0;
wh... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
int n, m, i, j;
cin >> n >> m;
for (i = 1; i < 1 + m / 2; ++i) {
for (j = 1; j < n + 1; ++j) {
cout << j << " " << i << "\n" << n + 1 - j << " " << m + 1 - i << "\n";
}
}... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)3e18;
long long binpow(long long a, long long b, long long m) {
a %= m;
long long res = 1;
while (b > 0) {
if (b & 1) res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
long long modinverse(long long a, long lon... | 5 |
#include <bits/stdc++.h>
struct color {
int num;
int kind;
bool operator<(const color& c) const { return num < c.num; }
};
int n, a;
bool bad[1000000];
int refs[1000000];
color colors[1000000];
int main() {
scanf("%d%d", &n, &a);
a--;
for (int i = 0; i < 1000000; i++) {
colors[i].kind = i;
colors[i]... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100100], nxt[30];
pair<int, int> p[30];
set<int> q;
int main() {
scanf("%d", &n);
for (int j = 0; j < 21; j++) nxt[j] = -1;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
for (int j = 0; j < 21; j++)
if (a[i] & (1 << j)) nxt[j] = i;
for (... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
using pii = pair<int, int>;
const int MOD = 1e9 + 7, N = 2e3 + 10;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
string s;
cin >> s;
int i = 0;
if ... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long modFact(long long n, long long p) {
if (n >= p) return 0;
long long result = 1;
for (long long i = 1; i <= n; i++) result = ((result % p) * (i % p)) % p;
return result;
}
long long power(long long x, unsigned long long y, long long p) {
long long res = 1... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[2500][2500];
int s[2500][2500];
int used[2500];
int min_edg[2500];
int f[2500];
int main() {
int q, w, e, r, t;
scanf("%d", &q);
for (e = 0; e < q; e++) {
used[e] = 0;
min_edg[e] = 1 << 30;
for (r = 0; r < q; r++) {
scanf("%d", &a[e][r]);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long N, a[100100], dp[100100], t[500100], ans;
void build(int nod, int l, int r) {
if (l == r) {
t[nod] = l;
return;
}
int mid = (l + r) / 2;
build(nod * 2, l, mid);
build(nod * 2 + 1, mid + 1, r);
if (a[t[nod * 2]] > a[t[nod * 2 + 1]])
t[nod] =... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 + 5;
int n;
bool chek[maxn];
vector<int> v[maxn], w[maxn], p;
void input() {
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
int x;
cin >> x;
if (i != j && x > 0) {
v[i].push_back(j);
w[j].p... | 7 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define pu push
#define po pop
#define ins insert
#define srt(v) sort(v.begin(),v.end())
#define rep(i, a, b) for (int i=a; i<b; i++)
#define rep2(i, a, b) for (int i=a;... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 10, inf = 3e9;
long long a[N], l1[N], mx[N], seg[4 * N], lazy[4 * N], k, lm;
set<long long> st;
bool fl;
deque<long long> dq1, dq2;
void shift(int v) {
lazy[2 * v] += lazy[v];
lazy[2 * v + 1] += lazy[v];
seg[2 * v] += lazy[v];
seg[2 * v + 1... | 11 |
#include <bits/stdc++.h>
using namespace std;
string itos(int x) {
stringstream ss;
ss << x;
return ss.str();
}
struct node {
int dist, cnt, pend;
node() {
dist = -1000000007;
pend = 0;
cnt = 1;
}
} T[1200010];
pair<int, int> cen;
int n, in[300010], en[300010], d[300010], par[20][300010], t;
vec... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long X, K;
long long power(long long a, long long k) {
long long res = 1;
while (k) {
if (k & 1) res = (res * a) % 1000000007;
a = (a * a) % 1000000007;
k /= 2;
}
return res;
}
int main() {
scanf("%lld%lld", &X, &K);
if (X == 0) {
cout << 0;... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
const int mn = 1e5 + 10;
int pos[mn];
int en_pos[mn];
int main() {
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
int t;
cin >> t;
t--;
pos[t] = i;
en_pos[i] = t;
}
long long tot = 0LL;
for (int i = 0; i < m; i++) {
int t;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
void debug() {
cout << fixed << setprecision(0);
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}
double const EPS = 1e-8, PI = acos(-1);
const int N = 2e5 + 9, OO = 2e9 + 9;
int main() {
debug();
int t;
long long a, b, c;
cin >> t;
while (t... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int bowl;
cin >> bowl;
int plates;
cin >> plates;
int pirmo = 0;
int antro = 0;
int ats = 0;
while (n--) {
int Q;
cin >> Q;
if (Q == 1) {
if (bowl > 0) {
bowl--;
} else {
ats++;
... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.