solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
long long a[300000], b[300000], c[300000];
int main() {
long long n, k, i, k1, k2, ans = 0, s = 0;
cin >> n >> k;
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
k1 = a[0];
k2 = a[n - 1];
for (i = 0; i < n; i++) b[a[i]]++;
c[k2 + 1] = 0;
for (i = k2; ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
vector<int> v1;
vector<int> v0;
for (int i = 0; i < n; i++) {
char x;
cin >> x;
if (x == '0') {
v0.push_back(i);
} else {
v... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1015;
int b[N][N];
char c[N];
int n;
char a[N];
int w[15];
int len = 0;
int sa[N], rk[N];
int tsa[N], trk[N];
int sum[15];
int f[2][N];
int cost[N][12][2];
int dj[11][N];
int lp[N];
int dp() {
for (int i = (int)1; i <= (int)n; i++) sa[i] = i;
for (int i = ... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int n, m, Q, Ans[N], ans;
int x[N], y[N];
int L[N][N], R[N][N];
char s[N][N];
void build(int id) {
L[id][0] = R[id][m + 1] = 0;
for (int i = (int)(1); i <= (int)(m); i++)
L[id][i] = (s[id][i] == 'X' ? 0 : L[id][i - 1] + 1);
for (int i = (int)(m... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const long long INFLL = 1001001001001001001LL;
template <typename T>
void pv(T a, T b) {
for (T i = a; i != b; ++i) cout << *i << " ";
cout << endl;
}
template <typename T>
void chmin(T& a, T b) {
if (a > b) a = b;
}
template <typename T>
v... | 12 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
static unsigned rnd() {
static int second = 124612741;
second ^= second << 13;
second ^= second >> 17;
return second ^= second << 5;
}
inline int fpow(int a, int st, int mod) {
int ans = 1;
while (st) {
if (st % 2) ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
vector<long long> p(n, 0);
p[0] = a[0];
for (int i = 1; i < n; i++) p[i] = p[i - 1] + a[i];
map<long long, long long> cnt;
for (int i = 0; i < n; i++) cnt[p[i]]+... | 13 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int t = 1;
cin >> t;
for (int i = 0; i < t; ++i) {
string s;
cin >> s;
std::vector<char> ans;
int x = 0;
int n = s.length() - 1;
if (s.length() < 2) {
if (s.length() == 1) {
cout << s << endl;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
string s, t;
char tmp[20];
string itostr(int x) {
sprintf(tmp, "%d", x);
return tmp;
}
int main() {
int n, x, y, tmp;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x >> y >> tmp;
s += "(" + itostr(x / 2) + "*((1-abs((t-" + itostr(i) + ")))+abs((abs((t-" +... | 14 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
;
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) cout << i << ' ';
cout << '\n';
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 2e5 + 5;
const int MOD = 1e9 + 7;
const long long INF = 1061109567;
const long double EPS = 1e-9;
const long double PI = acos(-1);
long long F[MX], B[MX], T[MX];
long long qpow(long long b, long long e) {
if (!e) return 1LL;
if (e & 1LL) return (qpow(b, e... | 11 |
#include <bits/stdc++.h>
int a[100000], k[100000];
int main() {
int n, i, min = INT_MAX, max = 0;
scanf("%d", &n);
for (i = 1; i <= n; ++i) {
scanf("%d", a + i);
if (a[i] < min) min = a[i];
if (a[i] > max) max = a[i];
}
if ((max - min) * 2 > n) {
printf("NO\n");
return 0;
}
for (i = 1;... | 12 |
#include <bits/stdc++.h>
static int ndigits1[10], ndigits2[10];
char DP1[100000 + 1], DP2[100000 + 1];
static int n = 0;
int min(int a, int b) { return (a < b) ? a : b; }
void Digits_Permutations() {
char digit;
while ((digit = getchar()) != '\n') {
ndigits1[digit - '0']++;
ndigits2[digit - '0']++;
n++;... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXM = 1e4 + 5;
int dp[(1 << 16)][16][16];
int mat[16][MAXM];
int cst[16][16], trans[16][16];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> mat[i][j];
}
}
if (n == 1) {
int ans ... | 12 |
#include <bits/stdc++.h>
double const EPS = 3e-8;
using namespace std;
template <class T>
T gcd(T a, T b) {
return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
return (a / gcd<T>(a, b) * b);
}
template <class T>
inline bool read(T &x) {
int c = getchar();
int sgn = 1;
while (~c && c... | 4 |
#include <bits/stdc++.h>
using namespace std;
namespace SA {
const int Max_N(600050);
int N, SA[Max_N], wa[Max_N], wb[Max_N], Cnt[Max_N], Rank[Max_N], Height[Max_N],
Log[Max_N], ST[20][Max_N];
char S[Max_N];
void getSA() {
int M = 128, *x = wa, *y = wb;
for (int i = 1; i <= N; ++i) ++Cnt[x[i] = S[i]];
for (in... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 20;
char str[maxn];
void work() {
scanf("%s", str + 1);
int lenstr = strlen(str + 1);
int tdi = (1e9 + 20);
for (int i = 1; str[i]; i++) {
if (str[i] == '.') {
tdi = i;
break;
}
}
int begin = 1, end = lenstr;
if (tdi ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int maxl = 18;
vector<int> t[maxn];
int par[maxl][maxn], h[maxn];
int n, Time = 1, st[maxn];
struct node {
int mxm;
int mnm;
int sndmxm;
int sndmnm;
node(int mxm_ = 0, int mnm_ = 0) {
mxm = mxm_;
sndmxm = mxm_;
mnm = mn... | 15 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
ostream &operator<<(ostream &o, const vector<T> &v) {
for (size_t i = 0; i < v.size(); i++)
o << v[i] << (i + 1 != v.size() ? " " : "");
return o;
}
template <int n, class... T>
typename enable_if<(n >= sizeof...(T))>::typ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long a, root=0;
cin >> a;
while(a!=0) {
root += a%10;
a /= 10;
}
root %= 9;
if(root==0)
root = 9;
cout << root << endl;
return 0;
} | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, q, m, ans;
int x[100001];
vector<int> v;
int binary(int m) {
int l = 0, r = n - 1, mid, midc;
if (m < x[0]) return 0;
while (l <= r) {
mid = (l + r) / 2;
if (x[mid] > m)
r = mid - 1;
else
l = mid + 1, midc = mid;
}
return midc + 1;
}... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int nsz = 2e5;
int n, m;
struct data {
int q, w;
data() {}
data(int q, int w) {
this->q = q;
this->w = w;
}
};
data dat[nsz + 5];
bool inline operator<(data a, data b) {
return a.q != b.q ? a.q > b.q : a.w < b.w;
}
struct treap {
int rt, sz, s[nsz ... | 20 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double EPS = 1e-7;
long long N;
long long duaPangkat[25];
long long ans[1000005];
long long leftMostBit(long long x) {
long long ans = 0;
while (x > 0) ans++, x /= 2LL;
return ans;
}
int main() {
scanf("%I64d", &N);
memset(ans, -1... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2410;
int n, l, r, a[N];
vector<int> p;
tuple<int, int, int> tmp[2];
vector<tuple<int, int, int>> ans;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 1, x; i <= 3 * n; i++) cin >> x, a[x] = 1;
for (int i = 1; i <=... | 24 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int tot, temps, tempx;
cin >> tot >> temps >> tempx;
if (!tempx && !tot)
cout << "YES\n";
else if (tempx < tot)
cout << "NO\n";
else if (tempx == tot)
cout << "YES\n";
else if (temps == 0) {
if (tempx == tot + 1)
cout << "YES\n... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int n, m, i, s[100010], sum[100010], k, conta;
struct bus {
int in, fi;
};
bus v[100010];
bool acompare(bus lhs, bus rhs) { return lhs.fi < rhs.fi; }
int main() {
ifstream in("input.txt");
cin >> n >> m;
for (i = 0; i < m; i++) {
cin >> v[i].in;
ci... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int N, M;
cin >> N >> M;
vector<pair<int, int>> ants(N);
for (int i = 0; i < N; ++i) {
cin >> ants[i].first >> ants[i].second;
M = max(M, ants[i].first + ants[i].second);
}
sor... | 14 |
#include <bits/stdc++.h>
using namespace std;
int following[1005];
int queueLength[1005];
int okQueue[1005];
int main() {
int n, k;
cin >> n >> k;
int head = k, shift = 1, tmp;
for (int i = 1; i <= n; i++) {
cin >> following[i];
queueLength[i]++;
tmp = i;
while (following[tmp] != 0) {
queu... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 120010;
struct node {
int tag, val, times, num;
long long ans;
} tr[N * 4];
int n, a[N];
void build(int v = 0, int l = 0, int r = n) {
tr[v].val = l;
tr[v].num = 1;
if (l + 1 == r) return;
int mid = (l + r) / 2, chl = v * 2 + 1, chr = v * 2 + 2;
... | 22 |
#include <bits/stdc++.h>
using namespace std;
void printList(list<int>* list) {
cout << "list : ";
for (__typeof((*list).begin()) li = ((*list).begin()); li != (*list).end();
++li) {
cout << *li << ",";
}
cout << endl;
}
void printT_VPII(vector<pair<int, int> > v) {
cout << "list : ";
for (__type... | 16 |
#include <bits/stdc++.h>
using namespace std;
int m, k, n, s, req[500010], cnt[500010], a[500010];
int cmp[500010], ans[500010];
void init() {
for (int i = 0; i < 500010; ++i) cmp[i] = -1;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> m >> k >> n >> s;
init();
for (int i = 0... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int k;
cin >> k;
int l = s.size();
if (l % k == 0) {
int g = l / k;
int cnt = 0;
for (int i = 0; i < s.size(); i++) {
string t = "";
int f = i + g;
for (int j = i; j < f; j++) {
t += s[j];
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int ot[2002][2002];
int ob[2002][2002];
int ov[2002][2002];
int oo[2002][2002];
string ma[2002];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> ma[i];
}
for (int i = 0; i < n; i++) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1100;
vector<int> a[MAXN];
int main() {
int m, k;
cin >> m >> k;
int n = 0;
for (int i = 1; i <= m; i++) {
int y = i + k;
for (int j = i + 1; j <= y; j++) {
if (j > m) {
y = k - (j - i - 1);
j = 1;
if (y + k >= ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n;
cin >> t;
while (t--) {
cin >> n;
int ans = 0;
while (n % 6 == 0 || (2 * n) % 6 == 0) {
if (n % 6 == 0) {
n /= 6;
ans++;
} else {
n /= 3;
ans += 2;
}
}
if (n == 1)
cout ... | 1 |
#include <bits/stdc++.h>
using namespace std;
string S;
bool check;
int gender;
bool seeA;
bool seeN;
bool seeV;
bool seeS;
int main() {
getline(cin, S, '\n');
for (int i = 0; i < S.size(); i++) {
if (S[i] == ' ' || i == S.size() - 1) {
if (S[i] == ' ') {
seeS = true;
}
if (i == S.size... | 8 |
#include <bits/stdc++.h>
using namespace std;
string fun(int a[], int n) {
if (a[n] == 15) return "DOWN";
if (a[n] == 0) return "UP";
if (n == 1) return "-1";
if (n > 1) {
if (a[n - 1] > a[n]) return "DOWN";
return "UP";
}
}
int main() {
int n;
cin >> n;
int a[n + 1];
for (int i = 1; i <= n; i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
string s;
cin >> n >> s;
int a, c, g, t, qm;
a = c = g = t = qm = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'A')
a++;
else if (s[i] == 'C')
c++;
else if (s[i] == 'G')
g++;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct P {
int x, y, z;
bool operator<(const P &a) const {
if (x != a.x) return x > a.x;
return y > a.y;
}
};
vector<int> v;
int i, n, d, m, k, a, b, c;
long long o[311][111];
long long l[111][111];
int j[111111];
int e;
int dx[10] = {0, 1, 0, -1, 1, 1, -1, -1... | 16 |
#include <bits/stdc++.h>
const double eps = 1e-9;
long long choose(int a, int b) {
double ret = 1;
for (int i = 0; i < b; i++) {
ret *= (a - i);
ret /= i + 1;
}
return (long long)(ret + eps);
}
int main() {
int n, m, t;
scanf("%d%d%d", &n, &m, &t);
long long ans = 0;
for (int i = 4; i < t; i++) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
cin >> n;
long a[5000];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long d = a[0] - a[1];
if (n == 2) {
cout << a[1] - d << endl;
return 0;
} else {
int cnt = 0;
for (int i = 2; i < n; i++) {
if (a[i - 1] - d != a... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a[100100], h[100100], mx[100100];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
}
for (int i = n; i >= 1; i--) {
mx[i] = max(mx[i + 1], a[i]);
}
for (int i = 1; i <= n; i++) {
if (a[i] > mx[i + 1]) continue;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 11, MAXL = 500000 + 10;
struct State {
int len, fa, num[MAXN], tr[26];
State() : len(0), fa(0) {
memset(num, 0, sizeof(num));
memset(tr, 0, sizeof(tr));
}
State(int len, int fa, int numr, int ref) : len(len), fa(fa) {
memset(num, 0, size... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = (1e9) + 7;
int f[1005][1005][6];
int C[1005][1005];
int jc[1005], ans[1005];
int n, m, i, j;
void init() {
for (i = 1, jc[0] = 1; i <= n; i++) jc[i] = (long long)jc[i - 1] * i % Mod;
for (i = 0; i <= n; i++) C[i][0] = 1;
for (i = 1; i <= n; i++)
fo... | 18 |
#include <bits/stdc++.h>
using namespace std;
int const N = 2e3 + 5;
int n;
int c[N], r[N];
int dp[2 * N][2 * N];
int last_right[2 * N][2 * N];
int lobound[2 * N];
vector<int> chose;
map<pair<int, int>, int> encode_intervals;
struct Compare {
bool operator()(const pair<int, int>& a, const pair<int, int>& b) const {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-3;
const int MAXN = 5e5 + 10;
const int MAXM = 1e4 + 10;
const long long mod = 1e9;
int a[MAXN], dp[MAXN];
int main() {
int n, k, d;
scanf("%d%d%d", &n, &k, &d);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a... | 13 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, k;
cin >> n >> k;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
long long cnt = 0, x = 1;
for (long long i = n / 2 + 1; i < n; i++) {
cnt = x * (a[i] - a[n / 2]);
if (k - cnt >= 0) {
k ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int a[100][100];
void check_row(int n, int m, vector<pair<char, int> >& vp) {
for (int i = 0; i < n; i++) {
int x = INT_MAX;
for (int j = 0; j < m; j++) {
x = min(x, a[i][j]);
}
int y = x;
if (x != 0)
for (int j = 0; j < m; j++) {
a... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
long long sum = 0;
vector<long long> a(n);
for (long long i = 0; i < n; ++i) {
cin >> a[i];
sum += a[i];
}
vector<long long> prime;
for (long long i = 2;... | 10 |
#include <bits/stdc++.h>
using namespace std;
queue<int> q;
int head[5009], tot, du[5009], n, cnt;
double ans;
int vis[5009];
inline int rd() {
int x = 0;
char c = getchar();
bool f = 0;
while (!isdigit(c)) {
if (c == '-') f = 1;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
int T, n, m, tot, cnt;
int a[N], b[N], A[N], c[N], li[N], p[N];
void lisan() {
sort(li + 1, li + 1 + tot);
cnt = unique(li + 1, li + 1 + tot) - li - 1;
for (int i = 1; i <= n; i++)
a[i] = lower_bound(li + 1, li + 1 + cnt, a[i]) - li;
for (... | 15 |
#include <bits/stdc++.h>
using namespace std;
string bin(string tt, int k) {
string poch = "";
string ff = tt;
while (k > 0) {
if (k % 2 == 1) poch = poch + ff;
k = k / 2;
ff = ff + ff;
}
return poch;
}
string f(int a1, int a2, int a3, int a4) {
string poch = "";
if (abs(a3 - a4) > 1) return "... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, l, x, y, a[100002], u, v, r = 2;
set<int> A;
bool X, Y;
int main() {
scanf("%d%d%d%d", &n, &l, &x, &y);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
A.insert(a[i]);
}
for (int i = 0; i < n; i++) {
if (A.find(a[i] + x) != A.end()) X = true;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
string S;
int c[26][200009];
int main() {
cin >> S;
for (int i = 0; i < S.size(); i++) {
c[S[i] - 'a'][i + 1] = 1;
}
for (int i = 0; i < 26; i++) {
for (int j = 1; j <= S.size(); j++) c[i][j] += c[i][j - 1];
}
int Q;
sca... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = LLONG_MAX, MOD = 1e9 + 7;
const int N = 4e5;
long long t[N * 2];
long long h;
long long dd[N];
long long n, a, b, c, d, start, len;
vector<pair<long long, pair<long long, long long>>> timetype;
void apply(int p, long long value) {
t[p] += value;
if... | 16 |
#include <bits/stdc++.h>
using namespace std;
struct tree {
int u, v, next, d;
} l[201000];
struct node {
int x, y, fx, fy;
} q[10100];
const int inf = 1 << 30;
int n, m, lian[10100], e = 1, be, en, dep[10100];
void build(int);
void bian(int, int, int);
int dinic();
bool bfs();
int dfs(int, int);
int main() {
sca... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long double Eps = 1e-12;
const long double Pi = 4 * atan(1);
int sgn(long double a, long double b = 0) {
a -= b;
return (a > Eps) - (a < -Eps);
}
struct Point {
long double x, y;
Point operator-(Point p) { return {x - p.x, y - p.y}; }
Point operator+(Point p... | 18 |
#include <bits/stdc++.h>
using namespace std;
int a[500004], b[500004] = {};
int main() {
int i, j, po;
int n, c = 0;
cin >> n;
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
i = n / 2 - 1;
int k = n - 1;
while (i >= 0) {
if (((a[i] * 2) <= a[k]) && b[k] == 0) {
b[k] = 1;
b[i] = 1;... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
int index = 1;
int sum = 0;
for (int i = 1; i < n; i++) {
sum += ((i)*2 + index * 2 + abs(i - index) * 2) * arr[i];
}
cout << sum << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int mxN = 2e4;
int n, k, a[mxN], dp[2][mxN + 1], qt, m[mxN], b[mxN], mx[mxN + 1];
void al(int mi, int bi, bool mo) {
if (qt && mi == m[qt - 1]) {
if (bi > b[qt - 1]) return;
--qt;
}
while (qt > 1 && (bi - b[qt - 1]) / (m[qt - 1] - mi) <
... | 22 |
#include <bits/stdc++.h>
int main() {
int n, i, s = 0, c = 0, b;
scanf("%d", &n);
int a[n];
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (i = 0; i < n; i++) {
s = s + a[i];
}
s = s / 2 + s % 2;
for (i = 0; i < n; i++) {
c = c + a[i];
if (c >= s) {
b = i;
break;
}... | 5 |
#include <bits/stdc++.h>
const int MAXN = 4e5 + 5;
int n;
std::vector<int> S;
struct Node {
int l, r, id;
Node(int l = 0, int r = 0, int id = 0) : l(l), r(r), id(id) {}
} a[MAXN];
struct BIT {
int tree[MAXN];
inline void add(int pos, int x) {
for (; pos < MAXN; pos += ((pos) & (-(pos)))) tree[pos] += x;
}... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const int N = 200005;
int a[N];
int b[105], data[N * 2], *d = data + 200000;
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
b[a[i]]++;
}
int wc = 0;
for (... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
int n, x, y, cnt[N];
long long ans;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i < n; i++) {
cin >> x >> y;
cnt[x]++;
cnt[y]++;
}
for (int i = 1; i <= n; i++) {
ans += cn... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, i, c;
cin >> n >> k;
vector<int> vector1(k);
set<int> S;
stack<int> stack1;
for (i = 0; i < k; i++) cin >> vector1[i], S.insert(vector1[i]);
c = 1;
while (c <= n) {
if (S.find(c) == S.end()) {
stack1.push(c++);
} else {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int a[n];
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
string s;
cin >> s;
char current_char = s[0];
std::vector<int> v;
v.push_back(a[0]);
long long int dmg = 0;
for (int i = 1; i < n; ++i) {
if (s[i] ==... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
vector<long long> v;
map<string, int> mp;
long long n, a, b, c, i;
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
a = 1;
b = 2;
while (c <= n) {
c = a + b;
a = b;
b = c;
i++;
}
co... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
map<char, int> b = {{'0', 1}, {'4', 1}, {'6', 1}, {'8', 2},
{'9', 1}, {'A', 1}, {'B', 2}, {'D', 1}};
long long x;
string hex;
cin >> x;
int ans = 0;
if (x == 0) {
cout << 1;
return 0;
}
while (x) {
if (x % 16 < ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long ans = 1;
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << int(((a ^ b) && (c || d)) ^ ((b && c) || (a ^ d))) << endl;
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, num[300100], tt = 1;
struct Node {
long long ls, rs, lm, rm, mx, ln, rn, len;
};
Node node[300100 << 1];
inline bool lj(long long u, long long v) {
return u > 0 && v || u < 0 && v < 0;
}
inline void up(long long now) {
long long u = node[now].ls, v = n... | 17 |
#include <bits/stdc++.h>
using namespace std;
double dp[2][1 << 9][240][2];
int first, k, p;
double pro;
inline double solve() {
memset(dp, 0, sizeof(dp));
int v = (first >> 9);
if (!v) {
dp[0][first][0][0] = 1.;
} else if (v % 2 == 0) {
int add = 0;
while (v % 2 == 0) {
v /= 2;
++add;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 10;
int n, k;
int vec[MAXN], sec[MAXN], gec[MAXN], t[MAXN];
bool same() {
for (int i = 0; i < n; i++)
if (vec[i] != sec[i]) return false;
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
for (int i = ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, ans = 0;
scanf("%lld", &n);
for (long long i = 3; i <= n; i++) {
ans += (i - 1) * i;
}
printf("%lld\n", ans);
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e1) {
cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
cout << e1 << " " << e2 << " " << e3 << endl;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 100;
const long long int INF64 = (1LL << 61) + 100;
const long long int MOD = 1000 * 1000 * 1000 + 7;
long long int bpow(long long int a, long long int b) {
if (b == 0) return 1;
if (b == 1) return a % MOD;
long long int r = bpow(a, b >> 1);
r ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, r = 0;
cin >> n;
vector<string> v(n);
map<string, int> m;
for (i = 0; i < n; i++) {
cin >> v[i];
sort(v[i].begin(), v[i].end());
for (j = 1; j < v[i].size(); j++) {
if (v[i][j] == v[i][j - 1]) {
v[i].erase(v[i].b... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long fact(long long n) {
if (n == 0) {
return 1;
}
return (n * fact(n - 1)) % 1000000000000000007;
}
long long power(long long x, long long y) {
long long out = 1;
while (y > 0) {
if (y & 1) out = (out * x) % 1000000000000000007;
y = y >> 1;
x... | 9 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> d[2000];
int main() {
int n, m, k, t, i, j, x, y, r;
cin >> n >> m >> k >> t;
for (i = 0; i < k; i++) scanf("%d %d", &d[i].first, &d[i].second);
sort(d, d + k);
pair<int, int> tm;
while (t--) {
scanf("%d %d", &tm.first, &tm.second);
i = in... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
char buf[100000], *p1 = buf, *p2 = buf;
inline int gi() {
int x = 0, 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 <<... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int module = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, p;
cin >> n >> m >> p;
--p;
string s, q;
cin >> s >> q;
vector<int> r(n);
stack<int> st;
for (int i = 0; i < n; ++i) {
if (s[i] == '(')
st.push(i);
... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct Dinic {
static const int MAXN = 100005, MAXM = 1000005;
struct Edge {
int to, next;
T cap;
} edge[MAXM];
int head[MAXN], tot;
void clear() {
memset(head, -1, sizeof(head));
tot = 0;
}
Dinic() { clear(); }
void add... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename G>
void dd(map<T, G> &v) {
for (const auto &i : v) cout << i.first << " " << i.second << endl;
cout << endl;
}
template <typename T>
void dd(set<T> &v) {
for (const auto &i : v) cout << i << " ";
cout << endl;
}
template <typename T, t... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 * 1000 + 10;
int mx, n, a, sar = 1;
long long ps[maxn];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
ps[i + 1] = ps[i] + a;
}
sort(ps + 1, ps + n + 1);
for (int i = 2; i <= n; i++) {
if (ps[i] != ps[i - 1]) {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long n, m;
cin >> n >> m;
map<long long, int> mp;
int arr[m];
long long sum = 0;
for (int i = 0; i < m; i++) {
cin >> arr[i];
sum += arr[i];
mp[arr[i]]++;
}
int cnt = 0;... | 11 |
#include <bits/stdc++.h>
using namespace std;
int cmp(vector<int> &a, vector<int> &b) {
int Min = min(a.size(), b.size());
int flag = 0;
for (int i = 0; i < Min; i++) {
if (a[i] > b[i]) return 1;
if (b[i] > a[i]) return 0;
}
if (a.size() > b.size()) return 1;
if (a.size() == b.size()) return 2;
re... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long int p[200005];
int main() {
long long int q, h, n;
cin >> q;
while (q--) {
cin >> h >> n;
for (int i = 1; i <= n; i++) cin >> p[i];
int ans = 0;
p[n + 1] = 0;
for (int i = 2; i <= n; i++) {
if (p[i] == p[i + 1] + 1)
i++;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4005;
int a[maxn], b[maxn], v[maxn];
int p[maxn][maxn];
int main() {
int n, m;
cin >> n >> m;
memset(v, 0, sizeof(v));
memset(p, 0, sizeof(p));
for (int i = 1; i <= m; i++) {
cin >> a[i] >> b[i];
v[a[i]]++;
v[b[i]]++;
p[a[i]][b[i]]... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 1;
vector<long long> gaus;
int ans, n;
long long temp, a, b;
void add(long long val) {
int bit = 60, lol = 0;
for (auto i : gaus) {
while (bit && !(val & (1LL << bit)) && !(i & (1LL << bit))) bit--;
if (!(i & (1LL << bit)) && (val & (1LL << b... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n;
for (k = 2; k * k < n; ++k)
if (n % k == 0) break;
if (n % k) return cout << "NO", 0;
int a = 1, b = n;
for (; b % k == 0; b /= k) a *= k;
if (b == 1) return cout << "NO", 0;
cout << "YES\n2\n";
if (a > b) swap(a, b);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n;
cin >> n;
vector<long long int> v(n);
map<long long int, long long int> m;
for (long long int i = 0; i < n; i++) {
cin >> v[i];
}
sort(v.begin(), v.end());
long long int cnt = 0;
long long int ans = 0;
for (int i = n -... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
bool debug = false;
int fa[20][N], deep[N], id[N], p[N];
vector<int> vc[N];
void dfs(int o, int f) {
deep[o] = deep[f] + 1, fa[0][o] = f;
for (int i = 1; i < 20; ++i) fa[i][o] = fa[i - 1][fa[i - 1][o]];
for (auto it : vc[o])
if (it != f) df... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5 * 1e5 + 1;
char S[MAXN + 1];
int N, a, b, T, cur = 0, ans = 0;
int main() {
scanf("%d", &N), scanf("%d", &a), scanf("%d", &b), scanf("%d", &T);
scanf("%s", S);
int j = N - 1;
while (j > 0) cur += a + 1 + b * (S[j--] == 'w');
j++;
cur -= a;
f... | 11 |
#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) { return a > b; }
int main() {
int t;
cin >> t;
while (t--) {
int a, b, c, d, k;
cin >> a >> b >> c >> d >> k;
int pen = a / c;
if (a % c != 0) pen++;
int penc = b / d;
if (b % d != 0) penc++;
if (pen + penc > k)
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int pwr(int a, int b) {
if (b == 0) return 1;
int c = pwr(a, b / 2);
if (b % 2) return c * c * a;
return c * c;
}
int main() {
int q;
cin >> q;
while (q--) {
long long n, cnt = 0;
cin >> n;
while (1) {
if (n % 2 == 0) {
n /= 2;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long int mx = 2e3 + 10;
long long int dp[mx][mx];
const long long int mod = 1e9 + 7;
int main() {
long long int n, k;
cin >> n >> k;
dp[0][1] = 1;
for (long long int len = 1; len <= k; len++) {
for (long long int i = 1; i <= n; i++) {
for (long ... | 6 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n, k;
cin >> n >> k;
long long int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int flag[63];
memset(flag, 0, sizeof(flag));
for (int i = 0; i < n; i++) {
int j = 0;
long long int val = 1;
while (val < a[i])... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int> > v[500007];
pair<int, int> edge_list[500007];
int diam[2];
class Tree {
int root;
vector<int> ord;
int st[500007], en[500007];
int rev[500007];
int depth[500007], parity[500007];
void dfs(int vertex, int prv) {
ord.push_back(ver... | 20 |
#include <bits/stdc++.h>
using namespace std;
vector<int> node[10000 + 7 << 2];
bitset<20000 + 7> ans;
int n, k;
void insert(int now, int C, int L, int R, int ll, int rr) {
if (L >= ll && R <= rr) {
node[now].push_back(C);
return;
}
int mid = (L + R) >> 1;
if (mid >= ll) insert(now << 1, C, L, mid, ll, ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
while (q--) {
int b, w;
cin >> b >> w;
if (b >= w) {
if (b > 3 * w + 1)
cout << "NO\n";
else {
cout << "YES\n";
int i = 2;
for (int j = 2; j <= 2 * w + 1; ++j) {
cout << i ... | 10 |
#include <bits/stdc++.h>
using namespace std;
bool solve(string x, string y) {
if (x == y) return true;
if (x.size() % 2 || y.size() % 2 || x.size() != y.size()) return false;
string a1, a2, b1, b2;
a1 = x.substr(0, x.size() / 2);
a2 = x.substr(x.size() / 2, x.size() / 2);
b1 = y.substr(0, y.size() / 2);
... | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.