solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
pair<pair<int, int>, int> p[111];
int a[111];
map<int, int> M;
int n;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i].first.second >> p[i].first.first;
p[i].second = i;
}
sort(p + 1, p + n + 1);
for (int i = 1; i <= n; i++) {
for (int... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int M = 1e2;
int nodes;
int t[M * N];
int root[2 * N];
int lc[M * N], rc[M * N];
void build(int no, int l, int r) {
if (l == r) {
t[no] = 0;
return;
}
int mid = (l + r) / 2;
lc[no] = nodes++;
rc[no] = nodes++;
build(lc[no], l... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int people;
int a = 1;
while (cin >> people) {
int coin[people];
for (int i = 0; i < people; i++) {
cin >> coin[i];
coin[i] = coin[i] + i;
}
sort(coin, coin + people);
for (int j = 0; j < people - 1; j++) {
if (coin[j... | 14 |
#include <bits/stdc++.h>
int main() {
long N;
long long unsigned NUMEROS[10000];
long i;
int CONT_RESTOS[3] = {0, 0, 0};
int AUX_RESTO;
int MIN;
int RESTO_ZERO;
while (scanf("%d", &N) != EOF) {
CONT_RESTOS[0] = 0;
CONT_RESTOS[1] = 0;
CONT_RESTOS[2] = 0;
for (i = 0; i < N; i++) {
sc... | 5 |
#include <bits/stdc++.h>
using namespace std;
char s[6000], t[6000], bo[6000];
int n, A[30], flag, l, r;
vector<int> way;
void get(int L) {
if (L == 0) return;
way.push_back(L);
int len = 0;
for (int i = 1; i <= L; i++) bo[++len] = s[n - i + 1];
for (int i = 1; i <= n - L; i++) bo[++len] = s[i];
for (int i ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long x, y;
long long kuai(long long x, int y) {
long long ans = 1;
x %= mod;
while (y) {
if (y & 1) (ans *= x) %= mod;
(x *= x) %= mod;
y >>= 1;
}
return ans;
}
map<int, long long> mapp;
long long work(int n) {
if (mapp[... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 205;
int n, a[N], ne[N][26], fail[N], num[N], cnt;
long long f[N][N], dp[N][N], l;
char s[N];
queue<int> q;
int main() {
scanf("%d%lld", &n, &l);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) {
scanf("%s", s + 1);
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long h, L;
cin >> h >> L;
long double ans = ((L * L) - (h * h));
ans = (double)ans / (2 * h);
printf("%0.8Lf\n", ans);
return 0;
}
| 2 |
#include <bits/stdc++.h>
#define fo(i,n) for(long i=0;i<n;i++)
#define rfo(i,n,j) for(long i=n;i>=j;i--)
#define st(a,n) sort(a,a+n)
#define pi 1000000007
using namespace std;
bool ch(long long a)
{
if(a==2|| a==3)
return true;
if(a%2 ==0)
return false;
for(long long ... | 2 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
#define pb push_back
#define ppp pop_back
#define pii pair<int,int>
#define fi first
#define se second
#define stie std::tie
#define vec vector
#define forn(i, l, r) for (int i=l; i<=r; i++)
#define forb(i, ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int fl = 1;
string tp = "";
reverse(s.begin(), s.end());
int pos = 0;
while (s[pos] == '0') pos++;
for (int i = pos; i < s.size(); i++) {
tp += s[i];
}
int l = 0, r = tp.size() - 1;
while (l < r) {
if (tp[l] != ... | 1 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
cout << (n * m + 1) / 2 << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
solve();
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int iinf = 1e9 + 10;
const long long inf = 1ll << 60;
const long long mod = 1e9 + 7;
void GG() {
cout << "0\n";
exit(0);
}
long long mpow(long long a, long long n, long long mo = mod) {
long long re = 1;
while (n > 0) {
if (n & 1) re = re * a % mo;
a =... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long double PI = atan(1.0) * 4;
const int64_t INF = 3e18;
const int32_t LOG = 21;
const long long int MOD = 998244353;
int32_t main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
long long int tests = 1;
cin >> tests;
for (long long int i... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 800;
const long long md = 1e9 + 7;
long long gcd(long long a, long long b) { return (b ? gcd(b, a % b) : a); }
void ans(long long ch, long long zn) {
long long g = gcd(ch, zn);
cout << ch / g << "/" << zn / g;
exit(0);
}
long long x, a, b;
int main() {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ans = 0;
for (int i = 0; i < n; i++) {
int cnt = 0;
for (int j = 0; j < 3; j++) {
int t;
cin >> t;
cnt += t;
}
if (cnt >= 2) ans++;
}
cout << ans;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
struct node {
long long p;
long long c;
int idx;
} a[500050];
bool cmp(node x, node y) { return x.p < y.p; }
long long ans[500050];
int main() {
ios::sync_with_stdio(false);
cin >> n >> k;
for (int i = 1; i <= n; ++i) cin >> a[i].p, a[i].idx = i;
for... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
struct node {
int ans, open, close;
node() { ans = open = close = 0; }
} segTree[4 * MAXN];
int N;
string str;
void buildTree(int at, int l, int r) {
if (l > r) return;
if (l == r) {
if (str[l] == '(')
segTree[at].open = 1;
e... | 12 |
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T>
inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
template <class T>
inline T sqr(T x) {
return x * x;
}
const double EPS = 1e-... | 16 |
#include <bits/stdc++.h>
using namespace std;
void FastIO() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cout.precision(15);
}
int main() {
FastIO();
long long int a, b, i, n, p, l, r, l1, l2, r1, r2, y, x, s, e;
double ans = 0.0;
vector<pair<long long int, long long int> > v;
cin >>... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> in, out, nin, nout;
map<string, int> ma;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
ma[s]++;
}
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (ma[s] > 0) {
ma[s]--;
} e... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct point {
long long x, y;
};
bool comp(struct point a, struct point b) {
return abs(a.x) + abs(a.y) < abs(b.x) + abs(b.y);
}
int main() {
long long n, i, mid, val = LONG_LONG_MIN, ans = 0;
cin >> n;
point p[n];
for (i = 0; i < n; i++) {
cin >> p[i].x >>... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 50960;
const int MOD = 1000000007;
long long dp[2][MAXN];
char s1[MAXN], s2[MAXN];
int main() {
scanf("%s %s", s1, s2);
int n = strlen(s1), m = strlen(s2);
long long ans = 0;
for (int i = 0; i < n; ++i) {
memset(dp[i & 1], 0, m << 3);
for (i... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, balance, last, ans;
string path;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> path;
for (int i = 0; i < n; i++) {
if (path[i] == 'U') {
balance++;
if (balance == 1) {
if (last == 1) ans++;
}
if (balance > 0... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, y, cnt = 0;
cin >> n >> x >> y;
int arr[n + 1];
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] <= x) cnt++;
}
if (x > y)
cout << n << endl;
else
cout << (cnt + 1) / 2 << endl;
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() { puts("INTERCAL"); }
| 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, a[N];
int ans[N];
int caozuo[N];
int main() {
int l = 1, r;
scanf("%d", &n);
r = n;
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) {
if (min(a[l], a[r]) > ans[i - 1]) {
if (a[l] < a[r])
... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool isOnlyUppercase(string str) {
for (int i = 0; i < str.length(); i++) {
if (str[i] >= 'a' && str[i] <= 'z') {
return false;
}
}
return true;
}
bool isInverted(string str) {
if (str[0] >= 'A' && str[0] <= 'Z') {
return false;
}
return isOnly... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a[80010] = {0};
int main() {
int t;
scanf("%d", &(t));
;
bool flag = false;
while (t--) {
int b, c;
scanf("%d", &(b));
;
scanf("%d", &(c));
;
b += 40000;
a[b] = c;
if (a[b + c]) {
if (a[b + c] + b + c == b) {
flag ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, counter = 0, flag = 1;
cin >> x;
int arr[x];
for (int i = 0; i < x; i++) cin >> arr[i];
for (int i = 0; i < x; i++) {
if (arr[i] == 1) {
if (arr[i - 1] == 1 || flag)
counter++, flag = 0;
else
counter += 2;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const long double pi = acos(-1.0);
int n, m, s;
vector<int> dir[300050], ndir[300050];
vector<pair<int, int> > edges;
bool vis[300050];
bool visedge[300050];
int resp[300050];
void pre() {
cin >> n >> ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int _x[4] = {1, 0, -1, 0};
const int _y[4] = {0, 1, 0, -1};
const double sqrt2 = sqrt(2);
const int maxn = 2000 + 5;
int A[maxn][maxn];
int Left[maxn][maxn], Right[maxn][maxn], Bottom[maxn][maxn], Top[maxn][maxn];
bool used[maxn][maxn];
int n;
void dfs(int x, int y) {... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long n, q, x;
string s;
int lyr(long long x) {
for (int i = 0; i < 64; ++i) {
if ((x >> i) & 1ll) return i;
}
}
long long U(long long x) {
long long out = ((x & (~(1ll << lyr(x)))) | (1ll << (lyr(x) + 1))) & n;
return (out ? out : x);
}
long long L(long lon... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200, MAXS = 5e4;
int f[MAXN][MAXS], N, K, S, r = 1e9;
int main() {
memset(f, 63, sizeof(f));
for (int i = 0; i < MAXS; i++) f[0][i] = 0;
scanf("%d%d%d", &N, &K, &S);
for (int i = 1, x; i <= N; i++) {
scanf("%d", &x);
for (int n = min(i, K); ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 1;
vector<pair<int, int> > a, b, d, pro;
vector<int> c;
int main() {
int i, j, m, n, x, y, t, pr, z, ymin, pa, pb, mid, e;
scanf("%d%d", &n, &m);
for (i = 0; i < m; i++) {
scanf("%d%d", &x, &y);
a.push_back(make_pair(x, y));
}
sort(a.be... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int ar[n];
int br[m];
for (int i = 0; i < n; i++) {
cin >> ar[i];
}
for (int i = 0; i < m; i++) {
cin >> br[i];
}
int mat[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
mat[i][j]... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, a[500001];
int main() {
scanf("%d", &n);
int i, top = -1;
long long ans = 0;
for (i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
while (top >= 1 && a[top] <= a[top - 1] && a[top] <= x) {
ans += min(a[top - 1], x);
top--;
}
a[++t... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
long long b[maxn];
map<int, int> pos;
long long n;
bool check(long long k) {
vector<long long> v;
v.clear();
for (long long i = 1; i <= n; i++) {
if (i == k) continue;
v.push_back(b[i]);
}
long long sz = v.size();
long long temp... | 9 |
#include<bits/stdc++.h>
#define ll long long int
#define ff first
#define ss second
#define eps 1e-9
#define mod 1000000007
using namespace std;
ll arr[3];
int main()
{
ll t,n,m,f,a,b,c,l,r,q,k,x,y,z,ans,mn,mx,sum=0;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
cin>>t;
while(t--)
{
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> arr, z;
void rotate(int i) {
z.push_back(i + 1);
int x = arr[i + 2];
arr[i + 2] = arr[i + 1];
arr[i + 1] = arr[i];
arr[i] = x;
}
void solve() {
cin >> n;
arr.resize(n);
for (auto &x : arr) cin >> x;
z.clear();
for (int i = 0; i < n - 2... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
int dir[8][2] = {-1, 0, 1, 0, 0, -1, 0, 1, -1, -1, -1, 1, 1 - 1, 1, 1};
template <typename S, typename T>
inline bool Min(S &a, const T &b) {
return a > b ? a = b, true : false... | 27 |
#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> m;
void solve() {
char t;
cin >> t;
long long int p;
cin >> p;
if (t == '?') {
cout << m[p];
return;
}
long long int pw = 1;
long long int pa = 0;
while (p) {
long long int di = p % 10;
if (di & 1) pa += pw... | 6 |
#include <bits/stdc++.h>
const int mod = 1000000007;
using namespace std;
int main() {
int prefix;
int n, x;
cin >> n;
int count = 0;
for (int i = (0); i < (n); i++) {
cin >> x;
if (i == 0) {
count++;
} else if (prefix != x) {
count++;
}
prefix = x;
}
cout << count << endl;... | 0 |
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
const double pi12 = 1.57079632679489661923;
struct point {
double x, y;
point operator-(const point & p) const{
return {x - p.x, y - p.y};}
double crossP(const point &p) const{
return x * p.y - y *... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long n, i, j;
cin >> n;
long long v[n];
for (i = 0; i < n; i++) {
cin >> v[i];
if (i)
j &= v[i];
else
j = v[i];
}
cout << j << '\n';
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int rd() { return RAND_MAX == 32767 ? ((rand() << 15) ^ rand()) : rand(); }
const int maxn = 2000;
const int inf = 1000000010;
int c[maxn][maxn], d[maxn][maxn];
void Init() {
for (int i = 0; i < 2000; i++) {
c[i][0] = d[i][0] = 1;
for (int j = 1; j <= i; j++) {
... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1024;
long long f[4][N][N];
void addVal(int x, int y, long long val, int ind) {
for (int i = x; i < N; i |= (i + 1))
for (int s = y; s < N; s |= (s + 1)) f[ind][i][s] ^= val;
}
long long getSum(int x, int y, int ind) {
long long res = 0;
for (int i =... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
cout << 2 * a - 1 << ' ' << 2 << '\n' << "1 2";
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
long long fact(long long n) {
long long ans = 1;
for (long long i = 2; i <= n; i++) {
ans = ans * i;
}
return ans;
}
long long ncr(long long n, long long r) {
return fact(n) / (fact(r) * fact(n - r));
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool isprime(int n) {
if (n <= 2) {
return false;
}
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
int main() {
int N;
if (scanf("%d", &N) == EOF) {
return 0;
}
if (isprime(N)) {
printf("1\n%... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long mxN = 210;
class CF213A {
public:
long long n, k, x, c[mxN];
vector<long long> a[mxN];
map<pair<long long, long long>, long long> cost;
void solve(std::istream &in, std::ostream &out) {
in >> n;
for (long long i = 1; i <= n; i++) in >> c[i],... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
pair<int, int> p[222222];
set<pair<int, int> > ans;
int solve(pair<int, int> o) {
int j = n, ret = 0;
for (int i = 1; i <= n && i <= j; ++i) {
for (; j >= i && p[j].first + p[i].first > o.first ||
(p[j].first + p[i].first == o.first &&
... | 18 |
#include <bits/stdc++.h>
char s[333][333];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i & 1) {
if (j == 0)
printf("^");
else if (j < n / 2)
printf("%c", j & 1 ? '.' : '<');
else
printf("<");
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c = 0;
scanf("%d%d", &a, &b);
while (b > 0) {
c *= 10;
c += b % 10;
b /= 10;
}
printf("%d\n", a + c);
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 4e6 + 5;
const long long mod = 1000000007;
int main() {
int n;
scanf("%d", &n);
;
int arr[n];
int ans[n];
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
;
if (i == 0)
ans[i] = arr[i];
else
ans[i] = arr[i] - ar... | 4 |
#include <bits/stdc++.h>
using namespace std;
string itosm(long long x) {
if (x == 0) return "0";
string res = "";
while (x > 0) {
res += ((x % 10) + '0');
x /= 10;
}
reverse(res.begin(), res.end());
return res;
}
long long stoim(string str) {
long long res = 0;
int p = 0;
if (str[0] == '-') p... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long Set(long long N, long long pos) { return N = N | (1ll << pos); }
long long reset(long long N, long long pos) { return N = N & ~(1ll << pos); }
bool check(long long N, long long pos) { return (bool)(N & (1ll << pos)); }
void CI(long long &_x) { scanf("%d", &_x); }
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int t[n + 1];
memset(t, 0, sizeof(t));
for (int i = 0; i < m; i++) {
int a, b, d;
cin >> a >> b >> d;
t[a] += d;
t[b] -= d;
}
int ans = 0;
if (m == 0) {
cout << 0;
return 0;
} else {
for (in... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void fastaf(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
void solve(void) {
long long int N;
cin >> N;
long long int A[N];
for (int i = 0; i < N; i++) cin >> A[i];
int count = 0;
for (int i = 0; i < N - 1; i++) {
... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,tune=native")
#pragma GCC target("avx,avx2")
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
long long t;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int a[2002][2002];
int main() {
int n;
cin >> n;
vector<int> max_x, min_x, max_y, min_y;
max_x.assign(2002, -2001);
max_y.assign(2002, -2001);
min_x.assign(2002, 2001);
min_y.assign(2002, 2001);
int temp_x, temp_y;
for (int i = 0; i < n; i++) {
cin >> ... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
const int inf = 1e9;
const long long mod = 1e9 + 7;
using namespace std;
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int t;
cin >> t;
while (t--) {
int n, m, a[1005][1005] = {0}, b[1005];
long long res = 0;
cin >> n >> ... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct hehe {
int x, y;
} p[4];
int cmp(hehe a, hehe b) { return a.x < b.x; }
int main() {
int n;
while (scanf("%d", &n) != EOF) {
for (int i = 0; i < n; i++) scanf("%d%d", &p[i].x, &p[i].y);
int flag = 0;
for (int i = 0; i < n - 1; i++) {
for (int j... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200000;
struct splay {
int fa, lx, rx, s, hs, dep, Alls, depl, depr, Pres;
} Q[N + 3];
int go[N + 3], t[N + 3], last[N + 3], en;
int g[N + 3], gs[N + 3], L[N + 3], R[N + 3], fa[N + 3], n, m, root, ls;
char ch;
void read(int &ss) {
for (; !isdigit(ch); ch =... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = (1 << 21) + 5;
int n, m;
int a[MAX];
long long tree[22][2];
void f(int l, int r, int lev) {
if (l >= r) return;
int mid = (l + r) >> 1;
f(l, mid, lev + 1);
f(mid + 1, r, lev + 1);
for (int i = l; i <= mid; ++i) {
tree[lev][0] += lower_bound(a +... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MAXSIZE = 10000020;
int bufpos;
char buf[MAXSIZE];
void init() {
buf[fread(buf, 1, MAXSIZE, stdin)] = '\0';
bufpos = 0;
}
int readint() {
int val = 0;
for (; !isdigit(buf[bufpos]); bufpos++)
;
for (; isdigit(buf[bufpos]); bufpos++) val = val * 10 + b... | 18 |
#include <bits/stdc++.h>
using namespace std;
vector<int> x[3], q[111];
int vis[111], done[11111], a[222], pr[222];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= 2 * n; i++) {
scanf("%d", &a[i]);
vis[a[i]]++;
}
int id = 1;
for (int i = 1; i <= 2 * n; i++)
if (vis[a[i]] == 1) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int r = 0, b = 0, y = 0, g = 0, x = -1, u = -1, w = -1, z = -1;
for (int i = 0; i < s.length(); i++) {
if (s[i] == 'R') x = i;
if (s[i] == 'B') u = i;
if (s[i] == 'Y') w = i;
if (s[i] == 'G') z = i;
if (x != -1 &&... | 3 |
#include <bits/stdc++.h>
using namespace std;
string s, t;
int ns, nt;
double endpoint, aways, rways;
void path(int, int);
int main() {
int i;
cin >> s >> t;
ns = s.length();
nt = t.length();
for (i = 0; i < ns; i++)
if (s[i] == '+')
endpoint++;
else
endpoint--;
path(0, 0);
printf("%.1... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int get(long long int n, long long int k, long long int base) {
if (k % 2 == 1) {
return base + k / 2;
}
if (n % 2 == 0) {
return get(n / 2, k / 2, base + n / 2);
}
return get(n / 2 + 1, k / 2 + 1, base + n / 2);
}
int main() {
long long int n,... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> p(n), b(n, false);
for (auto &el : p) {
cin >> el;
el--;
}
int sb = 0;
for (int i = 0; i < n; i++) {
int t;
cin >> t;
sb += t;
}
int ans = 0;
for (int i = 0; i < n; i++) {
if (!b[i]) {
... | 9 |
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); i++)
#define R(i, j, k) for(int i = (j); i >= (k); i--)
#define ll long long
#define sz(a) a.size()
#define vi vector<int>
using namespace std;
const int N = 2e5 + 7, M = N * 80, rk = 20, mx = (1 << rk) - 1;
int n, q, a[N];
int ch[M][2], to0[M], to... | 27 |
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios {
fast_ios() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
};
} fast_ios_;
template <typename T>
istream &operator>>(istr... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a = 0, b = 0, la = 0, lb = 0;
int t, x, y;
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> t >> x >> y;
if (t == 1) {
a += x;
la += 10;
} else {
b += x;
lb += 10;
}
}
if (a >= la / 2)
cout << ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long int M = 2e5 + 5, LG = 30, inf = 1e18, mod = 1e9 + 7;
long long int n, m;
long long int seg[4 * M], lzy[4 * M];
long long int cst[M];
vector<pair<long long int, long long int> > baze[M];
void lzyupd(long long int id, long long int v) {
seg[id] += v;
lzy[i... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long n, arr[100005], x, ans;
long long fp(long long x, long long y) {
if (y == 0) return 1 % MOD;
if (y % 2 == 1) return (x * fp(x, y - 1)) % MOD;
long long r = fp(x, y / 2);
return (r * r) % MOD;
}
int main() {
cin >> n >> x;
lo... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 3e5 + 10, mod = 10007;
int main() {
int n;
cin >> n;
int a[n];
for (int& i : a) cin >> i;
int b[n];
for (int& i : b) cin >> i;
vector<pair<int, int> > u;
for (int j = 0; j < n; j++)
for (int i = 1; i < n; i++) {
if (b[i] < b[i - 1... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n;
cin >> n;
string s;
cin >> s;
long long arr[10] = {0};
for (long long i = 0; i < n; i++) {
arr[s[i] - '0']++;
}
long long v = arr[8];
long long sum = 0;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4e3 + 5;
int a[N];
long long dp[N][N];
long long MIN[N][N];
struct node {
int pre;
int v;
bool operator<(const node& b) const { return v < b.v; }
} p[N];
int main() {
int n;
while (~scanf("%d", &n)) {
for (int i = 1; i <= n; i++) scanf("%d", &a[i... | 15 |
#include <bits/stdc++.h>
using namespace std;
vector<int> g[100010];
int t[100010], p[18][100010], L[100010], d[100010];
vector<int> a[18][100010], c[100010];
void dfs(int u) {
for (int i = 0; i < (int)g[u].size(); i++) {
int v = g[u][i];
if (t[v] == -1) {
t[v] = u;
d[v] = d[u] + 1;
dfs(v);
... | 14 |
#include <bits/stdc++.h>
int isV(char s) {
int flag = 0;
char ss[] = {'a', 'e', 'i', 'o', 'u'};
for (int i = 0; i < strlen(ss); i++) {
if (ss[i] == s) {
flag = 1;
break;
} else {
flag = 2;
}
}
return flag;
}
int main() {
char s1[1001], s2[1001];
int v1 = 0, v2 = 0, l1 = 0, l2... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
long solve(long x, int k) {
long p = 1989;
long m = 1;
while (m <= x || k) {
m *= 10;
p = p + ((x - p) % m + m) % m + 1;
k--;
};
return p - 1;
}
int main(int argc, char **argv) {
;
ios_base::sync_with_stdio(0);
int n... | 12 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1E-9;
const int INF = 1000000000;
const long long INF64 = (long long)1E18;
const double PI = 3.1415926535897932384626433832795;
typedef struct {
int a;
double p;
} tpo;
int main() {
long long i, j, n, k = 0, t, m, a[200];
cin >> n;
long long kmi... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
vector<int> r(n);
for (int i = 0; i < n; i++) {
cin >> r[i];
}
vector<vector<int>> adj;
adj.resize(n);
for (int i = 0; i < k; i++) {
int u, v;
... | 7 |
#include <bits/stdc++.h>
namespace io {
int F() {
int F = 1, n = 0;
char ch;
while ((ch = getchar()) != '-' && (ch < '0' || ch > '9'))
;
ch == '-' ? F = 0 : n = ch - '0';
while ((ch = getchar()) >= '0' && ch <= '9') n = n * 10 + ch - '0';
return F ? n : -n;
}
long long G() {
long long F = 1, n = 0;
... | 24 |
#include <bits/stdc++.h>
int s[3];
int a[3][2];
int find(int a1, int a2, char a, int b1, int b2, char b, int c1, int c2,
char c) {
int i, j;
if ((a1 == b1 && b1 == c1) && (a2 + b2 + c2) == a1) {
printf("%d\n", a1);
for (i = 0; i < a2; i++) {
for (j = 0; j < a1; j++) printf("%c", a);
pri... | 9 |
#include <bits/stdc++.h>
using namespace std;
int inline in() {
int x;
scanf("%d", &x);
return x;
}
long long inline lin() {
long long x;
scanf("%I64d", &x);
return x;
}
void P(long long x) { printf("%I64d", x); }
long long fx[] = {0, 0, -1, 1};
long long fy[] = {-1, 1, 0, 0};
map<long long, long long> na;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int b[100005];
int main() {
int n;
scanf("%d", &n);
int i;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
b[i] = 999999999;
}
int tot = 0;
for (i = 0; i < n; i++) {
int now = lower_bound(b, b + tot, a[i]) - b;
if (now == tot) tot+... | 7 |
#include <bits/stdc++.h>
using namespace std;
char s[101];
int str, stl, tec, sym, i;
int main() {
scanf("%s", s);
for (str = 0; s[str] != 0; str++)
;
sym = str;
str = ceil((double)str / 20);
stl = ceil((double)sym / str);
sym = str * stl - sym;
printf("%d %d\n", str, stl);
for (str; str > 0; str--)... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long Inf = (long long)1e12 + 9;
long long dp[109][109];
int nxt[109][26];
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int n;
long long K;
string s;
cin >> n >> K >> s;
for (int i = n; i >= 0; --i) {
if (i ==... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, c;
cin >> n >> c;
vector<int> p(n), t(n);
for (auto i = 0; (i) < (n); ++i) cin >> p[i];
for (auto i = 0; (i) < (n); ++i) cin >> t[i];
int Limak = 0, Radewoosh = 0;
int ... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int number(deque<int> v) {
long long int ret = 0;
for (int i = 0; i < v.size(); ++i) {
ret = ret * 10 + v[i];
}
return ret;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
deque<int> v;
int k = n;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long edges;
pair<long long, pair<long long, long long> > edgelist[2 * 200005];
vector<long long> link(200005), size(200005, 1);
long long find(long long x) {
while (x != link[x]) x = link[x];
return x;
}
bool same(long long i, long long j) { return find(i) == find(... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
int n, m, nt, nb;
struct Point {
int x, y;
Point(int _x = 0, int _y = 0) { x = _x, y = _y; }
inline bool in() { return x > 0 && x <= n && y > 0 && y <= m; }
} S, t[10], b[10];
struct Node {
int x, y, ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n, k, row, col, a[501][501];
int main() {
cin >> n >> k;
if (k > n * n) return cout << -1, 0;
while (k) {
a[++row][++col] = 1;
--k;
int j = row + 1;
while (k >= 2) {
a[row][j] = 1;
a[j][col] = 1;
k -= 2;
++j;
if (j > n... | 6 |
#include <bits/stdc++.h>
using namespace std;
char buf;
inline int xint() {
while (buf = getchar(), buf < '0' || buf > '9')
;
int x = buf - '0';
for (; buf = getchar(), buf >= '0' && buf <= '9'; x = x * 10 + buf - '0')
;
return x;
}
inline long long xll() {
while (buf = getchar(), buf < '0' || buf > '... | 14 |
#include <bits/stdc++.h>
using namespace std;
int grundy[111111] = {0};
int main() {
int n, m, i, j, k;
scanf("%d", &n);
static vector<int> minDiv(n + 1, 1000000000);
static vector<int> seen(n + 1, -1);
for (i = 3; i <= n; ++i) {
for (j = 2; j * (j + 1) / 2 <= i; ++j) {
int f = i - (j - 1) * j / 2;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2 * 1e7 + 5, INF = (int)1e9 * 2 + 10;
const int TSH = 100;
bool is_prime(int p) {
for (int i = 2; i * i <= p; i++)
if (p % i == 0) return false;
return true;
}
bool OFlow(long long a, long long b) {
if ((INF + b - 1) / b <= a) return true;
long ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int v[100001];
int acum[100001];
long long cnt = 0, ans[100001];
struct Q {
int i, j, p;
Q(int a, int b, int c) : i(a), j(b), p(c){};
Q() {}
bool operator<(const Q &other) const {
if (i / 300 == other.i / 300) return j < other.j;
return i / 300 < other.i / 3... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long A[10004];
long long N;
int allSame() {
sort(A, A + N);
return A[0] == A[N - 1];
}
int main() {
cin >> N;
long long maximum = (long long)-(1e4), x;
for (int i = 0; i < N; i++) {
cin >> x;
A[x]++;
maximum = max(maximum, A[x]);
}
if (maximum... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.