solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
template <typename A>
void _do(A x) {
cerr << x << "\n";
}
template <typename A, typename... B>
void _do(A x, B... y) {
cerr << x << ", ";
_do(y...);
}
long long n, k;
long long p[20];
pair<long long, long long> seg[100005];
vector<int> in[600005], out[600005];
vector... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 5e3 + 10;
vector<int> v[N];
int main() {
int n;
scanf("%d", &n);
set<pair<int, int>> sp;
for (int i = 1; i <= n; i++) {
int sz;
int a, x, y, m;
scanf("%d%d%d%d%d", &sz, &a, &x, &y, &m);
auto& vp = v[i];
... | 4 |
#include <bits/stdc++.h>
struct node {
int data;
int a;
} p[2000005];
int main() {
int n, i;
double sum = 0;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &p[i].data);
sum += p[i].data;
p[i].a = i;
}
double ave;
ave = (double)sum / n;
int count = 0;
for (i = 1; i <= n; i++) {... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long sum = 0, temp;
char s[100001];
int finder(int i) {
int kol = 1;
for (int j = 0; s[j] != 0; ++j) {
if (j != i && s[j] == s[i]) {
kol++;
s[j] = 3;
}
}
return kol;
}
int main() {
gets(s);
for (int i = 0; s[i] != 0; ++i) {
if (s[i] ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
signed main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
long long int TESTS = 1;
while (TESTS--) {
long long n, m;
cin >> n >> m;
long long... | 4 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int u, int v) { return (v != 0) ? gcd(v, u % v) : u; }
int win(int hp1, int atk1, int def1, int hp2, int atk2, int def2) {
double f = max(0, atk1 - def2);
double s = max(0, atk2 - def1);
double s2 = ceil(hp2 / f);
double s1 = ceil(hp1 / s);
if (s1 > s2) re... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b;
cin >> n >> a >> b;
cout << (n - max(a + 1, n - b) + 1);
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
int A[1000000 + 5];
vector<int> B;
void solve(void) {
int i;
long long mn_bunja, mn_bunmo;
B.clear();
sort(A, A + n);
i = 0;
while (i < n) {
if (i + 1 < n && A[i] == A[i + 1]) {
B.push_back(A[i]);
i++;
}
i++;
}
mn_bunja = mn_bu... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k, i, j, c = 0;
cin >> n >> k;
vector<int> a(n + 1), f(100005, 0), f2(100005, 0);
a[0] = 0;
for (i = 1; i <= n; i++) cin >> a[i];
for (i = 1; i <= n; i++) {
if (f[a[i]] == ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, SQ = 500;
int a[N], t[N], x[N], p[N], Cnt[2 * N][N / SQ + 5], T[N][N / SQ + 5], n;
vector<int> num;
void Build() {
for (int i = 0; i < n; i++) {
a[i] = lower_bound(num.begin(), num.end(), a[i]) - num.begin();
Cnt[a[i]][i / SQ + 1]++;
}
f... | 11 |
#include <bits/stdc++.h>
using namespace std;
bool isPrime[100005];
int n;
void pre() {
for (int i = 2; i <= n + 1; i++) isPrime[i] = 1;
for (int i = 2; i <= n + 1; i++) {
if (isPrime[i]) {
for (int j = i + i; j <= n + 1; j += i) isPrime[j] = 0;
}
}
}
int main() {
cin >> n;
pre();
if (n < 3)
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = INT_MAX;
long long a, b, c, d, n, j, i, k, l, m;
map<int, int> mp;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
if (n == 2) return cout << 2 << " " << 1, 0;
if (n % 2 == 1) {
cout << 1 << " ";
for (i = 2; i ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100001;
struct num {
int key, id;
num(int key_ = 0, int id_ = 0) {
key = key_;
id = id_;
}
} t_[MAXN], x_[MAXN];
struct que {
int op, t, x, id;
que(int op_ = 0, int t_ = 0, int x_ = 0, int id_ = 0) {
op = op_;
t = t_;
x = x_;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
int inp[100005];
int main() {
int n, a, b;
cin >> n;
int flag = 0;
string str;
for (int i = 0; i < n; i++) {
cin >> str;
int a, b;
cin >> a >> b;
if (a >= 2400 && b > 2400 && b - a > 0... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
char a[1000005];
int q;
struct node {
int optimal;
int open;
int close;
node(int op = 0, int cl = 0, int o = 0) {
optimal = op;
open = o;
close = cl;
}
};
node t[4 * 1000005];
node operator+(const node &left, const node &right) {
node res;
i... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1e9;
long long max(long long a, long long b, long long c) {
return max(a, max(b, c));
}
long long n;
long long house[200011];
long long mn[200011][2][2];
long long mx[200011][2][2];
long long f(long long i, long long j, long long k) {
if... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t--) {
int N;
scanf("%d", &N);
string str;
cin >> str;
int cnt0 = 0;
int cnt1 = 0;
for (int i = 1; i < N; i++) {
if (str[i] == str[i - 1] && str[i] == '0')
cnt0++;
else if (str... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double h, w;
cin >> h >> w;
float rat = float(h) / float(w);
if (rat > 1.25) {
if ((ceil(log2(w)) == floor(log2(w))) ? 1 : 0) {
h = floor(w * 1.25);
} else {
if (!(ceil(log2(h)) == floor(log2(h))) ? 1 : 0) h = pow(2, int(log2(h)));
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, a, b, s = 1, d = 2, q[105][105];
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> a >> b;
for (int i = 1; i <= a; ++i) {
for (int j = 1; j <= b; ++j) {
q[i][j] = 0;
if ((i + j) % 2 == 0) {
if (s <= n) {
q[i][j] = s;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k = 0, x, y;
const int P = 239017;
long long t;
int adj[1001][1001], dp[1001] = {}, a[1001];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
vector<int> a(n + 1);
map<int, int> h, c;
int p = 0;
set<pair<int, int>> f;
... | 4 |
#include <bits/stdc++.h>
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); }
unsigned long long power(unsigned long long a, unsigned long long b) {
a %= 1000000007;
unsigned long long res = 1;
while (b ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int arr[100005];
int main(void) {
int k, d;
cin.sync_with_stdio(false);
cin >> k >> d;
if (d == 0) {
if (k == 1)
cout << "0\n";
else
cout << "No solution\n";
return 0;
}
if (d <= k)
for (int i = 1; i <= d; i++) arr[i] = 1;
else
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[200020], b[100100];
int main() {
int n, ans = 0, i, max = 0;
cin >> n;
n = n * 2;
for (i = 1; i <= n; i++) {
cin >> a[i];
if (b[a[i]] == 1) {
b[a[i]] = 0;
ans--;
} else
ans++;
b[a[i]]++;
if (ans >= max) max = ans;
}
co... | 0 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> mem[102][3][2][2][2];
int x[101], y[101], b[11][11], n;
vector<int> dx[3], dy[3], un;
void init() {
for (int k = 0; k <= n * n + 1; ++k) {
for (int f = 0; f < 3; ++f) {
for (int l = 0; l < 2; ++l) {
for (int d = 0; d < 2; ++d) {
... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
const int N = 600 + 5, lg = 27, mod = 5e4 + 7;
int da[N][N];
void solve() {
int n, t;
cin >> n >> t;
queue<pair<int, int>> q;
q.push({300, 300});
da[300][300] = n... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long fact[1000005];
long long p(long long n, long long k) {
if (k == 0) return 1;
if (k == 1) return n;
long long x = p(n, k / 2) % 998244353;
if (k & 1) return (((x * x) % 998244353) * n) % 998244353;
return (x * x) % 998244353;
}
long long n... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1, c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f == 1 ? x : -x;
}
const int N = 104, M = 10004;
in... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x1 = 0, x2 = 0, a, n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a;
if (a % 2 == 1) {
x1++;
} else
x2++;
}
cout << min(x1, x2);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v, vp[200009];
vector<int>::iterator it;
int arr[200009];
int main() {
int n, i, j, k, l, m;
cin >> n;
for (i = 0; i < n; i++) {
cin >> arr[i];
}
for (i = 0; i < n; i++) v.push_back(0);
vp[n - 1].push_back(arr[0]);
v[n - 1] = arr[0];
for (i =... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void write(T x) {
if (x == 0) {
putchar('0');
return;
}
if (x < 0) x = -x, putchar('-');
static char stk[1024];
int top = 0;
while (x != 0) stk[top++] = x % 10, x /= 10;
while (top) putchar(stk[--top] + '0');
}
const int Len =... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long arr[200005], ans[200005];
map<long long, long long> memo;
vector<pair<long long, long long> > V[200005];
vector<long long> t;
int main() {
long long n, q;
scanf("%lld %lld", &n, &q);
for (long long i = 1; i <= n; i++) scanf("%lld", &arr[i]);
for (long long... | 8 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define fir first
#define sec second
#define pb emplace_back
#define gc() getchar()
inline int read()
{
int now=0,f=1; char c=gc();
for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
for(;isdigit(c);now=now*10+c-48,c=gc())... | 1 |
#include <bits/stdc++.h>
using namespace std;
void enable_comma() {}
string tostring(char c) {
string s = "";
s += c;
return s;
}
string tostring(string s) { return "\"" + s + "\""; }
string tostring(const char *c) { return tostring((string)c); }
string tostring(long long x) {
if (x < 0) return "-" + tostring(-... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7, INF = 1e9 + 7;
pair<int, int> tr[4 * N];
int lz[4 * N];
pair<int, int> merge(const pair<int, int> &a, const pair<int, int> &b) {
return pair<int, int>(max(a.first, b.first), min(a.second, b.second));
}
void propagate(int u, int st, int en) {
if (!... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long int NchooseK(int n, int k) {
if (k == 0) return 1;
return (n * NchooseK(n - 1, k - 1)) / k;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
double s = 0;
cin >> n;
vector<int> a(n);
... | 2 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
uint64_t H, L;
cin >> H >> L;
cout << (L * L - H * H) / (2.0 * H);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
cout << fixed << setprecision(13);
while (t--) {
solve();
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m;
cin >> n >> m;
long long int A[n], B[m];
for (long long int i = 0; i < n; i++) {
cin >> A[i];
}
for (long long int i = 0; i < m; i++) {
cin >> B[i];
}
long long p = -1e18;
long long C[n];
for (long long int i = 0;... | 3 |
#include <bits/stdc++.h>
using namespace std;
FILE* _fin = stdin;
FILE* _fout = stdout;
int _min(int a, int b) { return a <= b ? a : b; }
long long _min(long long a, long long b) { return a <= b ? a : b; }
int _max(int a, int b) { return a >= b ? a : b; }
long long _max(long long a, long long b) { return a >= b ? a : b... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, t;
cin >> n >> t;
int f = 0;
int x;
int sum = 1;
for (int i = 1; i < n; i++) {
cin >> x;
if (i == sum) sum += x;
if (sum == t) f = 1;
}
if (f == 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
template <class T>
T abs(T x) {
return x > 0 ? x : -x;
}
int n;
int m;
double a[10000];
double p;
int good(double x) {
double x1 = 0, x2 = 0;
for (int i = 0; i < (n); i++)
if (a[i] >= x)
x1 += a[i] - x;
else
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 201 * 1001;
struct node {
int l, r, h, b, lazyb, lazya, ans;
} p[N];
inline void add(int id, int x, int y) {
p[id].b += x;
p[id].lazyb += x;
p[id].ans += y;
p[id].lazya += y;
}
inline void shift(int x) {
int l = p[x].l, r = p[x].r;
if (r != -1) a... | 10 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long n, adin;
bool daun = 0;
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> adin;
daun = 0;
for (long long big = 1; big < (long long)1e6; big++) {
if (big * big >= adin) {
for (long long small = 1; small <= big; s... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, k, x, t;
long long a[200100];
long long ans, tmp, tmp1;
int b[100];
long long Power(long long u, int v) {
long long tmp = 1;
for (int i = 0; i < k; i++) tmp *= x;
return tmp;
}
int main() {
while (~scanf("%d%d%d", &n, &k, &x)) {
for (int i = 0; i < n; i++... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s1[50], s2[50];
cin >> s1 >> s2;
long long left = 0, right = 0, mid = 0, l;
l = strlen(s1);
for (long long i = 0; i < l; i++)
if (s1[i] == '|') {
mid = i;
break;
}
left = mid;
right = l - (mid + 1);
if ((strlen(s1) + str... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
scanf("%d:%d", &x, &y);
x %= 12;
printf("%.10lf %d\n", x * 30 + y * 0.5, y * 6);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
long long max_(long long a, long long b) { return a > b ? a : b; }
int main() {
long long n;
scanf("%lld", &n);
if (n == 1 || n == 2)
printf("1\n");
else {
long long x = 4, y = 5;
while (max_(x, y) < n) {
int xx = x, yy = y;
if (x & 1)
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int sol[200000 + 10];
int timelim = 0;
struct node {
int l;
int r;
int d;
} Node[200000 + 10];
bool ccc(int a, int b) { return a > b; }
bool cmp(struct node a, struct node b) { return a.l < b.l; }
int my_max(int a, int b) { return a > b ? a : b; }
bool check(int abil,... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int T, n;
int a[N], ans[N], tot = 0;
int ask(int first) { return a[first] ^ a[first + 1] ^ a[first + 2]; }
void flip(int first) {
if (a[first] == a[first + 1] && a[first + 1] == a[first + 2]) return;
a[first] = a[first + 1] = a[first + 2] =
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
long long n, k;
cin >> n >> k;
vector<long long> a(n);
for (long long i = 0, ThxDem = n; i < ThxDem; ++i) cin >> a[i];
vector<long long> b = a;... | 0 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
int r;
while (b != 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
struct Fraction {
public:
int numerator;
int denominator;
public:
Fraction(const int numerator, const int denominator) {
this->numerator = numerator;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int odd[1050000], even[1050000];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long int n, i, j, k, temp, c = 0, mid;
cin >> n;
long long int a[n], Xor[n];
for (i = 0; i < n; i++) {
cin >> a[i];
if (i)
Xor[i] = Xor[i - 1... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m, mod = 1e9 + 7;
cin >> n >> m;
int a[26][m];
memset(a, 0, sizeof a);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
char x;
cin >> x;
a[x - 'A'][j]... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
long long n, H;
bool check(long long x) {
if (x <= H) {
if (x >= INF) return true;
return x * (x + 1) >= 2LL * n;
} else if ((x - H) & 1) {
long long A = (x - H) / 2;
return A * (2 * H + A - 1) / 2 + H + A + (1 + H + A) * (H + A) / 2... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3 * 1e5 + 100;
int n, m, a[N], match[N], L[N], R[N], w, vi[N];
vector<tuple<int, int, int> > e, E;
vector<pair<int, int> > to[N];
inline int read() {
int f = 1, x = 0;
char s = getchar();
while (s < '0' || s > '9') {
if (s == '-') f = -1;
s = get... | 12 |
#include <bits/stdc++.h>
using namespace std;
int a[30];
map<long long, int> mp;
int main() {
string s;
cin >> s;
string in;
cin >> in;
int k;
cin >> k;
long long ans = 0;
for (int i = 0; i < s.size(); i++) {
int bc = 0;
long long hash = 0;
for (int j = i; j < s.size(); j++) {
hash = (... | 5 |
#include <bits/stdc++.h>
const int maxn = 4405;
const long long inf = 1e17 + 7;
template <typename T>
inline T max(const T &a, const T &b) {
return a > b ? a : b;
}
template <typename T>
inline T min(const T &a, const T &b) {
return a < b ? a : b;
}
struct edge {
int v, nxt, w;
long long f;
} e[maxn << 3];
int ... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct SegmentTree {
struct Node {
int l, r;
int mx, lzy;
};
Node seg[2000000];
void build(int l, int r, int idx) {
seg[idx].l = l, seg[idx].r = r;
if (l == r) {
return;
}
int mid = l + r >> 1;
build(l, mid, 2 * idx);
build(mid ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
cin >> t;
while (t--) {
long long int n, k;
cin >> n >> k;
long long int s = 0;
long long int x = 1;
while (x < n) {
if (x <= k) {
s++;
... | 1 |
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, a1, c1, h2, a2;
cin >> h1 >> a1 >> c1 >> h2 >> a2;
int sum = 0;
int h11 = h1, a11 = a1, c11 = c1, h22 = h2, a22 = a2;
while (h22 > 0) {
sum++;
if (h11 - a22 > 0 || h22 - a11 <= 0)
h22 -= a11;
else
h11 += c11;
h11 -=... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long a[30], sum;
map<long long, long long> m[30];
int main() {
for (int i = 0; i < 26; i++) cin >> a[i];
string s;
cin >> s;
int n = s.size();
long long res = 0;
for (int i = 0; i < n; i++) {
res += m[s[i] - 'a'][sum];
sum += a[s[i] - 'a'];
m[s[... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char arr[10][10];
string s1, s2, s3;
for (int i = 1; i <= 9; i++) {
cin >> s1;
cin >> s2;
cin >> s3;
for (int j = 1; j <= 3; j++) {
arr[i][j] = s1[j - 1];
arr[i][j + 3] = s2[j - 1];
arr[i][j + 6] = s3[j - 1];
}
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, q;
int p[100005];
int search(int x) {
int in;
int l, r, mid;
l = 1, r = n;
while (l < r) {
mid = l + r;
mid >>= 1;
if (p[mid] >= x)
r = mid;
else
l = mid + 1;
}
return l;
}
int main() {
ios_base::sync_with_stdio(false);
cin... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200011;
struct Frac {
long long n, d;
Frac(long long n, long long d) : n(n), d(d) {}
bool operator<(const Frac &rhs) const {
return (long long)n * rhs.d < (long long)d * rhs.n;
}
bool operator==(const Frac &rhs) const {
return (long long)n * ... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long f(long long pre, long long k) {
if (pre < 0)
return -pre / k + (pre % k != 0);
else
return -pre / k;
}
int main() {
long long p, k;
cin >> p >> k;
vector<long long> q;
q.push_back(f(p, k));
while (q.back() != 0) {
q.push_back(f(q.back(), ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
int read() {
int x = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * w;
}
int... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T gi() {
T x = 0;
bool f = 0;
char c = getchar();
while (c != '-' && (c < '0' || c > '9')) c = getchar();
if (c == '-') f = 1, c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return f ? -x : x;
}
const int N ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, q;
vector<int> adj[200005];
int a[200005], p[200005], idx[200005], h[200005];
int Lg[500005];
int in[200005], t[500005], euler;
void dfs(int u) {
in[u] = ++euler;
t[euler] = u;
for (auto v : adj[u]) {
h[v] = h[u] + 1;
dfs(v);
t[++euler] = u;
}
}
i... | 10 |
#include <bits/stdc++.h>
using namespace std;
int a, s, d, f, g, h, j, k, l, i, n, m;
vector<pair<int, int> > v[200002];
vector<int> pas[200003];
void dfs(int idx, int par, int nl, int er) {
if (er - nl == a) {
pas[a].push_back(idx);
}
if (er - nl > a) {
a = er - nl;
pas[a].push_back(idx);
}
for (... | 4 |
#include <bits/stdc++.h>
using namespace std;
const string alphabet{"abcdefghijklmnopqrstuvwxyzab"};
string solve(string& s) {
int N = s.size();
auto last = s[0];
for (int i = 1; i < N; ++i) {
if (s[i] == last) {
auto next = alphabet[s[i] - 'a' + 1];
if (i < N - 1 and s[i + 1] == next) next = alph... | 2 |
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#include <immintrin.h>
//#include <emmintrin.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,h,t) for (int i=h;i<=t;i++)
#define dep(i,t,h) fo... | 7 |
#include <bits/stdc++.h>
using namespace std;
int a[3100];
int main() {
int n, i, k, j;
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d", &a[i]);
k = 0;
for (i = 0; i < n; i++)
for (j = i + 1; j < n; j++)
if (a[i] > a[j]) k++;
printf("%.6lf\n", (double)((k & 1) ? ((k << 1) - 1) : k << 1));
}
| 5 |
#include <bits/stdc++.h>
long long f[5005];
using namespace std;
int main() {
int n, i, j;
cin >> n;
int a[n + 1], b[n + 1];
for (i = 1; i <= n; i++) scanf("%d", &a[i]), b[i] = a[i];
sort(b + 1, b + n + 1);
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
f[j] += abs(b[j] - a[i]);
if (j... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1111;
const long long inf = 1ll << 40;
struct Edge {
int v, next;
long long len;
} edge[2000000];
long long Point[MaxN];
int tot;
void insert(int u, int v, long long w) {
edge[tot].v = v, edge[tot].len = w, edge[tot].next = Point[u];
Point[u] = tot+... | 5 |
#include <bits/stdc++.h>
using namespace std;
int p[201000];
int a[201000];
int vis[201000];
int main() {
int n;
scanf("%d", &n);
int ans = 0, op = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= n; i++) {
if (vis[i] == 0) {
ans++;
int x = i;
while (!vi... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[4];
int e, f;
void ReadInput() {
for (int i = 0; i < 4; ++i) cin >> a[i];
cin >> e >> f;
}
void Solve() {
if (e > f) {
int temp = min(a[0], a[3]);
int ans = e * temp;
a[3] -= temp;
temp = min(a[1], min(a[2], a[3]));
ans += f * temp;
cout ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 5;
const long long INF = 1e18;
const int MOD = 998244353;
int n, m;
vector<pair<long long, long long>> edges1[20 * M], edges2[M << 1];
long long dis[20 * M];
long long c2 = 1e8;
void dij(int x, vector<pair<long long, long long>> adj[], int k) {
priorit... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void print(T &&first) {
cout << first << endl;
}
template <typename Head, typename... Tail>
void print(Head &&h, Tail &&...t) {
cout << h << " ";
print(std::forward<Tail &&>(t)...);
}
template <typename... T>
void read(T &...args) {
((cin >> ar... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300 * 1000 + 100;
const long long mod = 1e9 + 7;
const long long inf = 2 * 1e18;
const int delta = 10909;
int x11, y11, x12, y12, x13, y13, x14, y14, x21, x22, x23, x24, y21, y22, y23,
y24;
map<pair<int, int>, int> t;
int main() {
ios::sync_with_stdio... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
scanf("%d", &q);
for (int i = 0; i < q; i++) {
int l, r, d;
scanf("%d %d %d", &l, &r, &d);
if ((double)l / d > 1)
printf("%d\n", d);
else {
int f = ((double)r / d) + 1;
printf("%d\n", f * d);
}
}
return 0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long dx[] = {1, 0, -1, 0};
long long dy[] = {0, 1, 0, -1};
char dc[] = {'D', 'R', 'U', 'L'};
void solve() {
long long a1, a2, b1, b2;
cin >> a1 >> b1 >> a2 >> b2;
if (a1 == a2 && b1 == b2) {
cout << 0 << '\n';
return;
}
if (a1 == a2 || b1 == b2) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
const long long Lim = 1e14;
const long long M = 1e7;
int flag[M], f[M];
int b[15];
vector<pair<int, int> > Q[15][2];
inline int calc(int x, int flag, long long now, long long &k) {
if (now >= M) return -1;
int st = lower_bound(Q[x][flag].begin(), Q[x][fl... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxsize = 100;
int a[3][maxsize] = {0};
int b[maxsize] = {0};
int n;
int calc(int x) {
int res = 0;
res += b[x];
for (int i = 1; i < x; i++) res += a[1][i];
for (int i = x; i < n; i++) res += a[2][i];
return res;
}
int main() {
scanf("%d", &n);
for (... | 2 |
#include <bits/stdc++.h>
using namespace std;
int memo[100005], pd[100005];
int grundy(int n) {
if (n <= 2) return 0;
int &ret = memo[n];
if (ret != -1) return ret;
set<int> MEX;
pd[n] = (1 << 30);
for (int i = 2; i * i <= 2 * n; i++) {
int xi = (2 * n) / i - 1 + i;
if ((2 * n) % i != 0) continue;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long int module = 1000000007;
int main() {
int64_t ans;
long int a[2][2001] = {0}, n, i, j, k, m, x;
cin >> n >> k;
for (i = 1; i <= n; i++) a[0][i] = 1;
long int crow = 0;
for (i = 1; i < k; i++) {
crow = 1 - crow;
for (j = 1; j <= n; j++) a[crow]... | 3 |
#include <bits/stdc++.h>
int main() {
int ans, i, j, minmark, m, n, sum, l[101], r[101], t[101], c[101];
scanf("%d%d", &n, &m);
for (i = 0; i < m; i++) scanf("%d%d%d%d", &l[i], &r[i], &t[i], &c[i]);
sum = 0;
for (i = 1; i <= n; i++) {
ans = 1001;
minmark = -1;
for (j = 0; j < m; j++) {
if (i... | 2 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
int aabs(int a) {
if (a < 0) return -a;
return a;
}
int gcd(int a, int b) {
while (a > 0 && b > 0) {
if (a > b) {
a %= b;
} else {
b %= a;
}
}
return a + b;
}
vector<int> g[100013];
bool used[1000... | 4 |
#include <bits/stdc++.h>
using namespace std;
int s[30] = {0, 2, 3, 5, 7, 11, 13, 17, 19};
int cs[30];
int a[10005], N, cnt, ans[10005], m, pp;
void dfs(int k, int t) {
a[++cnt] = k;
while (t <= 5) {
if (k * s[t] <= 50000000) dfs(k * s[t], t);
t++;
}
return;
}
int pd[10], visit[10000];
void f(int k, int... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int n, tmp;
long long ans = 0;
int tree[maxn];
set<pair<int, int> > q;
inline int read() {
int ret = 0;
char ch = getchar();
while (!isdigit(ch)) ch = getchar();
while (isdigit(ch)) {
ret = (ret << 3) + (ret << 1) + (ch ^ 48);
ch = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, day = 0;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a >> b;
if (a > day) {
day = a;
} else {
day++;
int mod = a % b;
if (day % b > mod)
day = day + b - day % b + mod;
else
day = d... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct mycomp {
bool operator()(pair<int, int> const& a, pair<int, int> const& b) {
if (a.first == b.first) return a.second > b.second;
}
};
int64_t ceil_div(int64_t a, int64_t b) { return (a + b - 1) / b; }
int64_t fact(signed long long int n) {
return (n == 1 ||... | 0 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) { cout << x; }
void __print(long x) { cout << x; }
void __print(long long x) { ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
vector<vector<int> > lca;
int n;
int timer;
vector<int> tin, tout;
vector<vector<int> > adj;
map<pair<int, int>, int> hsh;
void dfs(int cur, int par) {
tin[cur] = ++timer;
lca[cur][0] = par;
for (int i = 1; i <= 20; i++) lca[cur][i] = lca... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class free>
inline void Min(free&, free);
template <class free>
inline void Max(free&, free);
struct inter {
int l, r, id, id1;
inline void operator^=(const inter x) { Max(l, x.l), Min(r, x.r); }
inline inter operator^(const inter x) { return {max(l, x.l), m... | 12 |
#include <bits/stdc++.h>
using namespace std;
void swap(int &x, int &y) {
int temp = x;
x = y;
y = temp;
}
int main() {
int arr[104], n, i, j;
cin >> n;
for (i = 0; i < n; i++) cin >> arr[i];
for (i = 0; i < n - 1; i++)
for (j = 0; j < n - 1 - i; j++) {
if (arr[j] > arr[j + 1]) {
cout <<... | 1 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e2+1e1+7,P=998244353;
int n;
vector<int>G[N];
int r;
int f[2][N][N],dep[N];
int g[2][N];
void inc(int &a,int b)
{
a+=b;
a>=P?a-=P:0;
}
void dfs(int x,int fa)
{
dep[x]=0;
for(int i=1;i<=n;i++)
f[0][x][i]=f[1]... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1100;
int n;
int a;
double minv = 10.0, maxv = 1e8;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a);
double v1 = a * 10.0 / i;
if (minv < v1) minv = v1;
double v2 = (a + 1) * 10.0 / i;
if (v2 < maxv) maxv... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long ss[60000];
long long sum = 0;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> ss[i];
sum = ss[i] + sum;
}
long long mov = 0;
long long bi = sum / n;
for (int i = 0; i < n - 1; i++) {
mov = mov + fabs(ss[i] - bi);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int h[100];
int a[100];
int main(int argc, char const *argv[]) {
string hName, aName;
cin >> hName >> aName;
int count;
cin >> count;
for (int i = 0; i < count; i++) {
int min, numb;
char c, s, color;
cin >> min >> c >> numb >> color;
if (c == 'h')... | 2 |
#include <bits/stdc++.h>
using namespace std;
int perm[6];
vector<string> an[750];
int cnt;
string ss[6];
void check() {
int s1 = perm[0], s2 = perm[1], s3 = perm[2];
int s4 = perm[3], s5 = perm[4], s6 = perm[5];
if (ss[s1][0] == ss[s2][0] && ss[s3][0] == ss[s1][ss[s1].size() - 1] &&
ss[s3].size() >= ss[s2]... | 6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.