solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
int n, Mx, Mn;
int head[maxn], size;
int son[maxn], sz[maxn], ans[maxn];
int sum[maxn], dep[maxn], dep_sum[maxn * 10];
char s[5];
struct node {
int v, nxt, w;
} e[maxn];
void add(int u, int v, int w) {
e[++size].v = v;
e[size].w = w;
e[size... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int count = 0;
for (int i = 1; i < n; i++) {
if (n % i == 0) count++;
}
cout << count << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int row[5005][2] = {0}, col[5005][2] = {0}, i, j, r, c, k, ch, n, paint;
scanf("%d %d %d", &r, &c, &k);
for (i = 1; i <= k; i++) {
scanf("%d %d %d", &ch, &n, &paint);
if (ch == 1) {
row[n][1] = paint;
row[n][0] = i;
} else {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int SIZE = 1e6 + 10;
char s[SIZE];
int mon[SIZE], mn, p[SIZE], pn;
int dp[SIZE];
int wa[SIZE];
int BIT[SIZE];
void ins(int x, int v) {
for (; x; x -= x & -x) BIT[x] += v;
}
int qq(int x) {
int res = 0;
int y = x - 1;
for (; x < SIZE; x... | 17 |
#include <bits/stdc++.h>
int main() {
int i, j, k, c = 0;
int s[4];
for (j = 0; j < 4; j++) scanf("%d", &s[j]);
for (k = 0; k < 4; k++) {
for (j = k + 1; j < 4; j++) {
if (s[k] == s[j]) s[j] = 0;
}
}
for (j = 0; j < 4; j++) {
if (s[j] == 0) c++;
}
printf("%d\n", c);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
char a[100000];
int dp[100000][3];
int nearest_same[100000];
int nearest_op[100000];
cin >> n;
for (i = 0; i < n; ++i) cin >> a[i];
int ans = 0;
nearest_op[n - 1] = nearest_same[n - 1] = -1;
for (i = n - 2; i >= 0; --i) {
if (a... | 8 |
#include <bits/stdc++.h>
using namespace std;
int x[200010];
char tp[200010];
vector<int> vec;
int main() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int mx = -0x3f3f3f3f, mn = 0x3f3f3f3f;
int Mx = -0x3f3f3f3f, Mn = 0x3f3f3f3f;
for (int i = 1; i <= n; i++) {
cin >> x[i... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 0, 1, -1, -1, 1, -1, 1};
const int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
int n;
int m[2048][2048];
int level[2048][2048];
int c, s, area;
void read() {
scanf("%d", &n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) scanf("%d", &m[i][j]);... | 11 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1E-8;
const int dx4[4] = {1, 0, 0, -1};
const int dy4[4] = {0, -1, 1, 0};
const int inf = 0x3f3f3f3f;
int n, k, res;
int pre[5] = {0, 1, 0, 1, 2};
int grundy(int a) {
if (k % 2 == 0) {
if (a == 1) return 1;
if (a == 2) return 2;
return (a % ... | 14 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll mod = 1e9 + 7;
const ll N = 1e5 + 5;
ll n, k;
vector<ll> a[50005];
ll kq = 0;
ll dp[50005][505];
ll par[50005];
void dfs(ll u) {
dp[u][0] = 1;
for (auto x : a[u])
if (x != par[u]) {
par[x] = u;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7, N = 1e5 + 5, INF = 1e18;
long long power(long long a, long long b) {
a = a % mod;
long long result = 1;
while (b) {
if (b & 1) result = (result * a) % mod;
b >>= 1, a = (a * a) % mod;
}
return result;
}
int main() {
std::io... | 4 |
#include <bits/stdc++.h>
using lint = long long;
using namespace std;
int main() {
int N;
lint P, K;
cin >> N >> P >> K;
map<lint, lint> cnt;
for (int i = 0; i < N; ++i) {
lint A;
cin >> A;
lint quad = 1;
for (int j = 0; j < 4; ++j) {
(quad *= A) %= P;
}
lint B = (quad + P - (A *... | 15 |
#include <bits/stdc++.h>
using namespace std;
int inf;
const double eps = 1e-8;
const double pi = acos(-1.0);
template <class T, class T2>
int chkmin(T &a, T2 b) {
return a > b ? a = b, 1 : 0;
}
template <class T, class T2>
int chkmax(T &a, T2 b) {
return a < b ? a = b, 1 : 0;
}
template <class T>
T sqr(T a) {
re... | 22 |
#include <bits/stdc++.h>
using namespace std;
int a[200005], b[200005];
int c[200005];
int pl[200005], tp[200005];
int cnt = 0;
void push(int p, int t) {
if (cnt >= 100000) return;
pl[cnt] = p, tp[cnt++] = t;
}
int sgn(int a) {
if (a > 0) return 1;
return -1;
}
bool check(int a) { return a >= 0 && a <= 9; }
cha... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 22;
const int INF = 1e9 + 2;
long long n, ans = INF, a[MAXN];
string str;
long long ed(long long x, long long y) {
if (x > y)
return x - y;
else
return y - x;
}
int main() {
cin >> n;
cin >> str;
for (long long i = 0; i < n; i++) cin... | 2 |
#include <bits/stdc++.h>
using namespace std;
void Alert() {
cout << "No" << endl;
exit(0);
}
int len = -1;
vector<string> dd, ss;
void Solve() {
string mask;
for (int i = 0; i < len; ++i) {
char c = dd[0][i];
for (int j = 1; j < dd.size(); ++j) {
if (dd[j][i] != c) {
c = '?';
brea... | 5 |
#include <bits/stdc++.h>
using namespace std;
int gcd1(int a, int b) {
if (a == 0) return b;
return gcd1(b % a, a);
}
long long modx(long long base, long long ex) {
long long ans = 1LL, val = base;
while (ex > 0LL) {
if (ex & 1LL) ans = (ans * val) % 1000000007LL;
val = (val * val) % 1000000007LL;
e... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int l, p, q;
float s, t;
cin >> l;
cin >> p;
cin >> q;
t = ((float)l) / (p + q);
s = p * t;
cout << s;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int g[12][12];
int n, m, k;
long long dp[(1 << 10) + 2][(1 << 10) + 2];
long long rub(int a, int b) {
if (dp[a][b] != -1) return dp[a][b];
if (__builtin_popcount(b) == 2 && a == b) {
int x, y = -1;
for (int i = 0; i <= (int)(n)-1; i++) {
if ((1 << i) & a) ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 25, MOD = 1e9 + 7;
int n, inv[N];
long long f[N];
int mod(long long x) { return ((x % MOD) + MOD) % MOD; }
int power(int a, int x) {
if (x == 0) return 1;
if (x % 2 == 1) return ((long long)a * power(a, x - 1)) % MOD;
int half = power(a, x / 2);
return... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
const long long MOD = 1e9 + 7;
long long bit[N];
void update(int idx, long long val) {
while (idx < N) {
bit[idx] += val;
bit[idx] %= MOD;
idx += (idx & -idx);
}
}
long long query(int idx) {
long long ret = 0;
while (idx > 0) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& stream, const vector<T> v) {
stream << "[ ";
for (int i = 0; i < (int)v.size(); i++) stream << v[i] << " ";
stream << "]";
return stream;
}
long long fpow(long long x, long long p, long long m) {
long long r = 1;
f... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long n, a[500005];
void print() {
for (long long i = 1; i <= n; ++i) cout << a[i] << " ";
cout << "\n";
}
void solve() {
cin >> n;
long long sum = 0;
for (long long i = 1; i <= n; ++i) {
cin >> a[i];
sum += a[i];
}
if (sum % n) {
cout << "-1\n... | 12 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC target("sse3", "sse2", "sse")
#pragma GCC target("avx", "sse4", "sse4.1", "sse4.2", "ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline", "fast-math", "unroll-loops", \
"no-stack-protector")
#pragma GCC optimize("Ofast,no-... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 600000000;
const long long mod = 1000000007;
const double pi = acos(-1.0);
const double EPS = 1e-11;
string toStr(long long n) {
stringstream ss;
ss << n;
return ss.str();
}
int toNum(string s) {
stringstream ss;
long long n;
ss << s;
ss >> n;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<int> pos[26];
void solve() {
int n, m;
string s;
cin >> n >> s;
for (int i = 0; i < n; i++) {
pos[s[i] - 'a'].push_back(i);
}
cin >> m;
for (int i = 0; i < m; i++) {
int answ = 0;
string t;
cin >> t;
vector<int> cnt(26, 0);
for (... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int node, leaf;
int dfs(int x, int v, int l, int r) {
if (node < x) {
if (l == r && l == v) {
return -1;
}
if (l != r && l != v) {
return -1;
}
return l ^ r;
}
int ret = 0, t;
ret += t = dfs(x << 1, v ^ 1, l... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
int n, b, d;
cin >> n >> b >> d;
int w = 0, t = 0;
int tmp;
while (n--) {
cin >> tmp;
if (tmp <= b) w += tmp;
if (w > d) t++, w = 0;
}
cout << t << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b = "";
cin >> a;
int z = a.size() - 1;
for (int i = 0; i < a.size(); i++) {
if (a[i] != a[a.size() - 1]) {
b += a[i];
} else {
if (i != a.size() - 1) {
a.erase(a.begin() + a.size() - 1);
b += a[i];
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n = 0;
long long ans = 0;
long long ye = 10000000000;
signed main() {
long long a, b;
cin >> a >> b;
n = a + b;
for (long long g = 1; g * g < n; g++) {
long long haveminb = (long long)ceil((double)b / ((double)g + 1));
if (haveminb * g > b) continu... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int inf = 50000000;
const int maxn = 300010;
struct node {
int ans, sufans, prefans, prefInc, prefDec, sufInc, sufDec;
long long last, first, lazy;
};
int n, A[maxn];
node st[maxn * 5];
void merge(int l, int r, int second, int e, int m,... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
long n, m;
long long k;
cin >> n >> m >> k;
if (k == 0) {
cout << 1 << " " << 1 << endl;
return 0;
}
if (k < n) {
cout << k + 1 << " " << 1 << endl;
return 0;
}
k -= n;
if (k == 0) {
cout << n <<... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, x;
int main() {
cin >> n;
for (int o = 0; o < n; o++) {
cin >> x;
if (x == 0) {
cout << "Y 0.0 0.0\n";
} else if (x < 4) {
cout << "N\n";
} else if (x == 4) {
cout << "Y 2.0 2.0\n";
} else {
double poc = 1.0;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 1;
vector<int> g[N], g2[N], stk;
int depth[N]{}, low[N], idx, depth2[N]{};
bool vis[N]{};
void dfs(int u, int p) {
low[u] = depth[u] = ~p ? depth[p] + 1 : 0;
vis[u] = true;
stk.push_back(u);
for (int i : g[u]) {
if (i == p) continue;
if (... | 15 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int w = INT_MAX, i, to;
unsigned long long accum;
bool operator<(edge const& e) const {
if (accum != e.accum) return accum > e.accum;
return w > e.w;
};
edge(int w, int i, int to) : w(w), i(i), to(to){};
};
vector<vector<edge>> graph;
int mai... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
x = 0;
char ch = getchar();
int fh = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') fh = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
x *= fh;
}
struct Info {
lo... | 26 |
#include <bits/stdc++.h>
using namespace std;
int qzh[305][305][2], a[305][305];
int qwq[5];
set<pair<int, int> > s;
inline int d(int x, int y) {
if (x > y) return qwq[2];
if (x < y) return qwq[1];
return qwq[0];
}
int main(int argc, char** argv) {
int n, m, t;
cin >> n >> m >> t >> qwq[0] >> qwq[1] >> qwq[2]... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> adj[2333333];
pair<int, int> vis[2333333][2];
int cnt[2333333], cm = 0;
int dfn[2333333], low[2333333], C = 0;
bool ins[2333333];
int st[2333333], sn = 0;
void tarjan(int x) {
dfn[x] = low[x] = ++C;
st[++sn] = x;
ins[x] = 1;
for (auto b : adj[x]) ... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long n, l, r, x;
int comb(vector<int> st, int i, int* arr) {
int tr = 0;
if (st.size() > 1) {
int sum = 0;
int maxv, minv;
maxv = minv = st[0];
for (auto a : st) {
sum += a;
maxv = max(maxv, a);
minv = min(minv, a);
}
if (l... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long ans[36] = {25,
125,
230,
120,
27,
26,
2000000000000000000,
2,
... | 22 |
#include <bits/stdc++.h>
using namespace std;
vector<int> factor[1000005];
int ans[1000005];
int n, m, i, t, g[524288];
complex<double> a[524288], b[524288];
void FFTinit() {
for (i = 1; i < 524288; i++) g[i] = g[i >> 1] >> 1 | ((i & 1) << 18);
}
void FFT(complex<double> *a, int f) {
int i, j, k, p;
for (i = 0; i... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool fs(T &x) {
int c = getchar();
int sgn = 1;
while (~c && c < '0' || c > '9') {
if (c == '-') sgn = -1;
c = getchar();
}
for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
x *= sgn;
return ~c;
}
ma... | 7 |
#include <bits/stdc++.h>
int main() {
int l, r, a;
scanf("%d%d%d", &l, &r, &a);
{
if (l + a == 0 || r + a == 0)
printf("0\n");
else {
if (l < r) {
int t = l;
l = r;
r = t;
}
if (l == r)
printf("%d\n", 2 * (r + a / 2));
else {
if (r + a ... | 0 |
#define IOS ios::sync_with_stdio(false);
#define rep(i, a, n) for(ll i=a;i<=n;i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
ll t, n, m, k, ans, cnt, sum, flag;
ll arr[N], brr[N];
char s[N];
int m... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, ans;
int main() {
scanf("%d", &n);
while (n) {
int mx = 0, x = n;
ans++;
while (x) {
mx = max(mx, x % 10);
x /= 10;
}
n -= mx;
}
printf("%d\n", ans);
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cout << 3 * n + i << " ";
}
return 0;
}
| 4 |
#include <bits/stdc++.h>
template <typename T>
T inline SQR(const T &a) {
return a * a;
}
template <typename T>
T inline ABS(const T &a) {
return a < 0 ? -a : a;
}
const double EPS = 1e-9;
inline int SGN(double a) {
return ((a > EPS) ? (1) : ((a < -EPS) ? (-1) : (0)));
}
inline int CMP(double a, double b) { retur... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int maxn = 200010;
vector<int> now;
stack<int> s;
vector<int> rev[maxn];
int n, tot;
int a[maxn];
bool vis[maxn];
bool instack[maxn];
long long ans;
long long pw(int p) {
if (p == 0)
return 1;
else {
long long ans = pw(p /... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long GCD(long long u, long long v) {
while (v != 0) {
long long r = u % v;
u = v;
v = r;
}
return u;
}
struct name {
int x, y;
};
bool comp(name a, name b) { return a.x < b.x; };
int n, k, b;
vector<vector<long long> > a;
vector<long long> z;
int ma... | 11 |
#include <bits/stdc++.h>
using namespace std;
bool check(int x, int n) {
int s = n / 2;
int cur = s * s / 2 + s % 2;
cur *= 4;
cur += 2 * (s - (s % 2)) + 1;
return x <= cur;
}
int main() {
int i, j;
int x;
cin >> x;
if (x == 3) {
cout << 5 << endl;
return 0;
}
for (i = 1; i < 64; i += 2) {... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e2 + 10;
int n, a[N], cnt[5];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
cnt[a[i] % 2]++;
}
if (cnt[1] % 2 == 0) {
cout << cnt[0] << endl;
} else {
cout << cnt[1] << endl;
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
void solve() {
int n;
cin >> n;
vector<int> a(n + 1), l(n + 1, INT_MAX), r(n + 1, INT_MIN);
for (int i = 0; i < n; i++) {
int x;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a, b;
cin >> n >> a >> b;
long long area = 6 * n;
if (area <= a * b) {
cout << a * b << "\n";
cout << a << " " << b << "\n";
return 0;
}
long long root = ceil(sqrt(6.0 * n));
long long newa, newb;
long long ans = 2e18;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, ans;
string s;
bool arr[5];
int main() {
memset(arr, 0, sizeof(arr));
cin >> n >> s;
for (int i = 0; i < n; i++) {
if (s[i] == 'R' && arr[2])
ans++, arr[1] = 1, arr[2] = 0, arr[3] = 0, arr[4] = 0;
else if (s[i] == 'R' && !arr[2])
arr[1] = 1;... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int size = 110000, mod = 1000000009;
const double pi = acos(-1.0);
char s[110][10010];
int pre[110][10010];
int n, m;
bool in(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }
bool flag;
long long cnt;
void bfs(int x, int y, int d, int f) {
while (1) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long a[n], b[n];
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
long long flag = n - 1;
for (long long i = n - 1; i >= 0; i--) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int ar[200000];
int n, k;
bool used[200000];
vector<int> answer;
int find_zero() {
for (int i = 0; i < n; ++i) {
if ((!used[i]) && (ar[i] == 0)) return i;
}
}
int main() {
cin >> n >> k;
for (int i = 0; i < n; ++i) {
cin >> ar[i];
}
for (int i = 0; i < n... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%d%d", &n, &k);
int b[1000];
for (int i = 0; i < n; i++) scanf("%d", b + i);
vector<int> a;
for (int i = n - k; i < n; i++) a.push_back(i + 1);
for (int i = n - k - 1; i >= 0; i--) {
bool ok = false;
for (int j = 0, cnt = ... | 10 |
#include <bits/stdc++.h>
namespace ringo {
template <class T>
inline void read(T &x) {
x = 0;
register char c = getchar();
register bool f = 0;
while (!isdigit(c)) f ^= c == '-', c = getchar();
while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
if (f) x = -x;
}
template <class T>
inline void print(T x)... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
double a[maxn], b[maxn];
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
map<long long, int> s;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%lf", &a[i]);
}
for (int i = 1; i <= n; i++... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long a[300001], s[300001], t[300001];
struct edge {
unsigned p, v;
long long w, s;
} es[300001 << 1];
unsigned eh[300001], ec;
struct query {
unsigned u, v, w;
};
vector<query> qv;
vector<unsigned> qs[300001];
void adde(unsigned u, unsigned v, long long w) {
es... | 19 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void rread(T& num) {
num = 0;
T f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') num = num * 10 + ch - '0', ch = getchar();
num *= f;
}
const lo... | 24 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, k;
cin >> n >> k;
string s;
int i = 1;
int last = k;
while (k > 0) {
last = k;
k -= i;
i++;
}
i--;
for (int j = 0; j < n; j++) {
s += 'a';
}
k--;
s[i] = 'b';
s[last - 1] = 'b';
reverse(s.begin(), s.end());
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
string s;
cin >> s;
int suff = 0;
for (int siz = 1; siz < n; siz++) {
if (s.substr(0, siz) == s.substr(n - siz, siz)) suff = siz;
}
cout << s;
for (int i = 0; i < ... | 5 |
#include<bits/stdc++.h>
#define ll long long
#define heap priority_queue
using namespace std;
const ll maxn=200000+5,inf=9e17;
ll ans,tag[maxn],a[maxn],t,n;
int main()
{
cin>>t;
while(t--)
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(a[i])
{
++tag[max(1ll,i-a[i]+1)];
--tag[i+1];
}
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 305;
struct Node {
int x, l;
} a[N];
int f[N][N], w[N], l[N], r[N], p[N];
bool cmp(const Node &a, const Node &b) {
return a.x == b.x ? a.l < b.l : a.x < b.x;
}
int g[N];
int main() {
int n, tot = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
long long pwr(long long a, long long b, long long mod) {
if (b == 0) return 1;
long long temp = pwr(a, b / 2, mod);
temp = (temp * temp) % mod;
if (b & 1) temp = (temp * a) % mod;
return temp;
}
long long pwr(long long a, long long b) {... | 7 |
#include <bits/stdc++.h>
using namespace std;
int a[500000][2], n;
bool fun(double t) {
double imax = -1e21;
for (int i = 0; i < n; ++i) {
if (a[i][1] > 0)
imax = max(imax, a[i][0] + a[i][1] * t);
else if (a[i][0] + a[i][1] * t <= imax)
return true;
}
return false;
}
int main() {
while (~s... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
struct Edge {
int from, to, nxt;
} edge[MAX * 2];
int tot, head[MAX], in[MAX], out[MAX];
void add(int x, int y) {
edge[++tot].nxt = head[x];
head[x] = tot;
edge[tot].from = x;
edge[tot].to = y;
in[y]++;
out[x]++;
}
int n, m;
bool flag1... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
int n;
cin >> n;
if (n % 2 == 0) {
cout << "NO";
return 0;
}
cout << "YES" << endl;
vector<int> a, b;
for (int i = 1; i <= n; i++) {
if (i % 2) {
a.push_b... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 52 + 20;
const long long oo = 1e18;
const int MOD = 1e9 + 7;
struct st {
st *left, *right;
int mn, l, r, m, lazy;
st(int l, int r) : l(l), r(r), lazy(0), mn(0) {
m = (l + r) / 2;
if (l != r) {
left = new st(l, m);
right = new st(m + 1... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, m, p, dir, l, r, t, cnt, ok;
int L[10010], R[10010];
char s[105][10010];
long long ret;
int main() {
scanf("%d%d", &n, &m);
m += 2;
for (int i = (0); i < (n); i++) {
s[i][0] = '#';
scanf("%s", s[i] + 1);
s[i][m - 1] = '#';
}
p = 1, dir = 1;
re... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int CMAX = 200010;
const long long MOD = 1e9 + 7;
const double eps = 1e-7;
const long long linf = LLONG_MAX;
const int inf = INT_MAX;
const double PI = 3.14159265;
int N, M;
int a[CMAX];
vector<tuple<int, int, int> > queries;
vector<int> ms, ans;
int ll1(int a, int l,... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, INF = 0x3f3f3f3f;
inline int read() {
int x = 0, f = 0;
char ch = 0;
while (!isdigit(ch)) f |= ch == '-', ch = getchar();
while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
return f ? -x : x;
}
int f[N];
int find(int k)... | 9 |
#include <bits/stdc++.h>
using ll = int;
const long long mod = 1e9 + 7;
const ll N = 5e5 + 5;
const int base = 400;
using ull = unsigned long long;
using namespace std;
string s, s1, s2, s3;
ll n, m, t, k, T, cnt, u, tong, v, a[N], ans, b[N], lazy[N * 4], st[N * 4];
vector<ll> adj[N], kq;
struct data {
ll pre, nxt, v... | 16 |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[3003];
int d[3003][3003];
int n, m;
void bfs(int u) {
int U = u;
queue<int> q;
q.push(u);
fill(d[U], d[U] + n, 0x3f3f3f3f);
d[U][u] = 0;
while (!q.empty()) {
u = q.front();
q.pop();
for (int(i) = (0); (i) < (adj[u].size()); ++(i)) {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, a[200005], b[200005];
int main() {
long long int i, j, c = 0, t, l, r, mid, z, k;
scanf("%lld", &n);
scanf("%lld", &m);
for (i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
}
sort(a + 1, a + n + 1);
for (i = 1; i <= n; i++) {
b[i - 1] = a[i... | 14 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-all-loops")
#pragma GCC target("sse4.2")
using namespace std;
ifstream in;
ofstream out;
const long long kk = 1000;
const long long ml = kk * kk;
const long long mod = ml * kk + 7;
const long long inf = ml * ml * ml + 7;
mt19937 rng(chrono::steady_clock::now()... | 22 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 100005, inf = 1000000000000000ll;
long long n, m, c = 1, o, up[maxn];
long double ans[maxn], ansi, d, mini, a, b, first[maxn], second[maxn], l[maxn];
long double e(long double x1, long double y1, long double x2, long double y2) {
long double k1, k2;... | 11 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
int t;
int n, s, k, a[N];
map<int, bool> vis;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> t;
while (t--) ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, q, mx, smx;
long long val[100005], dp[100005], a, b;
int c[100005];
int main() {
scanf("%d%d", &n, &q);
for (int i = 1; i <= n; i++) scanf("%I64d", &val[i]);
for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
while (q--) {
scanf("%I64d%I64d", &a, &b);
f... | 12 |
#include <bits/stdc++.h>
using namespace std;
int bs(vector<pair<long long int, long long int> > v, long long int x) {
int low = 0, high = v.size() - 1;
int ans = -1;
while (low <= high) {
int mid = (low + high) / 2;
if (v[mid].first >= x) {
ans = v[mid].second;
high = mid - 1;
} else
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const double eps = 1e-9;
const double INF = inf;
const double EPS = eps;
int D[42][(1 << 20) + 100];
int N[30];
char s[23][23];
int main() {
int i, j, add, n, k, x, y;
for (i = 0; i < 42; i++)
for (j = 0; j < (1 << 20) + 100; j++) D[i][j] = inf;... | 16 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int power(int x, int n) {
int res = 1;
while (n) {
if (n & 1) {
res = res * x % 1000000007;
}
x = x * x % 1000000007;
n >>= 1;
}
return (res % 1000000007);
}
int fac[1005];
int ncr(int n, int r) {
return fac[n] * (power(fac[n -... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct sumsegtree {
vector<long long> p;
vector<long long> ad;
long long n = 1;
void initfrom(vector<long long> a) {
while (n < a.size()) n *= 2;
p = vector<long long>(2 * n, 0);
ad = vector<long long>(2 * n, 0);
for (int i = 0; i < a.size(); i++) p[... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
if (n < 2) {
cout << 0;
return 0;
} else if (n == 2) {
cout << 1;
return 0;
} else if (n == 3) {
cout << 2;
return 0;
} else if (n == 4) {
cout << 2;
return 0;
} else if (n == 5) {
cout <<... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-13;
const long double PI = acos(-1);
const int INF = (int)1e9;
const long long INFF = (long long)1e18;
const int mod = 998244353;
const int MXN = (int)4e2 + 7;
inline long long add(long long v1, long long v2) {
v1 += v2;
if (v1 >= mod) v1 -= m... | 16 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
long long pw(long long a, long long b) {
long long ret = 1;
long long mul = a;
while (b > 0) {
if (b & 1) ret = (ret * mul);
mul = (mul * mul);
b /= 2;
}
return ret;
}
long long to_int(string s) {
long long ret = 0;
fo... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, m;
vector<int> adj[N];
vector<pair<int, int> > t;
int topic[N];
int tree[N];
void update(int x) {
for (int i = x; i <= N; i += (i & -i)) tree[i] += 1;
}
int query(int x) {
int res = 0;
for (int i = x; i > 0; i -= (i & -i)) res += tree[i];... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, m, cont, dis[10000];
void BFS(int node) {
queue<int> q;
q.push(node);
while (!q.empty()) {
int p = q.front();
q.pop();
if (p == n) {
cout << dis[p] << endl;
return;
} else {
if (dis[p + 1] == 0) {
q.push(p + 1);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int l, p;
int mini = 1000000000;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d%d", &l, &p);
mini = min(mini, p - l + 1);
}
printf("%d\n", mini);
for (int i = 1; i <= n; i++) printf("%d ", (i % mini));
printf("\n")... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 50, INF = (int)1e9;
const double EPS = 1e-5;
int n, m;
int sq;
vector<int> G[N];
stack<int> S;
int vis[N], dep[N];
vector<int> is;
int dfs(int v, int p, int d) {
dep[v] = d;
vis[v] = 1;
S.push(v);
int mn = INF;
for (int nxt : G[v]) {
i... | 13 |
#include <bits/stdc++.h>
using namespace std;
constexpr int maxn = 1e5 + 7, maxm = 2e2 + 7, mod = 1e9 + 7;
const auto fast = (cin.tie(0), cout.tie(0), ios::sync_with_stdio(0));
inline int add(int x, int y) { return (x + y) % mod; }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
int n, m, a;
array<int, maxm>... | 22 |
#include <bits/stdc++.h>
using namespace std;
int n, ar[1000000], ars[1000000], ans = 0;
string s = "";
int main() {
cin >> n;
n++;
for (int i = 0; i < n; i++) scanf("%d%d", &ar[i], &ars[i]);
for (int i = 0; i < n - 1; i++) {
if (ar[i] != ar[i + 1]) {
if (ar[i] < ar[i + 1]) {
s = s + 'R';
... | 7 |
#include <bits/stdc++.h>
long long mpow(long long a, long long n, long long mod) {
long long ret = 1;
long long b = a;
while (n) {
if (n & 1) ret = (ret * b) % mod;
b = (b * b) % mod;
n >>= 1;
}
return (long long)ret;
}
inline void read(int &x) {
x = 0;
register char c = getchar();
for (; c ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, tem;
long long n, m;
long long l, j;
cin >> t;
for (int i = 0; i < t; i++) {
cin >> n >> m;
cin >> l >> j;
tem = (l - n) * (j - m) + 1;
cout << tem << endl;
}
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int q, n, i = 1, ttl = 0;
cin >> q;
while (q--) {
cin >> n;
if (n <= 1) {
cout << ttl << endl;
} else {
while (n != 1) {
if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0) {
if (i <= 4) {
if (n % (i... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 2000;
vector<int> V[MAX];
vector<int> G[MAX];
vector<int> VV[MAX];
vector<int> GV[MAX];
long long MV[MAX];
long long MG[MAX];
long long A[MAX][MAX];
long long _BV(long long i, long long x) {
long long l = 0, r = VV[i].size() - 1, mid;
while (r - l ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
double fixAngle(double A) { return A > 1 ? 1 : (A < -1 ? -1 : A); }
double dcmp(double a, double b) {
return fabs(a - b) < 1e-6 ? 0 : a > b ? 1 : -1;
}
vector<pair<int, int>> graph1[1000 + 10];
vector<pair<int, int>> graph2[1000 + 10];
vector... | 11 |
#include <bits/stdc++.h>
using namespace std;
char s[50005];
int val[50005][2], sum;
long long ans;
priority_queue<pair<int, int>, vector<pair<int, int> >,
greater<pair<int, int> > >
Q;
int main() {
scanf("%s", s);
for (int i = 0; s[i]; ++i)
if (s[i] == '?') scanf("%d%d", &val[i][0], &val[i][... | 18 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.