solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
class triple {
public:
int a, b, c;
bool operator<(const triple &t) const {
if (t.a != this->a) {
return t.a < this->a;
} else if (t.b != this->b) {
return t.b < this->b;
} else {
return t.c < this->c;
}
}
};
int main() {
ios_base:... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7, inf = 0x3f3f3f3f, mod = 1e9 + 7;
bool notprime[maxn];
int mu[maxn], prime[maxn], cnt;
int dp[maxn];
vector<int> fac[maxn];
void getprime() {
notprime[0] = notprime[1] = 1;
mu[1] = 1;
for (int i = 2; i < maxn; ++i) {
if (!notprime[i]) prim... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
inline int read() {
int sum = 0, f = 1;
char c = getchar();
while (c > '9' || c < '0') {
if (c == '-') f = -f;
c = getchar();
}
while (c >= '0' && c <= '9') sum = sum * 10 + c - 48, c = getchar();
return sum * f;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, i, n, f;
scanf("%d", &k);
int a[k + 1];
vector<int> ans;
bool f10 = false, f1 = false;
for (i = 0; i < k; i++) scanf("%d", &a[i]);
sort(a, a + k);
if (a[0] == 0) {
ans.push_back(0);
}
if (a[k - 1] == 100) {
ans.push_back(100);... | 8 |
#include <bits/stdc++.h>
using namespace std;
int arr[100001];
int main() {
int n, s, t;
cin >> n >> s >> t;
for (int i = 1; i <= n; i++) cin >> arr[i];
int sol = 0;
if (s == t) {
sol = 0;
} else {
int temp = s;
for (int i = 1; i <= n; i++) {
if (arr[s] == temp) {
sol = -1;
... | 4 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
int IT_MAX = 1 << 19;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
char in[5050];
bool dp[5050... | 19 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int mo = 1e9 + 7;
LL qpow(LL a, LL b) {
LL ans = 1;
a %= mo;
while (b) {
if (b & 1) ans = ans * a % mo;
a = a * a % mo;
b >>= 1;
}
return ans;
}
const int maxn = 1e5 + 5;
char s[maxn];
int sum[maxn];
map<int, int> my;
int ma... | 9 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int N, C, a[2][500010],... | 14 |
#include <bits/stdc++.h>
using namespace std;
void fileioe() {
freopen("input.txt", "r", stdin);
freopen("xyz.txt", "w", stdout);
freopen("error.txt", "w", stderr);
}
const long long mod = 1000000007;
const long long INF = 1e18;
const long long MAX = 100001;
void solve() {
long long n;
cin >> n;
long long a... | 6 |
#include <bits/stdc++.h>
int a[3001], n;
double d[2][8997001];
int main() {
scanf("%d", &n);
int inv = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
for (int j = 0; j < i; j++) {
if (a[j] > a[i]) inv++;
}
}
d[0][0] = d[1][0] = 0.0;
for (int k = 1; k <= inv; k++) {
d[0][k] = d[1]... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[5010];
int L[5010];
int R[5010];
int Ok[5010];
int D[5010];
int M[5010];
int RDp[5010][5010];
int LDp[5010][5010];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (Ok[a[i]] == 0... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long C[(200)][(200)], dp[16][(200)];
int num[16], t;
long long k;
void prepare() {
for (int i = 0; i < (200); i++) C[i][0] = 1;
for (int i = 1; i < (200); i++)
for (int j = 1; j <= i; j++) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
}
long long solve(int len) {
... | 17 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int MaxN = 100005, NA = -1, MaxC = 0x3F3F3F3F;
int a[MaxN];
int n;
multiset<int, greater<int> > s;
deque<int> d;
int main(void) {
int i, v;
multiset<int>::iterator it;
while (scanf(" %d", &n) != EOF) {
for (i = 0; i < n; i++) scanf(" %d"... | 12 |
#include <bits/stdc++.h>
using namespace std;
unordered_map<long long, long long> is;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
long long n, k;
cin >> n >> k;
map<pair<long long, long long>, long long> um;
for (long long i = 1; i <= n; i++) {
um[{i, i}] = 1;
}
for (long long i... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
const int MOD = 1e9 + 7;
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;
}
struct node {
int x, val;
} a[MAXN];
int he... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
scanf("%lld", &t);
string s;
int x;
for (int i = 1; i <= t; i++) {
cin >> x;
cin >> s;
int count = 0;
int minm = 0;
for (int j = 0; j < s.length(); j++) {
if (s[j] == ')') {
count--;
if (count < 0... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class C>
inline bool in_(const typename C::key_type& k, const C& A) {
return A.find(k) != A.end();
}
inline bool in_(const string& s, const string& S) {
return S.find(s) != string::npos;
}
const int inf = 1e9;
const int maxv = 1e5 + 5;
int dp[maxv], vis[maxv],... | 17 |
#include <bits/stdc++.h>
using namespace std;
string dtob(int n) {
string r = "";
int t = n;
while (n > 0) {
r = to_string(n % 2) + r;
n /= 2;
}
return r;
}
int no_1(string s) {
int r = 0;
for (int i = 0; i < s.length(); i++)
if (s[i] == '1') r += 1;
return r;
}
int main() {
ios_base::sync... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<bool> > pic, ray, vis;
vector<int> ans;
int cnt;
void floodfill(int x, int y) {
if (vis[x][y] || !pic[x][y]) return;
vis[x][y] = true;
if (!pic[x - 2][y] && !pic[x + 2][y]) {
if (!pic[x][y - 1] && (!pic[x - 2][y + 5] || !pic[x + 2][y + 5]))
ray... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[33][34] = {
"111111101010101111100101001111111", "100000100000000001010110001000001",
"101110100110110000011010001011101", "101110101011001001111101001011101",
"101110101100011000111100101011101", "100000101010101011010000101000001",
... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct S {
int a, b;
long long value;
bool operator<(const long long &b) const { return value < b; }
} sum[2005 * 2005];
long long a[2005], b[2005];
int na, nb, c[3][2], cnt = 0;
long long sa, sb, md1, md2, v;
bool cmp(S a, S b) {
if (a.value < b.value)
return t... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b;
cin >> a >> b;
if (a % 2 != 0) {
a++;
}
if (abs(a - b) >= 2) {
cout << a << " " << a + 1 << " " << a + 2 << endl;
} else {
cout << -1 << endl;
}
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
scanf("%d%d", &n, &m);
multiset<int> S;
for (int i = 0; i < n; i++) {
int x;
double y;
scanf("%d%lf", &x, &y);
auto it = S.upper_bound(x);
if (it != S.end()) S.erase(it);
S.insert(x);
}
printf("%d\n", n - S.size());... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string str1, str2;
cin >> str1 >> str2;
sort(str1.begin(), str1.end());
sort(str2.begin(), str2.end());
int cnt1 = 0;
int p = 0;
for (int i = 0; i < n; i++) {
if (str1[p] > str2[i])
cnt1++;
else
p++;
;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897932384626433;
const int mod = 1000000007;
const long long inf = 3e18;
vector<vector<long long> > adj(100001);
bool vis[100001];
long long st[100001];
vector<long long> v;
void dfs(long long x, long long n) {
vis[x] = true;
st[x] = 1... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000000 + 7;
const int M = 32;
const int mod = 999983;
const int inf = 1e9 + 7;
const double pi = acos(-1);
const int maxn = N * 2;
const double PI = acos(-1);
unsigned int a[N];
int n;
unsigned int k;
unsigned int m1[N];
map<unsigned int, int> st;
map<unsigne... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, ans, c[6][6], a[15], b[15];
char s[6];
int chg(char x) {
return x == 'R' ? 0 : x == 'G' ? 1 : x == 'B' ? 2 : x == 'Y' ? 3 : 4;
}
int main() {
scanf("%d", &n), ans = 10;
for (int i = 0; i < n; ++i) scanf("%s", s), ++c[chg(*s)][s[1] - 49];
for (int i = 0; i < 1... | 9 |
#include <bits/stdc++.h>
inline int Get() {
char ch;
int Sign = 0, Num;
while ((ch = getchar()) < '0' || ch > '9')
if (ch == '-') Sign ^= 1;
Num = ch - '0';
while ((ch = getchar()) >= '0' && ch <= '9')
Num = (Num << 3) + (Num << 1) + ch - '0';
return Sign ? -Num : Num;
}
inline void update(int &x) {... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> arr(n);
vector<int> arr2;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr.begin(), arr.end());
int x;
for (int i = 0; i < n / 2; i++) {
arr... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename T1>
T amax(T &a, T1 b) {
if (b > a) a = b;
return a;
}
template <typename T, typename T1>
T amin(T &a, T1 b) {
if (b < a) a = b;
return a;
}
void SOLVE() {
long long n;
cin >> n;
vector<long long> v(n);
long long cnt = 0;
for... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 205123;
int n, first, second, q, m;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> n >> m;
q = n + 5;
for (int i = 1; i <= m; ++i)
cin >> first >> second, q = min(q, second - first + 1);
cout << q << "\n";
for (int i = 0; i < n... | 9 |
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<long long int, long long int> a,
pair<long long int, long long int> b) {
return a.first < b.first;
}
bool check(int a) {
int sum = 0;
while (a > 0) {
sum += (a % 10);
a /= 10;
}
if (sum == 10) return true;
return false;
}
bool prim... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q, n, num, lastNum;
cin >> q;
while (q--) {
cin >> n;
int colors[n];
int t[n];
cin >> t[0];
int firstSame = -1;
int numDiff = 0;
for (int i = 1; i < n; i++) {
cin >> t[i];
if (t[i] != t[i - 1]) {
numDiff... | 10 |
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
bool prime[1000001];
void sieve() {
memset(prime, true, sizeof(prime));
prime[1] = false;
for (int p = 2; p * p <= 1000000; p++) {
if (prime[p] == true) {
for (int i = p * p; i <= 1... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool ch(long long n) {
if (n < 0) n *= -1;
while (abs(n) != 0) {
if (n % 10 == 8) return 1;
n /= 10;
}
return 0;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
long long i;
long long a;
cin >> a;
for (i = 1; !ch(i + a); i++) {
}... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1E-9;
const int INF = (int)1E9;
const long long INF64 = (long long)1E18;
const long double PI = 2 * acos(.0);
struct point {
int x, y;
};
point points[10];
int IsOrthogonal(point a, point b, point c) {
return (b.x - a.x) * (b.x - c.x) + (b.y - a.... | 8 |
#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(-... | 19 |
#include <bits/stdc++.h>
const double PI =
3.141592653589793238462643383279502884197169399375105820974944;
using namespace std;
void solve() {
long long n, k;
cin >> n >> k;
if (n == 1) {
cout << "0"
<< "\n";
return;
}
if ((k * (k - 1)) / 2 < n - 1) {
cout << "-1"
<< "\n";
... | 9 |
#include <bits/stdc++.h>
namespace duliu {
using namespace std;
const int INF = 0x3f3f3f3f;
} // namespace duliu
using namespace duliu;
const int N = 2e5 + 10;
string str, tmp;
set<int> G[80];
int n, m;
int tree[N << 2];
void PushUp(int rt) { tree[rt] = tree[rt << 1 | 1] + tree[rt << 1]; }
void Revise(int L, int l, in... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, l, r, m, an, ans[1000001][3], sz, x, siz, A, B, t[100001], tn, oN, o[21];
set<int> v[100001];
set<pair<int, int> > s;
set<int>::iterator nw, it;
set<pair<int, int> >::iterator itt;
namespace io {
const int SIZE = (1 << 21) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double a, b, c;
cin >> a >> b >> c;
double d = b * b - 4 * a * c;
if (a == 0) {
if (b == 0) {
if (c == 0)
cout << -1 << endl;
else
cout << 0 << endl;
} else
cout << 1 << endl << fixed << setprecision(10) << (dou... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
string s;
cin >> s;
set<char> p(s.begin(), s.end());
if ((p.size() == s.length()) && (((*max_element(s.begin(), s.end()) -
*min_element(s.begin(), s.end())) +
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
long long dp[n + 1];
dp[0] = 0;
for (int i = 1; i < n + 1; i++) {
string ch;
ch = to_string(i);
int nb;
int mini = i + 1;
for (int j = 0; j < ch.size(); j++) ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long n, a[100005], res = 1, dp[100005];
pair<long long, long long> it[400005];
void build(long long id, long long l, long long r) {
if (l == r) {
it[id].first = a[l];
it[id].second = l;
return;
}
long long mid = (l + r) >> 1;
build(id * 2, l, mid);
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
vector<int> v(200007);
vector<pair<int, int> > v2(200007);
vector<int> ans(200007);
for (int i = 0; i < n; i++) {
cin >> v[i];
v2[i].first = v[i];
v2[i].second... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int SIZE = (1 << 17);
struct SegmentTree {
int tree[2 * SIZE];
SegmentTree() : tree() {}
void clear(int val) { fill(tree, tree + 2 * SIZE, val); }
void set(int v, int val) {
v += SIZE;
tree[v] = val;
v /= 2;
while (v > 0) {
tree[v] = max(... | 16 |
#include <bits/stdc++.h>
using namespace std;
struct prj {
string name;
int ver;
prj(string name, int ver) : name(name), ver(ver) {}
};
int n;
map<prj, vector<prj> > g;
queue<pair<prj, int> > q;
vector<prj> ans;
map<string, bool> used;
bool operator<(prj l, prj r) {
if (l.name == r.name) return l.ver < r.ver;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 100;
const long long mod = 1e9 + 7;
const long long base = 2e9 + 1;
long long col[maxn];
long long siz[maxn];
vector<long long> adj[maxn];
long long par[maxn];
long long find_par(long long u) {
if (u == par[u]) return u;
return par[u] = find... | 14 |
#include <bits/stdc++.h>
using namespace std;
int a[200010], b[200010], n, P1[200010][20 + 2], P2[200010][20 + 2], lg[200010];
long long ans;
void build() {
for (int i = 1; i < 200010; i++) lg[i] = log2(i);
for (int i = 0; i < n; i++) P1[i][0] = a[i];
for (int j = 1; j <= 20; j++) {
for (int i = 0; i <= n - (... | 13 |
#include <bits/stdc++.h>
using namespace std;
int a[100010];
long long GetMaxSum(int n, int len, int k) {
long long mxsum = -(~0ULL >> 1);
long long ans = 0;
multiset<int> Saki;
multiset<int> Nodoka;
for (int i = 0; i < n; i++) {
if (i >= len) {
if (Saki.find(a[i - len]) != Saki.end()) {
Sak... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 20;
bool adj[N][N];
long long dp[1 << N][N];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
adj[a][b] = adj[b][a] = true;
}
for (int i = 0; i < n; i++) dp[1 << i][i] = 1;
l... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7, mod1 = 1e9 + 9;
long long c[300005], idd[300005], po[300005], po1[300005], m;
vector<long long> ed[300005];
set<pair<long long, long long> > my[300005];
pair<long long, long long> has[300005];
string s;
long long base = 10000007;
long long merge(lon... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
struct pi {
int sum;
int lson;
int rson;
} pp[maxn * 23];
int root[maxn], tot;
struct ppi {
int le;
int ri;
int s;
} pp1[maxn << 2];
void build1(int tot, int l, int r) {
pp1[tot].le = l;
pp1[tot].ri = r;
pp1[tot].s = 0;
if (l == ... | 14 |
#include <bits/stdc++.h>
using namespace std;
char grid[105][105];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) cin >> grid[i][j];
int row = 0, col = 0, k = 0;
for (int i = 1; i <= n; i++) {
k = 0;
for (int j = 1; j <= n; j++) {
if (grid[i][j] == 'E... | 7 |
#include <bits/stdc++.h>
using namespace std;
int ans[1002][1002][5];
int calc(vector<int>& col, int x, int y, int n, int i, int j, bool k) {
if (i >= col.size() && ((j > x && j <= y) || j == 1)) return 0;
if (i >= col.size()) return INT_MAX - 1000010;
if (ans[i][j][k] != -1) return ans[i][j][k];
ans[i][j][k] =... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 5 * 1e5 + 7;
const long double pi = 3.14159265359;
const int INF = 1e9 + 7;
const double eps = 1e-9;
const int xi[4] = {-1, 1, 0, 0};
const int yi[4] = {0, 0, -1, 1};
const int xxi[8] = {+1, 0, -1, 0, +1, -1, +1, -1};
const int yyi[8] = {0, -1, 0, +1, +1... | 6 |
#include <bits/stdc++.h>
long long gcd(long long x, long long y) { return (!y) ? x : gcd(y, x % y); }
long long lcm(long long x, long long y) { return ((x / gcd(x, y)) * y); }
using namespace std;
void fast();
int main() {
fast();
int t;
cin >> t;
while (t--) {
int c, d;
cin >> c >> d;
if (c == 0 &&... | 0 |
#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
inline void up(int& x, int y) {
x = x + y < 1000000007 ? x + y : x + y - 1000000007;
}
inline char emm(int q, int w) { return q == w ? '\n' : ' '; }
inline int read() {
int x = 0, f = 1;
char ch = getchar();
whil... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
long long int k;
cin >> n >> m >> k;
bool array1[1002][1002];
for (int i = 0; i < 1002; i++) {
for (int j = 0; j < 1002; j++) {
array1[i][j] = 0;
}
}
int ans = 0;
int flag = 0;
for (long long int i = 0; i < k; i++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int dx[9] = {-1, 0, 0, +1, -1, -1, +1, +1, 0};
int dy[9] = {0, -1, +1, 0, -1, +1, -1, +1, 0};
vector<pair<int, int> > st;
char w[10][10];
bool flag = false;
void rec(int x, int y, int step) {
if ((x == 1 && y == 7) || step == 9) {
printf("WIN");
exit(0);
}
for... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, p;
cin >> s >> p;
int q = 0, m = s.size(), n = p.size(), pos = n, neg = 0, res = 0;
vector<int> v(255);
for (int i = 0; i < n; ++i) v[p[i]]++;
for (int i = 0; i < m; ++i) {
if (s[i] == '?') {
q++;
} else {
int x = --v[s... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
int c = 0, one = 0, store = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '1') {
one = 1;
}
if (one == 1 && s[i] == '0') {
c++;
}
if (on... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int a[n][n];
int cnt = (n * n);
long long ans = 0;
for (int i = 0; i < n; i++) {
for (int j = n - 1; j >= k - 1; j--) {
a[i][j] = cnt--;
}
ans += cnt + 1;
}
for (int i = 0; i < n; i++) {
for (int j ... | 5 |
#include <bits/stdc++.h>
template <class T>
inline void rd(T &x) {
char c = getchar(), f = 0;
x = 0;
while (!isdigit(c)) f = (c == '-'), c = getchar();
while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
x = f ? -x : x;
}
const int MAXN = 6e5 + 7;
const long long HA = 1e9 + 7, INV2 = (1 + HA) / 2;
std::ve... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long ans[2000005], ans1[2000005], ans2[2000005], L[1000005], R[1000005],
arr[1000005];
vector<long long> st;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n, q, k;
cin >> n;
for (int i = 1; i <= n; ++i) cin >> arr[i];
for (int i = 1; ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
cin.ignore();
while (t) {
long double n;
cin >> n;
long double pi_by_2 = acos(0.0);
long double result = 1 / tan(pi_by_2 / n);
cout << fixed;
cout << setprecision(6) << result << endl;
t--;
}
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
int n;
long long sum, cnt, top, ans, A[511111], js[511111], B[511111], C[511111];
priority_queue<long long, vector<long long>, greater<long long>> q;
bool comp(long long x, long long y) { return x > y; }
int main() {
scanf("%d", &n);
for (int i = 1;... | 22 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
int64_t t = 1;
cin >> t;
int64_t n, c0, c1, h;
string s;
int64_t count0, count1;
while (t--) {
cin >> n >> c0 >> c1 >> h;
cin >> s;
count0 = count1 = 0;
for (int64_t i = 0; i < n; i++)... | 0 |
#include <bits/stdc++.h>
using namespace std;
map<int, long long> m;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
m[x - i] += x;
}
long long max_ = 0;
for (map<int, long long>::iterator it = m.begin(); it != m.end(); it++) {
max_ = max(max_, it->second);
}
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
int n;
cin >> n;
int A[n];
for (int i = 0; i < n; i++) {
cin >> A[i];
}
int count = 0;
for (int i = 0; i < n; i++) {
if (A[i] > b && A[i] < c) {
count++;
}
}
cout << count << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int m = n * (n - 1) / 2;
vector<pair<int, int>> e(m + 1);
vector<int> f(n), sz(n, 1), ecnt(n);
vector<vector<int>> ans(n, {0, 1});
for (int i = 0; i < n; i++) f[i] = i;
for (int i = 0, tot = 0; i < n; i++) {
for (int j = 0; ... | 19 |
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 3e3 + 1;
uint16_t a[N], nxt[N], lst[N];
uint16_t dp[N][N];
int main() {
cin.tie(0), ios::sync_with_stdio(0);
int t, n;
cin >> t;
while (t--) {
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i], --a[i];
}
memset(lst, -1, n * ... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int mn = 311111;
int vis1[mn], vis2[mn], a[mn], b[mn];
int main() {
int n;
while (scanf("%d", &n) != EOF) {
memset(vis1, 0, sizeof(vis1));
memset(vis2, 0, sizeof(vis2));
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
vis1[a[i]] = i;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long T, n, k;
long long a[15], bb[15], po[15];
long long lp(int t) {
long long d = 1;
for (int i = 1; i <= t; ++i) d = d * 10;
return d;
}
int main() {
cin >> T;
for (int ii = 1; ii <= T; ++ii) {
cin >> n >> k;
k = k + 1;
for (int i = 1; i <= n; +... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, i, k, p;
vector<long long> a;
cin >> n;
for (i = 0; i < n; i++) {
cin >> m;
a.push_back(m);
}
string s;
cin >> s;
for (i = 0; i < n - 1; i++) {
if (s[i] == '1') {
k = i;
while (1) {
k++;
if... | 6 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, temp;
cin >> n;
vector<int> a, sortedA;
int nn = n;
while (n--) {
cin >> temp;
a.push_back(temp);
sortedA.push_back(temp);
}
if (nn == 1) {
cout << "YES\n";
return;
}
sort(sortedA.begin(), sortedA.end());
int i =... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using max_heap = priority_queue<T>;
template <typename T>
ostream &operator<<(ostream &os, min_heap<T> H) {
while (!H.empty()) {
os << H.top() << " ";
H.pop();
... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5008;
int k, n;
char s[N];
bitset<N> ck[N];
struct node {
int num;
node *c[2];
node(int x = 0) {
num = 0;
c[0] = c[1] = 0;
}
} * root;
void add(node *x, int i) {
for (int j = (i); j <= (n); j++) {
char c = s[j] - 'a';
if (x->c[c] == 0... | 15 |
#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> card[305];
map<long long, long long> dp[305];
int total;
long long gcd(long long a, long long b) {
if (!b) return 0;
if (a % b == 0) return b;
return gcd(b, a % b);
}
long long min(long long a, long long b) { return a > b ? b : a; }
long lon... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int m, long long int n) {
if (n == 0) return m;
return gcd(n, m % n);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int rem = 0;
string s;
cin >> s;
int a[n];
for (int i = 0; i < n; i++) a[i] ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int cmp1(const void *a, const void *b) {
char *s1 = (char *)a;
char *s2 = (char *)b;
return strcmp(s1, s2);
}
int main() {
int n, s[601], flag[101], a[101], ans = 0;
fill(flag, flag + 101, 0);
fill(s, s + 601, 0);
scanf("%d", &n);
for (int i = 1; i <= n; i++... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline int rint() {
int a;
scanf("%d", &a);
return a;
}
inline long long rll() {
long long a;
scanf("%lld", &a);
return a;
}
inline double rdouble() {
double a;
scanf("%lf", &a);
return a;
}
int a[100005];
int main() {
int n = rint();
int mi = 100000, ... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void cmax(T& a, T b) {
a = max(a, b);
}
template <class T>
void cmin(T& a, T b) {
a = min(a, b);
}
void _BG(const char* s) {}
template <class T, class... TT>
void _BG(const char* s, T a, TT... b) {
for (int c = 0; *s && (c || *s != ','); ++s) {
... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2000010;
long long n, a, s[N];
bool isprime[N];
vector<long long> prime;
void seive() {
isprime[0] = 1;
isprime[1] = 1;
for (long long i = 4; i <= N / 2; i += 2) isprime[i] = 1;
for (long long i = 3; i * i <= N / 2; i += 2) {
if (isprime[i] =... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 5005;
long long n, par[N][20], h[N], res[N];
vector<long long> g[N];
vector<pair<long long, long long>> e;
unordered_map<long long, long long> mp;
void dfs(long long v, long long p) {
par[v][0] = p;
h[v] = h[p] + 1;
for (long long i = 1; i < 20; ++... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = mod * mod;
const long double eps = 1e-8;
int n;
struct edge {
int to, cost;
};
vector<edge> G[1000];
vector<pair<int, int>> nd[1000];
vector<pair<pair<int, int>, int>> ans;
int root;
void dfs(int id, int fr, int obc)... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a[100010], b[100010];
struct node {
int cnt, val;
};
node tree[100010 << 2];
void build(int L, int R, int rt) {
tree[rt].val = -0x7FFFFFFF;
tree[rt].cnt = 0;
if (L != R) {
int mid = (L + R) >> 1;
build(L, mid, rt << 1);
build(mid + 1, R, rt << 1 | 1)... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long a[100000];
long long b1[100000];
long long b2[100000];
int main() {
long long n, p, q, r;
cin >> n >> p >> q >> r;
for (int i = 0; i < n; i++) cin >> a[i];
b1[0] = p * a[0];
for (int i = 1; i < n; i++) b1[i] = max(b1[i - 1], p * a[i]);
b2[n - 1] = r * ... | 7 |
#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
const long long MAX_N = 1000;
using namespace std;
vector<int> gn[MAX_N];
vector<int> gm[MAX_N];
int mark[MAX_N];
int markm[MAX_N];
void dfs(int v, int o) {
if (o) {
markm[v]++;
for (int i = 0; i < gm[v].size(); ++i) {
int u = gm[v][i];
if (!... | 6 |
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define loop(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define loopr(i,a,b) for(int i=(int)a;i>=(int)b;--i)
#define count_1(n) __builtin_popcountll(n)
#define pb push_back
#define pc ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int64_t gcd(int64_t n, int64_t m) { return m ? gcd(m, n % m) : n; }
int64_t lcm(int64_t n, int64_t m) { return n / gcd(n, m) * m; }
struct debugger {
static void call(string::iterator it, string::iterator ed) {}
template <typename T, typename... aT>
static void call(s... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 6e5;
class Graph {
vector<long long> head, nxt, to, fa, siz, in, dep, sum, G;
long long s, a, b, tot = 0, m, A, B, n;
long long find(long long x) { return G[x] == x ? x : G[x] = find(G[x]); }
long long f(long long k) {
return -in[k] * sum[k] ... | 25 |
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
#define CC(_...) fprintf(stderr,_)
using namespace std;
typedef long long LL;
enum{N=307,E=607,P=998244353};
int n,k,hd[N],nt[E],to[E],F[N][N],G[N][N],tF[N][N],tG[N][N],sF[N][N],sG[N][N],H[N];
void fly(int u,int f=... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int N = 600010;
int n, k, l[N], r[N];
vector<pair<int, int> > tmp, arr;
set<pair<int, pair<int, int> > > st;
vector<pair<int, int> > g[N];
int has[N];
int last[N];
long long sum[N];
long long all[N];
int cur[N];
long long Sum = 0;
int All = 0;
int Last = -1;
set<pair<... | 27 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int a, b, c, score = INT_MAX, A, B, C;
cin >> a >> b >> c;
for (long long int i = 1; i <= 30001; ++i) {
for (lo... | 12 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long mask[300][300][5];
inline long long popcount64c(uint64_t first) {
const uint64_t m1 = 0x5555555555555555;
const uint64_t m2 = 0x3333333333333333;
const uint64_t m4 = 0x0f0f0f0f0f0f0f0f;
const uint64_t m8 = 0x00ff00ff00ff00ff;
const uint64_t m16 ... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
string s;
cin >> s;
int sum = 0;
int m = 0;
for (int l = 0; l < n; ++l) {
map<char, int> a;
for (int r = l; r < n; ++r) {
a[s[r]]++;
m = 0;
for (auto p : a) {
if (p.second > m) {
m... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
int n, q, a[N], ans[N], sum[N], lg[N];
vector<pair<int, int>> queries[N];
int main() {
scanf("%d%d", &n, &q);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
a[i] = i - a[i];
}
for (int i = 1; i <= q; ++i) {
int x, y;
scanf("... | 15 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
long long n, m;
long long v[111111], c[111111], dp[111111];
int main() {
long long i, j, k, x, y, z, ca = 1, re = 0;
scanf("%I64d%I64d", &(n), &(m));
for (int i = (int)(1); i <= (int)(n); ++i) scanf("%I64d", &(v[i]));
for (int i = (in... | 12 |
#include <bits/stdc++.h>
using namespace std;
int s[101];
int main() {
int n;
cin >> n;
int x;
cin >> x;
int t;
for (int i = 0; i < n; i++) {
cin >> t;
s[t] = true;
}
int a = 0;
for (int i = 0; i < x; i++) {
if (!s[i]) a++;
}
if (s[x]) a++;
cout << a;
return 0;
}
| 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.