solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
cin >> n >> m >> k;
long long ans = 0;
vector<int> a(m), b(m), c(m), x(k);
for (int i = 0; i < m; i++) cin >> a[i] >> b[i] >> c[i];
for (int i = 0; i < x.size(); i++) cin >> x[i];
for (int i = 0; i < m; i++) {
for (int j = 0; j < ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
if ((n * (n - 1)) / 2 > k) {
for (int i = 1; i <= n; i++) cout << "1 " << i << endl;
} else
cout << "no solution" << endl;
return 0;
}
| 5 |
#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), ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, k, a[100010];
map<int, int> m;
set<int> p;
int main() {
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < k; i++) {
m[a[i]]++;
if (m[a[i]] == 1)
p.insert(a[i]);
else
p.erase(a[i]);
}
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
double x, y, x1, y1, x2, y2, t;
cin >> x >> y >> x1 >> y1 >> x2 >> y2;
t = (x1 - x) * (y2 - y1) - (y1 - y) * (x2 - x1);
if (!t)
cout << "TOWARDS";
else if (t > 0)
cout << "LEFT";
else
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n1, n2, k1, k2;
int limit1, limit2;
int dp[101][101][11][11];
int dfs(int n1, int n2, int k1, int k2) {
if (n1 + n2 == 0) return 1;
if (dp[n1][n2][k1][k2] != -1) return dp[n1][n2][k1][k2];
int x = 0;
int y = 0;
if (n1 > 0 && k1 > 0) x = dfs(n1 - 1, n2, k1 - 1,... | 9 |
#include <bits/stdc++.h>
using namespace std;
int jump(vector<int> &arr, int x, int p) {
int j = 0;
for (int i = 0; i < arr.size(); i++) {
if ((j + 1) % 2 == p) {
if (arr[i] <= x) j++;
} else
j++;
}
return j;
}
bool possible(vector<int> &arr, int x, int k) {
return jump(arr, x, 1) >= k || ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
const int INFINITE = 0x3f3f3f3f;
template <class T>
inline void checkmin(T &a, T b) {
if (b < a) a = b;
}
template <class T>
inline void checkmax(T &a, T b) {
if (b > a) a = b;
}
template <class T>
inline T sqr(T x... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10005;
vector<int> E[maxn];
bool vis[maxn];
int vlink[maxn], ulink[maxn], n1, a[maxn], b[maxn], c[maxn], w[maxn], ans[maxn];
bool dfs(int u) {
for (int j = 0; j < E[u].size(); j++) {
int i = E[u][j];
if (!vis[i]) {
vis[i] = true;
if (v... | 16 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void amin(T &x, U y) {
if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
if (x < y) x = y;
}
int main() {
int n;
cin >> n;
int x, y;
cin >> x >> y;
int a, b;
char c;
vector<pair<pai... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
const int mo = 1e9 + 7;
int a[N];
int main() {
int n, D;
scanf("%d%d", &n, &D);
for (int i = (1); i <= (n); ++i) scanf("%d", &a[i]);
int t = 0, m;
scanf("%d", &m);
for (int i = (1); i <= (m); ++i) {
int x;
scanf("%d", &x);
whi... | 23 |
#include <bits/stdc++.h>
using namespace std;
int dp[5010][5010] = {0};
int main() {
int n, m;
cin >> n >> m;
string a, b;
cin >> a >> b;
int ans = 0;
a = " " + a;
b = " " + b;
for (int i = 1; i <= a.length() - 1; ++i) {
for (int j = 1; j <= b.length() - 1; ++j) {
if (a[i] == b[j]) {
d... | 10 |
#include <bits/stdc++.h>
const int N = 305;
using namespace std;
map<int, int> mp;
int l[N], c[N];
vector<pair<int, int> > f[N];
int gcd(int a, int b) {
int q = a % b;
while (q != 0) {
a = b;
b = q;
q = a % b;
}
return b;
}
int main() {
int n;
scanf("%d", &n);
int i, j, k, t;
for (i = 0; i <... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, a[200001], b[200001], d[200001], cnt, res;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
d[a[i]] = i;
}
for (int i = 1; i <= n; i++) {
scanf("%d", &b[i]);
if (res < d[b[i]]) {
cout << d[b[i]] - res << " ";
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long b, m;
int main() {
scanf("%lld%lld", &m, &b);
long long ans = 0;
for (long long h = b; h >= 0; h -= 1ll) {
long long w = ((b - h) * m);
long long temp = (((0 + h) * (h + 1ll)) / 2ll) * (w + 1ll) +
(((0 + w) * (w + 1ll)) / 2ll) * ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m, *a, *indexes;
int search(int arr[], int size, int searchNum) {
int mid;
mid = arr[size / 2];
if (mid == searchNum) {
return indexes[mid - 1];
} else {
for (int i = (size / 2); i > 0; i--) {
if (arr[i] == searchNum) {
return indexes[i ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000001, M = 11111111;
long long MOD = 998244353, inv2 = (MOD + 1) / 2;
int INF = int(1e9);
long double eps = 1e-8;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
long double pi = acos(-1.0L);
int read() {
int v = 0, f = 1;
char c = getchar();
whi... | 14 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int MAX = 500009;
const long long MOD = 1000000007;
long long pw(long long base, long long expo, long long c) {
if (expo == 0) return 1;
long long f = pw(base, expo / 2, c);
if (expo & 1) return (((f * f) % c) * base) % c;
return (f * ... | 3 |
#include <bits/stdc++.h>
using namespace std;
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 31; i >= 0; i--) {
int t = 1 << i;
int c = 0;
int j = 0;
for (int k = 0; k < n; k++... | 7 |
#include <bits/stdc++.h>
using namespace std;
int yes[100010], no[100010];
int mem[100010], nc;
bool crime[100010];
int n, m, syes, sno;
int main() {
int i, j;
scanf("%d %d", &n, &m);
for (i = 1; i <= n; i++) {
scanf("%d", &mem[i]);
if (mem[i] > 0) {
yes[mem[i]] += 1;
syes += 1;
} else {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, ans;
while (cin >> n) {
if (n == 1)
ans = 1;
else if (n == 2)
ans = 2;
else if (n == 3)
ans = 6;
else if (n % 2 == 0) {
if (n % 3 == 0)
ans = (n - 1) * (n - 2) * (n - 3);
else
ans = ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 50;
const int INF = 1 << 30;
int a[70];
long long dp[15][75][1 << 11];
long long dfs(int pos, int s, bool limit, bool lead, int j) {
if (pos == -1) {
return (s == 0);
}
if (!limit && !lead && dp[j][pos][s] != -1) return dp[j][pos][s];
i... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, K;
long long ans = -1;
int now[50];
pair<int, int> X[100005], Y[100005];
void work(int z1, int z2, int z3, int z4) {
int ct = 0;
for (int i = n; i >= n - z1 + 1; i--) now[++ct] = X[i].second;
for (int i = 1; i <= z2; i++) now[++ct] = X[i].second;
for (int i =... | 15 |
#include <bits/stdc++.h>
using namespace std;
int lmt, f, chk, cnt;
void solve() {
int n;
cin >> n;
string s[n];
for (int i = 0; i < n; i++) {
cin >> s[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (s[i][j] == '.') {
if (i + 2 >= n || j + 1 >= n || j - 1 < 0) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
const long long LINF = 0x7fffffffffffffff;
const int maxn = 1e5;
const int modn = 1e9 + 7;
const char v[] = {'a', 'e', 'i', 'o', 'u'};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int k, f = 0;
cin >> k;
for (int i = 5; i <= k ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n;
vector<int> v;
map<int, int> m;
for (int i = 0; i < 4 * n; ++i) {
cin >> k;
m[k]++;
}
for (map<int, int>::it... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a;
string b;
cin >> a;
cin >> b;
int s = a.size();
vector<int> ot1;
vector<int> ot2;
vector<int> v(26, -1);
int count = 0;
int u = 0;
for (int i = 0; i < s; i++) {
if (a[i] == b[i]) {
if (v[a[i] - 'a'] == -1 && v[a[i] - 'a... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
int frq[(int)1e5 + 5] = {};
for (int j = 1; j <= q; j++) {
int x, y;
cin >> x >> y;
int ans = 0;
for (int i = 1; i * i <= x; i++) {
if (x % i == 0) {
if (frq[i] + y < j) ans++;
frq[i] = j;
i... | 11 |
#include <bits/stdc++.h>
int min(int a, int b) { return a < b ? a : b; }
int ds[200000 * 2];
int find(int i) { return ds[i] < 0 ? i : (ds[i] = find(ds[i])); }
void join(int i, int j) {
i = find(i);
j = find(j);
if (i == j) return;
if (ds[i] > ds[j])
ds[i] = j;
else {
if (ds[i] == ds[j]) ds[i]--;
d... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1.01e9;
const double eps = 1e-9;
const int N = 2e5 + 10;
int t[N];
int p[N];
inline int comp(int x, int y) {
long long v1 = t[x] * (long long)p[y];
long long v2 = t[y] * (long long)p[x];
if (v1 != v2) return v1 < v2;
return p[x] < p[y];
}
int a[N];
d... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, a, b, t, ans, i;
cin >> t;
while (t--) {
cin >> a >> b >> n;
i = a ^ b;
if (n % 3 == 0) {
cout << a << endl;
} else if (n % 3 == 1)
cout << b << endl;
else
cout << i << endl;
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long a, b, c, d, sum = 0, i, j;
cin >> a >> b >> c;
long long n;
cin >> n;
vector<long long> f1(n);
for (i = 0; i < n; i++) {
cin >> f1[i];
if (f1[i] < c && f1[i] > b) sum++;
}
cout << sum;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x;
scanf("%d", &x);
if (x % 2)
puts("Ehab");
else
puts("Mahmoud");
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> solve(long long volume) {
if (volume == 0) {
return {0, 0};
}
long long a = 1;
while (a * a * a <= volume) ++a;
--a;
if (a == 1) return {volume, volume};
pair<long long, long long> res1 = solve(volume - a * a * a);
pair<long lo... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> b, a(n);
int i;
for (i = 0; i < n; i++) cin >> a[i];
b = a;
int r, l;
int k;
stable_sort(b.begin(), b.end());
while (a != b) {
i = 0;
while (i != n - 2 && a[i] <= a[i + 1]) i++;
l = i;
while (i < ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int mhash(int a, int b, int c, int d);
class FenwickTree {
private:
int lsb(int x) { return x & -x; }
public:
int* F;
int n;
FenwickTree(int _n) {
n = _n;
F = (int*)malloc(sizeof(int) * (n + 5));
for (int i = 0; i <= n; i++) F[i] = 0;
}
void add(i... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(26, -1);
vector<int> b(26, -1);
vector<int> cnt(26);
for (int i = 0; i < n; i++) {
vector<bool> kek(26);
string s;
cin >> s;
for (auto &c : s) {
c -= 'a';
cnt[c]++;
if (kek[c]) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long n, temp, ans, tempn = 0;
cin >> n;
temp = n;
int count = 0;
while (temp > 0) {
temp /= 10;
count++;
}
temp = 1;
for (int i = 0; i < count; i++) {
tempn += temp;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int sum = 0;
int mes, maxmsg;
int n;
cin >> n;
int *t = new int[n];
int *c = new int[n];
for (int i = 0; i < n; ++i) {
cin >> t[i] >> c[i];
}
mes = maxmsg = c[0];
for (int i = 1; i < n; ++i) {
mes = max(0, mes - (t[i] - t[i - 1]));
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
long long l, r;
double prob[1010];
double dp[1010][1010];
long long deset[20];
int Digits(long long n) {
int ret = 0;
while (n > 0) {
ret++;
n /= 10;
}
return ret;
}
long long Num(long long n) {
long long ret = 0LL;
int numDig = Digits(n);
fo... | 12 |
#include <bits/stdc++.h>
using namespace std;
int a[2 * int(1e5) + 5], n;
void Solve() {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
long long ans = a[n];
for (int i = n - 1; i >= 1; i--)
if (a[i] < a[i + 1])
ans += a[i];
else {
ans += max(0, a[i + 1] - 1);
a[i] = max(0, a[i + ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int maxm = 4e5 * 26 + 5;
const int INF = 0x3f3f3f3f;
const long long LINF = 3e17 + 1;
const int mod = 2520;
const int MOD = 1e6 + 7;
inline long long read() {
register long long x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {... | 15 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os << "[";
for (long long i = 0; i < v.size(); ++i) {
os << v[i];
if (i != v.size() - 1) os << ", ";
}
os << "]";
return os;
}
template <typename T>
ostream& operator<<(ostream& o... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, k, t;
int a[25][25];
int head[45], Next[405], ver[405], edge[405];
int tot = 0;
int vis[45];
void add(int x, int y, int z) {
Next[++tot] = head[x], ver[tot] = y, edge[tot] = z;
head[x] = tot;
}
int dfs(int x, int sum, int limit) {
if (sum > limit) return 0;
i... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, ma[300000], m[300000], ans = 0;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> m[i];
ma[i] = m[i];
}
sort(m, m + n);
for (int i = 0; i < n; i++)
if (ma[i] != m[i]) ans++;
cout << (ans > 2 ? "NO" : "YES") << endl;
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[501][501];
int ans[501];
bool dp[501][1024];
pair<int, int> ptr[501][1024];
int main(void) {
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
memset(dp, false, sizeof(dp));
for (int j = 0;... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 50003;
char s[MAXN];
int num[26];
void out(int index) {
int l = strlen(s);
for (int i = 0; i < index; i++) {
if (s[i] != '?')
printf("%c", s[i]);
else
printf("A");
}
vector<int> v;
for (int j = 0; j < 26; j++) {
if (!num[j]... | 5 |
#include <bits/stdc++.h>
int main() {
int a, b, c, x, y, z, l = 0, p = 0;
scanf("%d%d%d%d%d%d", &a, &b, &c, &x, &y, &z);
if (a < x) {
l = x - a;
} else {
p = (a - x) / 2;
}
if (b < y) {
l += y - b;
} else {
p += (b - y) / 2;
}
if (c < z) {
l += z - c;
} else {
p += (c - z) / ... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout) {
if (s != e) {
os << *s;
++s;
}
while (s != e) {
os << sep << *s;
++s;
}
return os;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
bool home = 1;
signed realMain();
signed main() {
home = 0;
if (home) {
freopen("tony_stark", "r", stdin);
} else {
ios::sync_with_stdio(0);
cin.tie(0);
}
realMain();
}
long long k;
struct S {
long long mn;
long long mx;
};
S operator+(S a, S b) { ... | 19 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename T1>
ostream &operator<<(ostream &out, pair<T, T1> obj) {
return out << "(" << obj.first << "," << obj.second << ")";
}
template <typename T, typename T1>
ostream &operator<<(ostream &out, map<T, T1> cont) {
typename map<T, T1>::const_itera... | 8 |
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::map;
using std::max;
using std::min;
using std::queue;
using std::sort;
using std::stack;
using std::string;
int two(int a, int *b) {
for (int i = 0;; i++) {
if (a == 0) return i;
b[i] = a % 2 == 1 ? 1 : b[i];
a /= 2;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct node {
double l, p;
} a[100010];
int cmp(node a, node b) {
double a1, a2, a3, a4;
double b1, b2, b3, b4;
a1 = (a.l + b.l) * a.p * b.p;
a2 = (a.l * 2 + b.l) * a.p * (1 - b.p);
a3 = (a.l + b.l) * (1 - a.p) * b.p;
a4 = (a.l + b.l) * (1 - a.p) * (1 - b.p);
... | 13 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const long long inf = 1000000000000000000LL;
const int maxN = 310000;
int a[maxN], b[maxN];
int n, m;
int order[maxN];
int pA[maxN], posA[maxN];
int pB[maxN], posB[maxN];
bool cmp(int x, int y) { return a[x] - b[x] < a[y] - b[y]; ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MAXN = 1000010;
int n, k;
long long s[MAXN], fac[MAXN], inv[MAXN], p = 1, ans;
char a[MAXN];
long long qpow(long long x, long long n) {
long long p = x, con = 1;
while (n) {
if (n & 1) con = (con * p) % MOD;
p = (p * p) % MO... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n;
cin >> n;
long long int i, a[n], odd = 0, even = 0, ans = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
if (i % 2) {
if (a[i] % 2) odd++;
} else {
if (a[i] % 2) ev... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50;
const int oo = 1e9;
const int mod = 1e9 + 7;
long long Power(long long a, long long b) {
if (!b) return 1;
long long ret = Power(a, b / 2);
if (b % 2) return ((ret * ret) % mod * a) % mod;
return (ret * ret) % mod;
}
int main() {
int x, y;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
bool y;
int n, m;
cin >> n >> m;
int s = n * m;
char arr[s];
for (int i = 0; i < s; i++) {
cin >> arr[i];
}
for (int i = 0; i < s; i++) {
if (arr[i] == 'C' || arr[i] == 'Y' || arr[i] == 'M') {
y = true;
break;
}
y = f... | 0 |
#include <bits/stdc++.h>
using namespace std;
char s[1001][1001];
bool a[1000][1000];
int n, m;
bool check(int x, int y) {
bool f = false;
for (int i = x; i >= x - 2 && i >= 0; i--) {
for (int j = y; j >= y - 2 && j >= 0; j--) {
if (!(i == x - 1 && j == y - 1)) {
if (i < n - 2 && j < m - 2) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
const double eps = 1e-9;
int a, b, n;
double sx, sy, ex, ey;
double dist[maxn][maxn];
double posx1[maxn], posx2[maxn], posy1[maxn], posy2[maxn];
bool vis[maxn];
bool equ(double a, double b) { return fabs(a - b) < eps; }
struct Point {
double x, ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
pair<int, int> p[100005];
long long cnt[100005];
int pre[30000005];
int size[30000005];
int lst[100005];
int y[100005];
int main() {
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%d %d", &p[i].first, &p[i].second);
y[i] = p[i].second;
... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using v = vector<T>;
const long long inf = 4611686018427387903;
void read() {}
template <typename Arg, typename... Args>
void read(Arg& arg, Args&... args) {
cin >> (arg);
read(args...);
}
void print() {}
template <typename Arg, typename... Args>
v... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
struct tree {
long long amount, count;
} t[N << 3];
void upd(int v, int tl, int tr, int pos, long long pl) {
if (tl == tr) {
t[v].count += pl;
t[v].amount += 1ll * pos * pl;
} else {
int mid = tl + tr >> 1;
if (pos <= mid) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i, j, c = 2, a = 2, b = 1;
cin >> n;
if (n & 1) {
a = 1;
b = 2;
}
for (i = a; i < n; i += 2) cout << i << " ";
cout << n << " ";
for (i = n - 2; i >= a; i -= 2) cout << i << " ";
cout << n << " ";
for (i = b; i < n; i ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int pre[11111];
vector<int> V[11111];
int main() {
for (int i = 3; (i - 1) < 11111; i++) {
pre[i] = (i * (i - 1)) / 2;
}
int n;
scanf("%d", &n);
int ans;
int i;
for (i = 3; pre[i] <= n; i++)
;
ans = i - 1;
printf("%d\n", ans);
int topo = 1;
for... | 8 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define inf ll(1e16) + 5
#define mod 1000000007
#define mod1 998244353
#define mod2 999983
#define N 25001
//***DON'T GET STUCK ON ONE APPROACH
ll power(ll a, ll n, ll m);
ll power(ll a, ll n, ll m)
{
if (n == 0)
return 1;
ll x = po... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = int(2e5) + 99;
int n;
int p[N];
int rp[N];
int a[N];
long long b[N];
long long t[4 * N];
long long add[4 * N];
void build(int v, int l, int r) {
if (r - l == 1) {
t[v] = b[l];
return;
}
int mid = (l + r) / 2;
build(v * 2 + 1, l, mid);
build(v... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 113;
const int maxm = 1e3 + 13;
double cnt[2][maxm * maxn];
int x[maxm];
double pre[maxm * maxn];
int main() {
int n, m, s = 0;
scanf("%d%d", &n, &m);
if (m == 1) {
puts("1");
return 0;
}
for (int i = 1; i <= n; ++i) {
scanf("%d", x + ... | 15 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void pop_front(std::vector<T> &vec) {
assert(!vec.empty());
vec.erase(vec.begin());
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
return (a.second < b.second);
}
long long int modexp(long long int base, long long int exp) {... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double pi =
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int MR = 1010;
const int MS = 60;
int pom[MR][MR];
bool ans[MR][2];
int dp[2][MR][MS][2];
int pre[MR][2], best[MR][MR];
int main() {
int n, p, k;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, m, q;
int mat[101][101];
pair<int, int> arr_map[101][101];
int main() {
ios::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
cin >> n >> m >> q;
int ti, ri, ci, xi;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
arr_map[i][j].first = i, ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int const N = 1e3 + 9;
int com[N][N], comh[N][N];
int n, m;
char arr[N][N];
inline void makeCom() {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (arr[i][j] == arr[i][j - 1])
com[i][j] = com[i][j - 1] + 1;
else
com[i][j] ... | 11 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:33554432")
using namespace std;
unsigned long long n;
int main() {
cin >> n;
vector<unsigned long long> res;
for (int i = 0; i <= 59; ++i) {
unsigned long long a = 1LL << i;
unsigned long long L = 1, R = min((unsigned long long)2e9, n / a + 1) + 1;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
long long n, k;
cin >> n >> k;
long long x = k;
for (long long i = 0; i < n; i++) {
long long y;
cin >> y;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)(2e18);
const long double eps = 1e-6;
const unsigned long long infu = (unsigned long long)(1e36);
const long double pi = 3.141592653589793;
long long power(long long a, long long k) {
if (k == 0) return 1;
if (k % 2) return power(a, k - ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
long long res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
const int N = 40100;
int T, p[N], c[N], dep[... | 26 |
#include <bits/stdc++.h>
using namespace std;
int const N = 200020;
int t[N * 4];
int up(int op, int node, int start, int end, int ind, int v) {
if (start > ind || end < ind) return t[node];
if (start == end) return t[node] = v;
int mid = (start + end) / 2;
up(op ^ 1, node * 2 + 1, start, mid, ind, v);
up(op ... | 9 |
#include <bits/stdc++.h>
using namespace std;
ofstream fout;
FILE *outt, *inn;
ifstream fin("1.txt");
int n, d, m;
int a[101];
int main() {
cin >> n >> d;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
cin >> m;
int sum = 0;
sort(a, a + n);
int i = 0;
while (i < min(n, m)) {
sum += a[i];
i++;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int dell[8][2] = {{1, 2}, {1, -2}, {2, 1}, {2, -1},
{-1, 2}, {-1, -2}, {-2, 1}, {-2, -1}};
long long mod = 998244353;
const long long inf = (1LL << 31) - 1;
const int maxn = 1e5 + 7;
const int maxm = 1e6 + 7;
const double eps = 1e-8;
const d... | 18 |
#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;
string s;
cin >> s;
vector<int> nxt0(n + 1), nxt1(n + 1);
nxt0[n] = nxt1[n] = n;
for (int i = n - 1; i >= 0; i--) {
nxt0[i] = s[i] == '0' ? i : nxt0[i + 1]... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const double eps = 1e-10;
const int MOD = (int)1e9 + 7;
const int N = 100010;
const int M = 99991;
int main() {
int m, r;
while (scanf("%d %d", &m, &r) != EOF) {
if (m == 1) {
printf("%.10lf\n", 2 * double(r));
continue;
}
do... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct Mirror {
int point, type;
double l, r;
} mi[110];
bool choose[110];
double hl, hr;
int n, ans;
void solve() {
for (int row = 2; row <= 100; row++) {
int hhl = 100.0 - hl;
int hhr = row % 2 == 1 ? hr : 100 - hr;
double tan = 100000.0 / (100.0 * row -... | 12 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int lzx = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -f;
c = getchar();
}
while (c >= '0' && c <= '9') {
lzx = lzx * 10 + c - '0';
c = getchar();
}
return lzx * f;
}
double P[100001], len1[1... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5001;
int n, m;
char buf[maxn], out[maxn];
bool f[maxn];
int main() {
scanf("%s", buf);
n = strlen(buf);
for (m = 0; 2 << m <= n; ++m)
;
for (int i = 0; i < 1 << m; ++i) f[i] = 1;
for (int i = 0; i <= n - (1 << m); ++i) {
out[i] = 'z';
... | 19 |
#include <bits/stdc++.h>
using namespace std;
int n, m, f[2][42][42][42][42];
char s[52][108];
int a[52][52], b[52][52], T;
struct Tprogram {
void open() {
freopen("1.in", "r", stdin);
freopen("1.out", "w", stdout);
}
void close() {
fclose(stdin);
fclose(stdout);
}
void init() {
scanf("%d%... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
cin >> x >> y;
int a = y, b = y, c = y;
int co = 0;
while (true) {
if (a >= x && b >= x && c >= x) {
cout << co;
return 0;
}
co++;
if (co % 3 == 1) {
a = b + c - 1;
} else if (co % 3 == 2) {
b = a ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int m, d;
cin >> m >> d;
int a[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if ((a[m] - (8 - d)) % 7)
cout << 2 + (a[m] - (8 - d)) / 7;
else
cout << 1 + (a[m] - (8 - d)) / 7;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
struct Line {
int l, r;
Line(int l = 0, int r = 0) : l(l), r(r) {}
};
bool cmp(Line a, Line b) {
if (a.l == b.l) return a.r < b.r;
return a.l < b.l;
}
const int N = 100004;
vector<Line> fs[N], sc[N];
int take[N];
int n, m, k, id;
map<int,... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, m;
cin >> t >> m;
vector<int> v(m, 1000000000);
int c = 1;
for (int i = 0; i < t; i++) {
string s;
cin >> s;
if (s == "alloc") {
int x;
cin >> x;
int r = 0;
bool found = false;
for (int i = 0; i < m; i+... | 8 |
#include<bits/stdc++.h>
#define int long long
#define in freopen("input.txt","r",stdin);
#define out freopen("output.txt","w",stdout);
#define r0cket007 in out
const int mod = 1e9 + 7 ;
int binpow( int a , int b )
{
int res = 1 ;
while( b )
{
if( b&1 )
{
res = (res * a) % mod ;
b -- ;
}
if( b != 0 )
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = int(2e5) + 111;
struct edge {
int v, c;
edge() {}
edge(int v, int c) : v(v), c(c) {}
};
int a[maxN];
long long path[maxN];
long long v_ind[maxN];
int ptop;
vector<edge> e[maxN];
bool is_normal[maxN];
int dem[maxN];
void dfs(int u) {
int l = 1, r = p... | 11 |
#include <bits/stdc++.h>
using namespace std;
int N, Ans, A[25][25], B[25][25], w[25][25];
int Tim, LA[25], LB[25], VA[25], VB[25], QA[25], QB[25], Mat[25], Suf[25];
inline int min(int a, int b) { return a < b ? a : b; }
inline int max(int a, int b) { return a > b ? a : b; }
bool Find(int u) {
VA[u] = Tim;
for (int... | 19 |
#include <bits/stdc++.h>
int main() {
int n;
std::cin >> n;
std::vector<int> sa;
std::map<int, bool> g1, g2;
for (int i = 1; i <= n; ++i) {
int tm;
std::cin >> tm;
sa.push_back(tm);
g1[tm] = true;
}
int m;
std::cin >> m;
std::vector<int> sb;
for (int i = 1; i <= m; ++i) {
int tm;... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
string second;
cin >> second;
vector<int> cnt(2, 0);
for (char& c : second) {
cnt[c - '0']++;
}
int num_moves = min(cnt[0], cnt[1]);
if ((num_moves & 1)) {
cout << "DA" << endl;
} else {
cout << "NET" << endl;
}
return;
}
int m... | 1 |
#include <bits/stdc++.h>
using namespace std;
int x, y, p[333333], r[333333], n, m[333333], X, Y, brr[333333], cnta, cntb,
ans;
int tree[2222222], pos[333333];
long long d[333333], arr[333333];
map<long long, int> mp1;
map<int, int> mp2;
vector<pair<int, int> > v[333333];
queue<int> q;
void pushup(int node) {
tre... | 16 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using ld = long double;
struct Node {
int cnt;
ll sum;
int apw;
};
vector<Node> t;
Node merge(const Node& a, const Node& b) {
return {a.cnt + b.cnt, a.sum + b.sum, -... | 24 |
#include <bits/stdc++.h>
using namespace std;
vector<int> G[300005];
long long a[300005], b[300005];
long long ans[300005];
int n, m;
long long pref1[300005], pref2[300005];
int main() {
ios::sync_with_stdio(0);
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
for (int i = 0; i < m; i++... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
long long res = 1;
a %= mod;
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
pair<int, int> c[233], z[233], f[233];
int a[233], b[233];
boo... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 10;
vector<int> g[N];
int n, f[N][2], sz[N], leaf[N];
void dfs1(int u, int p) {
sz[u] = 1;
int mn = N, mx = 0;
for (auto v : g[u]) {
if (v == p) continue;
dfs1(v, u);
sz[u] += sz[v];
leaf[u] += leaf[v];
mn = min(mn, leaf[v] -... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int N = 100005;
int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
void testCase() {
int a;
cin >> a;
cout << 2 * a - 1 << " 2\n1 2";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie... | 6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.