text
stringlengths 49
983k
|
|---|
#include <bits/stdc++.h>
using namespace std;
long long int fact(long long int n) {
return (n == 1 || n == 0) ? 1 : n * fact(n - 1);
}
long long int nCr(long long int n, long long int r) {
return fact(n) / (fact(r) * fact(n - r));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int flag = 0;
int n, x;
cin >> n >> x;
vector<long long int> v(n);
long long int maxd = 0;
long long int maxx = 0;
unordered_set<int> s;
for (int i = 0; i < int(n); i++) {
cin >> v[i];
maxx = max(maxx, v[i]);
s.insert(v[i]);
}
if (s.count(x)) {
cout << 1 << '\n';
continue;
}
if (x < maxx) {
cout << 2 << '\n';
} else if ((x % maxx) != 0)
cout << (x / maxx) + 1 << '\n';
else
cout << (x / maxx) << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
using LL = long long;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
const int INF = 1e9;
const int MXN = 0;
const int MXV = 0;
int main() {
cin.tie(nullptr);
cout.tie(nullptr);
ios_base::sync_with_stdio(false);
;
int t;
cin >> t;
while (t--) {
int n, x;
bool hasEqual = false;
cin >> n >> x;
vector<int> v(n);
for (int i = 0; i != (int)n; ++i) {
cin >> v[i];
if (v[i] == x) {
hasEqual = true;
}
}
int mx = *max_element(v.begin(), v.end());
if (hasEqual) {
cout << 1 << '\n';
} else {
cout << max((x / mx) + 1 * (x % mx != 0), 2) << '\n';
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long tests;
cin >> tests;
for (long long test = 0; test < tests; ++test) {
long long n, x;
cin >> n >> x;
vector<long long> a(n);
long long fl = 1e9;
for (long long &i : a) {
cin >> i;
if (i == x) {
cout << 1 << '\n';
fl = 1;
}
}
if (fl == 1) continue;
sort((a).begin(), (a).end());
if (a.back() > x) {
cout << 2 << '\n';
continue;
}
long long m = a.back();
cout << min(fl, (x + m - 1) / m) << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int Tn;
cin >> Tn;
while (Tn--) {
int n, x;
cin >> n >> x;
int mx = 0, flag = 0;
while (n--) {
int t;
cin >> t;
if (t == x) flag = 1;
mx = max(mx, t);
}
if (!flag)
printf("%d\n", max((x - 1) / mx + 1, 2));
else
printf("%d\n", 1);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long double PI = acosl(-1);
bool compare_int(int a, int b) { return (a > b); }
bool compare_string(string a, string b) { return a.size() < b.size(); }
bool compare_pair(const pair<int, int> &a, const pair<int, int> &b) {
if (a.second == b.second)
return a.first > b.first;
else
return (a.second > b.second);
}
int fx[9] = {0, 0, -1, 1, -1, -1, 1, 1};
int fy[9] = {-1, 1, 0, 0, -1, 1, -1, 1};
void NA() {
cout << "NO" << endl;
exit(0);
}
void YA() {
cout << "YES" << endl;
exit(0);
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int t;
cin >> t;
while (t--) {
long long int n, m, x, mi = INT_MAX;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> x;
if (x == m)
mi = 1LL;
else if (x > m)
mi = min(mi, 2LL);
else {
long long int v = ceil((double)m / (double)x);
mi = min(mi, v);
}
}
cout << mi << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n, x;
cin >> n >> x;
vector<int> a(n);
for (int& i : a) {
cin >> i;
}
bool istrue = false;
for (int& i : a) {
if (i == x) istrue = true;
}
if (istrue) {
cout << 1 << '\n';
continue;
}
sort(a.begin(), a.end());
if (a[n - 1] > x)
cout << 2 << '\n';
else
cout << x / a[n - 1] + min(x % a[n - 1], 1) << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t) {
long long n, x;
cin >> n >> x;
long long a[n];
long long max = 0;
bool flag = 0;
int ans1 = 0;
for (long long i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == x) {
flag = 1;
ans1 = 1;
}
if (a[i] >= max) max = a[i];
}
if (ans1 == 0 && x > max) {
long long count = 0;
if (x % max == 0)
count = x / max;
else
count = x / max + 1;
cout << count << endl;
} else if (ans1 == 0 && x < max) {
cout << 2 << endl;
} else
cout << ans1 << endl;
t -= 1;
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long int T, n, x, a[100010], ans, dt[26][100010], dt2[26][26];
string s;
int main() {
ios::sync_with_stdio(false);
cin >> T;
while (T--) {
cin >> n >> x;
for (int i = 0; i < n; i++) cin >> a[i];
ans = 999999987654321;
for (int i = 0; i < n; i++)
ans = min(ans, x / a[i] + (bool)(x % a[i]) + (x / a[i] ? 0 : 1));
cout << ans << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long a[111111], mx, x;
int t, n;
int main() {
cin >> t;
while (t--) {
mx = 2e9;
cin >> n >> x;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (int i = 0; i < n; i++) {
if (a[i] > x) {
mx = min(mx, 2ll);
continue;
}
if (x % a[i] == 0) {
mx = min(mx, x / a[i]);
} else {
int tp = x % a[i];
if (lower_bound(a, a + n, tp) - a != n) {
mx = min(mx, (x / a[i] + 1));
} else {
mx = min(mx, x / a[i] + 2);
}
}
}
cout << mx << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void pause() {}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
string s[50];
long long int x, y = 0, n = 0, z, a, b, c = 0;
cin >> z;
while (z > 0) {
cin >> x >> y;
c = 1000000001;
for (int i = 0; i < x; i++) {
cin >> a;
n = y / a;
if (y % a > 0) n++;
if (y < a) n++;
c = min(c, n);
}
cout << c << endl;
z--;
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int INF = LONG_LONG_MAX >> 1;
const long long int NINF = LONG_LONG_MIN;
const long long int mmod = 100000000000ll;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long int t;
cin >> t;
while (t-- > 0) {
long long int n, x;
cin >> n >> x;
long long int a[n];
for (long long int& xx : a) cin >> xx;
sort(a, a + n);
long long int ans = INF;
for (long long int i = 0; i < n; i++) {
if (x % a[i] == 0) {
ans = min(ans, x / a[i]);
} else {
if (a[i] > x)
ans = min(ans, 2ll);
else
ans = min(ans, x / a[i] + 1);
}
}
cout << ans << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
int t;
cin >> t;
while (t--) {
long long n, x;
cin >> n >> x;
long long a[n], c = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == x) c++;
}
if (c > 0)
cout << "1" << endl;
else {
sort(a, a + n);
if (x <= (2 * (a[n - 1])))
cout << "2" << endl;
else {
if (x % a[n - 1] == 0)
cout << x / a[n - 1] << endl;
else {
long long p, q;
p = x / a[n - 1];
q = p * a[n - 1];
p += 1;
for (int i = 0; i < n - 1; i++) {
if (x % a[i] == 0) {
p = min(p, x / a[i]);
}
}
cout << p << endl;
}
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int t;
int n, x;
int a[100010];
bool one;
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &x);
int mx = 0;
one = false;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] == x) one = true;
mx = max(mx, a[i]);
}
if (one)
printf("1\n");
else if (x % mx == 0)
printf("%d\n", x / mx);
else if (x < mx)
printf("2\n");
else
printf("%d\n", x / mx + 1);
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const int N = 1e2 + 10;
int Dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
int Dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long powm(long long a, long long b) {
long long res = 1;
while (b > 0) {
if (b % 2) res *= a;
a *= a;
b /= 2;
}
return res;
}
map<long long, long long> mp;
long long queries(long long u, long long v, long long w = 0) {
long long ret = 0;
while (u != v) {
if (u < v) swap(u, v);
ret += mp[u];
mp[u] += w;
u /= 2;
}
return ret;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int t;
cin >> t;
while (t--) {
int n, x, mx = 0;
cin >> n >> x;
set<int> st;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
st.insert(a);
mx = max(mx, a);
}
if (st.count(x))
cout << "1\n";
else
cout << max(2, (x + mx - 1) / mx) << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int t = 0;
cin >> t;
while (t--) {
int n = 0, x = 0, ans1 = INT_MAX;
cin >> n >> x;
for (int i = 0; i < n; ++i) {
int in1 = 0;
cin >> in1;
if (!(x % in1))
ans1 = min(ans1, x / in1);
else
ans1 = min(ans1, max(2, (x - 1) / in1 + 1));
}
cout << ans1 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, x;
cin >> n >> x;
unordered_set<int> s;
int mx = 0;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
s.insert(a);
mx = max(mx, a);
}
if (s.count(x))
cout << 1 << '\n';
else
cout << max(2, (x + mx - 1) / mx) << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<long long int> v, v1, v2, v3, v4;
vector<pair<long long int, long long int> > vec, vec1, vec2;
vector<pair<long long int, pair<long long int, long long int> > > vec3;
vector<long long int> adj[200005];
map<long long int, long long int> Mp, Mp1, Mp2;
set<long long int> st, st1, st2, st3;
queue<long long int> Q;
stack<long long int> Stk;
multiset<pair<long long int, long long int> > S, S2;
multiset<long long int>::iterator it;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int t, n, x, a, val;
cin >> t;
while (t--) {
cin >> n >> x;
for (int i = 1; i <= n; i++) {
cin >> a;
if (x >= a) {
val = x / a;
if ((x % a) != 0) {
val++;
}
} else {
val = 2;
}
v.push_back(val);
}
cout << *min_element(v.begin(), v.end()) << endl;
v.clear();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, x, i, m = -1, p = 2, y;
cin >> n >> x;
long long a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > m) m = a[i];
if (a[i] == x) p = 0;
}
if (p == 0) {
cout << 1;
return;
}
y = x / m;
if (x % m != 0) y++;
cout << max(p, y);
return;
}
int main() {
long long t;
cin >> t;
while (t--) {
solve();
cout << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int n, x, ma = INT_MIN, a;
cin >> n >> x;
vector<int> mat(n, 0);
set<int> st;
for (int i = 0; i < n; i++) {
cin >> a;
ma = max(ma, a);
st.insert(a);
}
int ans = 0;
bool b = false;
while (x > 0) {
if (st.find(x) != st.end()) {
ans++;
break;
} else if (x <= 2 * ma) {
if (b)
ans++;
else
ans += 2;
break;
} else {
b = true;
int k = x / ma;
x = x - k * ma;
ans += k;
}
}
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int t;
int n, x;
int num;
int mx;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--) {
mx = -1e9;
cin >> n >> x;
bool flag = false;
for (int i = 0; i < n; i++) {
cin >> num;
if (num == x)
flag = true;
else
mx = max(mx, num);
}
if (flag)
cout << 1 << "\n";
else
cout << max(0, (x / mx) - 1) + (x % mx ? 2 : 1) << "\n";
;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int i = 0; i < t; i++) {
long n, x;
cin >> n >> x;
vector<long> a(n, 0);
long mm = 0;
int t = 0;
for (int j = 0; j < n; j++) {
cin >> a[j];
if (mm < a[j]) {
mm = a[j];
}
if (a[j] == x) {
cout << 1 << endl;
t = 1;
}
}
if (t) continue;
if (mm > x) {
cout << 2 << endl;
} else {
if (x % mm == 0) {
cout << x / mm << endl;
} else {
cout << x / mm + 1 << endl;
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int ans;
int main() {
int t;
cin >> t;
while (t--) {
int n, d;
cin >> n >> d;
int mx = -1;
bool flag = 0;
for (int a = 0; a < n; a++) {
int x;
cin >> x;
if (x == d) flag = 1;
mx = max(x, mx);
}
if (flag) {
cout << 1 << "\n";
continue;
}
long long int l = 2, h = 1000000000;
long long int m;
while (l <= h) {
m = l + (h - l) / 2;
long long int cur = mx * m;
if (cur > d)
h = m - 1;
else if (cur < d)
l = m + 1;
else
break;
}
if (mx * m >= d)
cout << m << "\n";
else
cout << m + 1 << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N];
int cmp(int a, int b) { return b > a; }
int main() {
int T;
scanf("%d", &T);
while (T--) {
int n, x, ans = 0;
scanf("%d %d", &n, &x);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] == x) ans = 1;
}
if (ans == 1) {
puts("1");
continue;
}
sort(a + 1, a + 1 + n, cmp);
if (x < a[n])
puts("2");
else {
ans = 2e9;
for (int i = 1; i <= n; i++)
if (x % a[i] == 0)
ans = min(ans, x / a[i]);
else
ans = min(ans, x / a[i] + 1);
printf("%d\n", ans);
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105000;
int n, x;
int a[MAXN];
void solve() {
scanf("%d %d", &n, &x);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int ans = 2e9;
for (int i = 0; i < n; i++) {
if (a[i] == x) {
ans = min(ans, 1);
} else {
int cur = max(2, (x + a[i] - 1) / a[i]);
ans = min(ans, cur);
}
}
printf("%d\n", ans);
}
int main() {
int tn;
scanf("%d\n", &tn);
while (tn--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFLL = 1e18;
const int MOD = 1e9 + 7;
const int alphabet = 26;
const double PI = 3.1415926535;
const int MAXINT = 1e5 + 1;
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, x;
scanf("%d", &n), scanf("%d", &x);
int ans = INF;
vector<int> a(n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (a[i] <= x)
ans = min(ans, x / a[i] + bool(x % a[i]));
else
ans = min(ans, 2);
}
printf("%d\n", ans);
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
char dir[4] = {'u', 'l', 'd', 'r'};
long long int cmp1(pair<long long int, string> a,
pair<long long int, string> b) {
if (a.first != b.first)
return a.first < b.first;
else
return a.second < b.second;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
long long int n, x;
cin >> n >> x;
bool abc = 0;
vector<long long int> a(n);
for (long long int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == x) {
if (abc == 0) {
cout << 1 << endl;
abc = 1;
}
}
}
if (abc == 1) continue;
sort((a).begin(), (a).end());
if (x < a[n - 1]) {
cout << 2 << endl;
} else {
long long int tmp = x / a[n - 1];
if (x % a[n - 1] != 0) tmp++;
cout << tmp << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct Scanner {
bool hasNext = 1;
bool hasRead = 1;
int nextInt() {
hasRead = 0;
int res = 0;
char flag = 1, ch = getchar();
while (ch != EOF && !isdigit(ch)) {
hasRead = 1;
flag = (ch == '-') ? -flag : flag;
ch = getchar();
}
while (ch != EOF && isdigit(ch)) {
hasRead = 1;
res = res * 10 + (ch - '0');
ch = getchar();
}
if (ch == EOF) hasNext = 0;
return res * flag;
}
long long nextLL() {
hasRead = 0;
long long res = 0;
char flag = 1, ch = getchar();
while (ch != EOF && !isdigit(ch)) {
hasRead = 1;
flag = (ch == '-') ? -flag : flag;
ch = getchar();
}
while (ch != EOF && isdigit(ch)) {
hasRead = 1;
res = res * 10 + (ch - '0');
ch = getchar();
}
if (ch == EOF) hasNext = 0;
return res * flag;
}
char nextChar() {
hasRead = 0;
char ch = getchar();
while (ch != EOF && isspace(ch)) {
hasRead = 1;
ch = getchar();
}
if (ch == EOF) hasNext = 0;
return ch;
}
int nextString(char *str) {
hasRead = 0;
int len = 0;
char ch = getchar();
while (ch != EOF && isspace(ch)) {
hasRead = 1;
ch = getchar();
}
while (ch != EOF && !isspace(ch)) {
hasRead = 1;
str[++len] = ch;
ch = getchar();
}
str[len + 1] = 0;
if (ch == EOF) hasNext = 0;
return len;
}
} sc;
long long rd() {
long long x = sc.nextLL();
return x;
}
void rd(int &x) { x = sc.nextInt(); }
void rd(long long &x) { x = sc.nextLL(); }
void rd(char &x) { x = sc.nextChar(); }
void rd(char *x) { sc.nextString(x); }
template <typename T1, typename T2>
void rd(pair<T1, T2> &x) {
rd(x.first);
rd(x.second);
}
template <typename T>
void rd(T *x, int n) {
for (int i = 1; i <= n; ++i) rd(x[i]);
}
void printInt(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x >= 10) printInt(x / 10);
putchar('0' + x % 10);
}
void printLL(long long x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x >= 10) printLL(x / 10);
putchar('0' + x % 10);
}
void pr(int x, char ch = '\n') {
printInt(x);
putchar(ch);
}
void pr(long long x, char ch = '\n') {
printLL(x);
putchar(ch);
}
template <typename T1, typename T2>
void pr(pair<T1, T2> x, char ch = '\n') {
pr(x.first, ' ');
pr(x.second, ch);
}
template <typename T>
void pr(T *x, int n) {
for (int i = 1; i <= n; ++i) pr(x[i], " \n"[i == n]);
}
template <typename T>
void pr(vector<T> &x) {
int n = x.size();
for (int i = 1; i <= n; ++i) pr(x[i - 1], " \n"[i == n]);
}
template <typename T>
void cmin(T &x, T y) {
if (y < x) x = y;
}
template <typename T>
void cmax(T &x, T y) {
if (y > x) x = y;
}
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1.0);
const double EPS = 1e-9;
int n, x;
int a[200005];
struct Solver {
void InitOnce() {}
void Read() {
rd(n);
rd(x);
rd(a, n);
}
void Solve() {
sort(a + 1, a + 1 + n);
a[n + 1] = INF;
if (*lower_bound(a + 1, a + 1 + n, x) == x) {
puts("1");
return;
}
if (a[n] * 2 >= x) {
puts("2");
return;
}
int res = (x + a[n] - 1) / a[n];
pr(res);
}
} solver;
int main() {
solver.InitOnce();
int t = 1;
t = sc.nextInt();
while (t--) {
solver.Read();
if (!sc.hasRead) break;
solver.Solve();
if (!sc.hasNext) break;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 10e-9;
const int INF = 1e9 + 5;
const long long INFLL = (long long)INF * (long long)INF;
const long long MOD = 1e9 + 7;
const long double PI = 3.14159265358979323846;
struct HASH {
size_t operator()(const pair<int, int>& x) const {
return hash<long long>()(((long long)x.first) ^
(((long long)x.second) << 32));
}
};
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os << "[";
for (int i = 0; i < (int)v.size(); ++i) {
os << v[i];
if (i != (int)v.size() - 1) os << ", ";
}
os << "]\n";
return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
os << "{";
for (const auto& it : v) {
os << it;
if (it != *v.rbegin()) os << ", ";
}
os << "}\n";
return os;
}
template <typename T>
ostream& operator<<(ostream& os, const unordered_set<T>& v) {
os << "{";
for (const auto& it : v) {
os << it;
if (it != *v.rbegin()) os << ", ";
}
os << "}\n";
return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v) {
os << "{";
for (const auto& it : v) {
os << it.first << " : " << it.second;
if (it != *v.rbegin()) os << ", ";
}
os << "}\n";
return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const unordered_map<T, S>& v) {
os << "{";
for (const auto& it : v) {
os << it.first << " : " << it.second;
if (it != *v.rbegin()) os << ", ";
}
os << "}\n";
return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
os << "(";
os << v.first << ", " << v.second << ")";
os << "\n";
return os;
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
void solve() {
int n;
long long x;
cin >> n >> x;
unordered_set<long long> a;
long long ma = 0;
long long cnt = INT_MAX;
for (int i = 0; i < n; i++) {
long long num;
cin >> num;
a.insert(num);
ma = max(ma, num);
if (x % num == 0) {
cnt = min(cnt, x / num);
}
}
if ((double)ma > (double)x / 2) {
cout << min(cnt, 2LL) << "\n";
return;
}
long long left = x - (2 * ma - 1);
long long cand2 = ceil((double)left / ma) + 2;
long long cand = x / ma;
long long r = x % ma;
if (r != 0) {
if (a.find(r) != a.end()) {
cand += 1;
} else {
cand += 2;
}
}
cout << min({cnt, cand, cand2}) << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
const int NMAX = 50;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
vector<long long> del(long long n) {
vector<long long> ans;
long long i = 1;
for (i = 1; i * i < n; i++) {
if (n % i == 0) {
ans.push_back(i);
ans.push_back(n / i);
}
}
if (n % i == 0) ans.push_back(i);
sort((ans).begin(), (ans).end());
return ans;
}
void solve() {
int n, x;
cin >> n >> x;
int Max = INT_MIN;
bool kek = false;
int ans = INT_MAX;
for (int i = 0; i < n; i++) {
int y;
cin >> y;
if (y > x)
ans = min(ans, 2);
else
ans = min(int(ceil(x / double(y))), ans);
}
cout << ans << "\n";
}
int main() {
srand(time(0));
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) solve();
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = (2e5 + 5);
const int mod = 1e9 + 7;
long long int n, a[N], x;
vector<vector<int>> g;
long long int pow_mod_m(long long int a, long long int n) {
if (!n) return 1;
long long int pt = pow_mod_m(a, n / 2);
pt *= pt;
pt %= mod;
if (n & 1) pt *= a, pt %= mod;
return pt;
}
struct LCA {
vector<int> height, euler, first, segtree;
vector<bool> visited;
int n;
LCA(vector<vector<int>> &adj, int root = 0) {
n = adj.size();
height.resize(n);
first.resize(n);
euler.reserve(2 * n);
visited.assign(n, false);
dfs(adj, root);
int m = euler.size();
segtree.resize(4 * m);
build(1, 0, m - 1);
}
void dfs(vector<vector<int>> &adj, int node, int h = 0) {
visited[node] = 1;
height[node] = h;
first[node] = euler.size();
euler.push_back(node);
for (auto to : adj[node]) {
if (!visited[to]) {
dfs(adj, to, h + 1);
euler.push_back(node);
}
}
}
void build(int node, int b, int e) {
if (b == e)
segtree[node] = euler[b];
else {
int m = (b + e) >> 1;
build(node << 1, b, m);
build(node << 1 | 1, m + 1, e);
int l = segtree[node << 1], r = segtree[node << 1 | 1];
segtree[node] = (height[l] < height[r]) ? l : r;
}
}
int query(int node, int b, int e, int L, int R) {
if (b > R || e < L) return -1;
if (b >= L and e <= R) return segtree[node];
int mid = (b + e) >> 1;
int left = query(node << 1, b, mid, L, R);
int right = query(node << 1 | 1, mid + 1, e, L, R);
if (left == -1) return right;
if (right == -1) return left;
return (height[left] < height[right]) ? left : right;
}
int lca(int u, int v) {
int left = first[u], right = first[v];
if (left > right) swap(left, right);
return query(1, 0, euler.size() - 1, left, right);
}
int dist(int u, int v) {
int lca_u_v = lca(u, v);
return height[u] + height[v] - 2 * height[lca_u_v];
}
};
long long int ceil(long long int m) { return x % m == 0 ? x / m : x / m + 1; }
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int ts = 1;
cin >> ts;
while (ts--) {
cin >> n >> x;
bool flag = 0;
for (long long int i = 0; i < n; ++i) {
cin >> a[i];
if (x == a[i]) flag = 1;
}
if (flag)
cout << 1 << "\n";
else
cout << max(2ll, ceil(*max_element(a, a + n))) << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
if (a == 0) return b;
return gcd(b % a, a);
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int tt;
cin >> tt;
while (tt--) {
int n, x;
cin >> n >> x;
int a[n];
for (auto &i : a) cin >> i;
sort(a, a + n);
auto ptr1 = lower_bound(a, a + n, x);
auto ptr2 = upper_bound(a, a + n, x);
if (ptr1 != ptr2) {
cout << 1 << "\n";
continue;
}
if (ptr2 != a + n) {
cout << 2 << "\n";
} else {
ptr2--;
int val = *(ptr2);
cout << (x + val - 1) / val << "\n";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int i = 0; i < t; i++) {
int n, x;
cin >> n >> x;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
sort(a.begin(), a.end());
int count = INT_MAX;
for (int i = 0; i < n; i++) {
if (a[i] == x)
count = 1;
else
count = min(count, max(2, (x - 1) / a[i] + 1));
}
cout << count << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int maxn = 100;
int a[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t;
for (cin >> t; t; t -= 1) {
int n, x, am = 0, ok = 0;
cin >> n >> x;
for (int a; n; n -= 1) {
cin >> a;
am = max(a, am);
if (a == x) ok = 1;
}
if (ok)
cout << "1\n";
else
cout << max(2, (x + am - 1) / am) << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long int T, n, x;
long int i, j, k;
bool eqx;
cin >> T;
while (T--) {
eqx = false;
k = -1;
cin >> n >> x;
for (i = 0; i < n; ++i) {
cin >> j;
k = max(k, j);
if (j == x) eqx = true;
}
if (eqx) {
cout << 1;
} else if (k > x) {
cout << 2;
} else {
if (x % k == 0)
cout << x / k;
else
cout << x / k + 1;
}
cout << "\n";
}
}
|
#include <bits/stdc++.h>
int main() {
int t, n;
long long int x, jump, jumpmax, rta;
bool exactx;
std::cin >> t;
for (int i = 0; i < t; i++) {
exactx = false;
std::cin >> n;
std::cin >> x;
std::cin >> jumpmax;
if (jumpmax == x) exactx = true;
for (int j = 1; j < n; j++) {
std::cin >> jump;
if (!exactx) {
if (jump == x) exactx = true;
if (jump > jumpmax) jumpmax = jump;
}
}
if (exactx)
rta = 1;
else if (x < jumpmax)
rta = 2;
else
rta = ceil(((double)x) / jumpmax);
std::cout << rta << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
template <typename X>
inline X abs(const X& a) {
return a < 0 ? -a : a;
}
template <typename X>
inline X sqr(const X& a) {
return a * a;
}
bool rev(pair<long long int, long long int>& a,
pair<long long int, long long int>& b) {
return a.first < b.first || (a.first == b.first && a.second > b.second);
}
void test() {
long long int n, x;
cin >> n >> x;
long long int mx = -1;
long long int a[n];
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] <= x) mx = max(mx, a[i]);
}
sort(a + 1, a + n + 1);
long long int ans = 2e9;
if (mx > 0) {
ans = x / mx;
if (x % mx) ans++;
}
if (a[n] > x) ans = min(ans, 2LL);
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t = 1;
cin >> t;
while (t--) test();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int fi(int l, int r, int n) {
while (l <= r) {
int mid = (l + r) / 2;
if (a[mid] == n) return 1;
if (a[mid] < n) l = mid + 1;
if (a[mid] > n) r = mid - 1;
}
return 0;
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, x, ans = 0;
scanf("%d %d", &n, &x);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (a[i] == x) ans = 1;
}
if (ans == 1) {
printf("1\n");
continue;
}
sort(a, a + n);
long long int max = a[n - 1] * 2;
if (x % a[n - 1] == 0)
ans = x / a[n - 1];
else if (x <= max) {
ans = 2;
} else {
ans = x / max * 2 - 2;
x = x % max + max;
if (a[n - 1] + max >= x)
ans += 3;
else
ans += 4;
}
printf("%d\n", ans);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long n, x;
cin >> n >> x;
long long arr[n + 10];
long long maxi = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
long long res = 10000000000;
for (int i = 0; i < n; i++) {
long long temp = x / arr[i];
long long f = x % arr[i];
if (f > 0) {
if (temp == 0)
temp += 2;
else
temp++;
}
res = min(res, temp);
}
cout << res << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int main() {
int t;
cin >> t;
while (t--) {
int n, x;
cin >> n >> x;
int cnt1 = 0, cnt2 = 0;
int flag = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] >= (x - 1) / 2 + 1 && flag != 1) flag = 2;
if (a[i] == x) flag = 1;
}
sort(a, a + n);
if (flag) {
printf("%d\n", flag);
continue;
} else {
printf("%d\n", (x - 1) / a[n - 1] + 1);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int N = 2e5 + 10;
const ll inf = 1e15 + 42;
const ll mod = 1000000007;
void testCase() {
int t;
cin >> t;
while (t--) {
int n;
ll x;
cin >> n >> x;
ll a[n + 2];
int flg = 0;
ll mid = (x + 1) / 2;
ll mx = -1;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == x) {
flg = 1;
}
if (a[i] >= mid && flg == 0) {
flg = 2;
}
mx = max(mx, a[i]);
}
if (flg == 1) {
cout << "1"
<< "\n";
} else if (flg == 2) {
cout << "2"
<< "\n";
} else {
ll ans = (x - 2 * mx + mx - 1) / mx;
ans = (ans + 2);
cout << ans << "\n";
}
}
}
int main() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
testCase();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t > 0) {
long n;
long long z;
long long x;
cin >> n;
cin >> x;
vector<long long> A(n + 5);
bool flag = 0;
long long m = INT_MIN;
long long ans = 0;
for (long i = 0; i < n; i++) {
cin >> A[i];
if (A[i] == x) {
flag = 1;
}
if (A[i] > m) {
m = max(A[i], m);
}
}
if (flag == 1) {
cout << "1\n";
t -= 1;
continue;
}
if (x < m) {
ans = 1;
} else {
ans = x / m;
}
if (x % m != 0) ans += 1;
cout << ans << endl;
t -= 1;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
int x;
cin >> n >> x;
bool ans = false;
int maxx = 0;
int no;
int a[n];
for (int(i) = 0; (i) < (n); (i)++) {
cin >> a[i];
if (a[i] == x) ans = true;
maxx = (maxx < a[i] ? a[i] : maxx);
}
int ans2 = x / maxx;
if (x % maxx != 0) ans2++;
int xx = x;
if (maxx == 1)
cout << xx << endl;
else if (ans)
cout << ans << endl;
else
cout << (2 < ans2 ? ans2 : 2) << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long brr[500000];
long long arr[500000];
map<int, int> mm;
map<long long, long long> mmm;
vector<int> v;
vector<long long> vv;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cout << fixed << setprecision(15);
int t;
cin >> t;
while (t--) {
long long n, x;
cin >> n >> x;
set<long long> a;
long long y, maxi = -1;
for (int i = 0; i < n; i++) {
cin >> y;
a.insert(y);
maxi = max(maxi, y);
}
if (a.count(x))
cout << "1" << endl;
else
cout << max((long long)2, (long long)(x + maxi - 1) / maxi) << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, x;
cin >> n >> x;
int a[n];
int mx = -1;
int count = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
mx = max(mx, a[i]);
if (a[i] == x) count = 1;
}
if (count == 1) {
cout << 1 << endl;
} else if (2 * mx >= x) {
cout << 2 << endl;
} else {
int k = x / mx;
if (x % mx == 0) {
k--;
}
k++;
cout << k << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e9 + 7;
const long long int inf2 = inf * inf;
priority_queue<long long int, vector<long long int>, greater<long long int>>
mnheap;
priority_queue<long long int> mxheap;
long long int gcd(long long int x, long long int y) {
if (x == 0) return y;
return gcd(y % x, x);
}
int is_prime(long long int x) {
if (x < 2) return 0;
for (long long int i = 2; i * i <= x; i++) {
if (x % i == 0) return 0;
}
return 1;
}
inline long long int modpw(long long int x, long long int y, long long int z) {
long long int res = 1;
x = x % z;
while (y) {
if (y & 1) res = (res * x) % z;
x = (x * x) % z;
y /= 2;
}
return res;
}
inline long long int modinv(long long int x, long long int z) {
return modpw(x, z - 2, z);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
long long int n, x;
cin >> n >> x;
int flag = 0;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] == x) flag = 1;
}
if (flag == 1) {
cout << 1 << endl;
continue;
}
sort(arr, arr + n);
if (arr[n - 1] > x) {
cout << 2 << endl;
} else {
cout << (x + arr[n - 1] - 1) / arr[n - 1] << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int cnst = 1e9 + 7;
bool IsQuery = true;
long long int q = 1, cnt;
void solve() {
long long int c, r, b, g, o, e, p = 0, d, x, y, n, minm = cnst, maxm = -1,
k = 1, sum = 0, ans = 0, l, flag = 0;
string s, t;
vector<long long int> a, v;
map<long long int, long long int> m;
cin >> n >> d;
a.resize(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == d) flag = 1;
}
maxm = *max_element(a.begin(), a.end());
ans = d / maxm;
if (flag) {
cout << 1 << endl;
return;
}
if (d % maxm != 0) ans += 1;
if (ans == 1) ans++;
cout << ans << endl;
return;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
if (IsQuery) cin >> q;
for (int i = 0; i < q; i++) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void canhazfast() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
template <typename T>
T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
template <typename T>
T extgcd(T a, T b, T &x, T &y) {
T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
while (b) {
T q = a / b;
a %= b;
swap(a, b);
x0 -= q * x1;
swap(x0, x1);
y0 -= q * y1;
swap(y0, y1);
}
x = x0;
y = y0;
return a;
}
int ctz(unsigned x) { return __builtin_ctz(x); }
int ctzll(unsigned long long x) { return __builtin_ctzll(x); }
int clz(unsigned x) { return __builtin_clz(x); }
int clzll(unsigned long long x) { return __builtin_clzll(x); }
int popcnt(unsigned x) { return __builtin_popcount(x); }
int popcntll(unsigned long long x) { return __builtin_popcountll(x); }
int bsr(unsigned x) { return 31 ^ clz(x); }
int bsrll(unsigned long long x) { return 63 ^ clzll(x); }
int a[100016];
void solve() {
int n, x, ans;
cin >> n >> x;
ans = 1e9;
for (int i = 0; i < n; ++i) {
cin >> a[i];
if (a[i] == x)
ans = min(ans, 1);
else if (a[i] > x)
ans = min(ans, 2);
else
ans = min(ans, (x - 1) / a[i] + 1);
}
cout << ans << '\n';
}
int main() {
canhazfast();
int t;
cin >> t;
for (; t; --t) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, x;
cin >> n >> x;
int a[n];
int ans = 1e9;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > x) {
ans = min(ans, 2);
}
if (a[i] <= x) {
ans = min(ans, (x + a[i] - 1) / a[i]);
}
}
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 5;
int t, n, x;
int s[M];
int main() {
cin >> t;
while (t--) {
cin >> n >> x;
memset(s, 0, sizeof(s));
int flag = 0;
int ma = 0;
for (int i = 0; i < n; i++) {
cin >> s[i];
if (s[i] == x) flag = 1;
ma = max(ma, s[i]);
}
if (flag) {
cout << 1 << endl;
} else if (ma > x)
cout << 2 << endl;
else {
int w = x / ma;
if (x % ma == 0) {
cout << w << endl;
} else
cout << ++w << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n, x;
cin >> n >> x;
int ans = INT_MAX;
for (int i = 0; i < n; i++) {
int w;
cin >> w;
if (w == x) ans = 1;
ans = min(ans, max(2, (x + w - 1) / w));
}
cout << ans << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, x, a, b;
cin >> t;
while (t--) {
cin >> n >> x;
a = 0;
bool flag = false;
for (int i = 0; i < n; i++) {
cin >> b;
a = max(a, b);
if (b == x) {
flag = true;
}
}
if (x > a) {
cout << (int)ceil((double)x / a) << endl;
} else {
if (flag) {
cout << 1 << endl;
} else {
cout << 2 << endl;
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int cases;
cin >> cases;
for (int i = 0; i < cases; i++) {
int n, x;
cin >> n >> x;
int maxx = 0;
bool check = false;
for (int k = 0; k < n; k++) {
int num;
cin >> num;
if (num == x) check = true;
maxx = max(maxx, num);
}
if (check) {
cout << 1 << endl;
} else {
if (maxx >= x) {
cout << 2 << endl;
} else {
if (((x * 1.0) / 2) <= maxx) {
cout << 2 << endl;
} else {
int t = x / maxx;
if (maxx * t < x) t++;
cout << t << endl;
}
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
int T;
cin >> T;
while (T--) {
long long int n, k;
cin >> n >> k;
long long int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
if (count(a, a + n, k) > 0) {
cout << 1;
} else {
long long int h = 2;
sort(a, a + n);
if (k % a[n - 1] == 0) {
cout << max(h, k / a[n - 1]);
} else {
cout << max(h, (k / a[n - 1]) + 1);
}
}
cout << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
unordered_set<int> st;
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
for (int& x : a) {
cin >> x;
}
st.clear();
int max_a = 0;
unordered_set<int> idx1;
for (int i = 0; i < n; i++) {
max_a = max(max_a, a[i]);
if (st.find(a[i]) != st.end()) {
break;
}
st.insert(a[i]);
if (i + 1 == max_a && i + 1 < n) {
idx1.insert(i + 1);
}
}
reverse(a.begin(), a.end());
st.clear();
max_a = 0;
unordered_set<int> idx2;
for (int i = 0; i < n; i++) {
max_a = max(max_a, a[i]);
if (st.find(a[i]) != st.end()) {
break;
}
st.insert(a[i]);
if (i + 1 == max_a && i + 1 < n) {
if (idx1.find(n - (i + 1)) != idx1.end()) idx2.insert(n - (i + 1));
}
}
cout << idx2.size() << endl;
for (int i : idx2) {
cout << i << " " << n - i << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int ara[n];
for (int i = 0; i < n; i++) cin >> ara[i];
int x = 2;
vector<pair<int, int>> sol;
while (x--) {
map<int, int> m1, m2;
bool ans = true;
int vis = 0, ans1 = 0, ans2 = 0, temp = 0;
for (int i = 0; i < n; i++) {
vis++;
if (m1[ara[i]] == 0) {
m1[ara[i]] = 1;
temp = max(temp, ara[i]);
if (vis == temp) ans1 = vis;
} else
break;
}
if (ans1 == n) {
ans = false;
} else {
vis = 0;
temp = 0;
for (int j = n - 1; j >= ans1; j--) {
vis++;
if (m2[ara[j]] == 0) {
m2[ara[j]] = 1;
temp = max(temp, ara[j]);
if (vis == temp) ans2 = vis;
} else
break;
}
if (ans2 != n - ans1) ans = false;
}
if (ans) {
if (x == 1)
sol.push_back({ans1, ans2});
else {
if (sol.size() > 0) {
if (sol[0].first != ans2 && sol[0].second != ans1) {
sol.push_back({ans2, ans1});
}
} else {
sol.push_back({ans2, ans1});
}
}
}
reverse(ara, ara + n);
}
cout << sol.size() << endl;
for (int i = 0; i < sol.size(); i++) {
cout << sol[i].first << " " << sol[i].second << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, i, j;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long arr[n + 1];
long long tot = 0;
for (i = 1; i <= n; i++) {
cin >> arr[i];
tot += arr[i];
}
map<long long, long long> cnt1, cnt2;
long long chkr1[n + 1], chkr2[n + 2];
memset(chkr1, 0, sizeof(chkr1));
memset(chkr2, 0, sizeof(chkr2));
for (i = 1; i <= n; i++) {
chkr1[i] = chkr1[i - 1];
if (cnt1[arr[i]] == 0) {
chkr1[i]++;
}
cnt1[arr[i]]++;
}
for (i = n; i >= 1; i--) {
chkr2[i] = chkr2[i + 1];
if (cnt2[arr[i]] == 0) {
chkr2[i]++;
}
cnt2[arr[i]]++;
}
long long adder = 0;
vector<long long> res;
for (i = 1; i < n; i++) {
adder += arr[i];
bool val1 = (adder == (i * (i + 1) / 2));
long long k = n - i;
bool val2 = ((tot - adder) == (k * (k + 1) / 2));
bool val3 = (chkr1[i] == i);
bool val4 = (chkr2[i + 1] == (n - i));
if (val1 && val2 && val3 && val4) res.push_back(i);
}
long long len = res.size();
cout << len << "\n";
for (i = 0; i < len; i++) cout << res[i] << " " << n - res[i] << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long tc;
cin >> tc;
while (tc--) {
long long n;
cin >> n;
long long x[n + 5];
long long m = 0;
set<long long> st;
for (long long i = 0; i < n; i++) {
cin >> x[i];
m = max(m, x[i]);
}
set<pair<long long, long long>> y;
long long f = 0;
for (long long i = 0; i < m; i++) {
if (st.count(x[i]) == 0) {
st.insert(x[i]);
} else {
f = 1;
break;
}
}
st.clear();
long long r = n - m;
for (long long i = m; i < n; i++) {
if (st.count(x[i]) == 0) {
st.insert(x[i]);
} else
f = 1;
if (x[i] > r) {
f = 1;
}
}
if (f == 0) {
y.insert({m, n - m});
}
st.clear();
f = 0;
for (long long i = n - 1; i >= n - m; i--) {
if (st.count(x[i]) == 0) {
st.insert(x[i]);
} else
f = 1;
}
st.clear();
for (long long i = 0; i < n - m; i++) {
if (st.count(x[i]) == 0) {
st.insert(x[i]);
} else
f = 1;
if (x[i] > r) {
f = 1;
}
}
if (f == 0) {
y.insert({n - m, m});
}
cout << y.size() << endl;
while (y.size()) {
auto t = *y.begin();
cout << t.first << " " << t.second << endl;
y.erase(t);
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const long long maxn = 1e6 + 5;
const int N = 2e5 + 5;
int n, a[N], mx, ans_cnt, ans[N][2];
bool vis[N];
bool check(int *a, int n) {
for (int i = 1; i <= n; i++) vis[i] = 0;
for (int i = 1; i <= n; i++) vis[a[i]] = 1;
for (int i = 1; i <= n; i++) {
if (!vis[i]) return 0;
}
return 1;
}
bool judge(int x, int y) { return check(a, x) && check(a + x, y - x); }
void solve() {
ans_cnt = 0;
cin >> n;
mx = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
mx = max(a[i], mx);
}
if (judge(n - mx, n)) {
ans[++ans_cnt][0] = n - mx;
ans[ans_cnt][1] = mx;
}
if (mx * 2 != n && judge(mx, n)) {
ans[++ans_cnt][0] = mx;
ans[ans_cnt][1] = n - mx;
}
cout << ans_cnt << '\n';
for (int i = 1; i <= ans_cnt; i++) {
cout << ans[i][0] << " " << ans[i][1] << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while (T--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline int inn() {
int x = 0, c = getchar();
bool f = 0;
for (; !isdigit(c); c = getchar())
if (c == '-') f = 1;
if (f)
for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) - (c ^ 48);
else
for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
return x;
}
const int N = 200005;
int n, a[N], c[N], q[N][2];
bool b[N], pre[N], suf[N];
void add(int i) {
for (; i <= n; i += (i & -i)) ++c[i];
}
int getsum(int i) {
int sum = 0;
for (; i >= 1; i -= (i & -i)) sum += c[i];
return sum;
}
int main() {
int t = inn();
while (t--) {
n = inn();
for (int i = 1; i <= n; ++i) {
a[i] = inn();
}
memset(b, 0, sizeof(bool) * (n + 1));
memset(c, 0, sizeof(int) * (n + 1));
memset(pre, 0, sizeof(bool) * (n + 1));
for (int i = 1; i < n; ++i) {
if (b[a[i]])
break;
else {
b[a[i]] = 1;
add(a[i]);
pre[i] = (getsum(i) == i);
}
}
memset(b, 0, sizeof(bool) * (n + 1));
memset(c, 0, sizeof(int) * (n + 1));
memset(suf, 0, sizeof(bool) * (n + 1));
for (int i = n; i >= 2; --i) {
if (b[a[i]])
break;
else {
b[a[i]] = 1;
add(a[i]);
suf[i] = (getsum(n - i + 1) == n - i + 1);
}
}
int ans = 0;
for (int i = 1; i < n; ++i) {
if (pre[i] && suf[i + 1]) {
++ans;
q[ans][0] = i;
q[ans][1] = n - i;
}
}
printf("%d\n", ans);
for (int i = 1; i <= ans; ++i) {
printf("%d %d\n", q[i][0], q[i][1]);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 1e17;
void solve() {
long long n;
cin >> n;
long long a[n], b[n], c[n];
long long mx = -1;
for (long long i = 0; i < n; i++) {
cin >> a[i];
b[i] = a[i];
c[i] = a[i];
mx = max(mx, a[i]);
}
long long ok = 1, OK = 1;
long long p = mx;
long long q = n - mx;
if (p < q) {
ok = 0;
OK = 0;
}
long long aa[n], bb[n];
for (long long i = 0; i < p; i++) {
aa[i] = i + 1;
}
long long j = 1;
for (long long i = p; i < n; i++) {
aa[i] = j++;
}
for (long long i = 0; i < q; i++) {
bb[i] = i + 1;
}
j = 1;
for (long long i = q; i < n; i++) {
bb[i] = j++;
}
sort(b, b + p);
sort(b + p, b + n);
sort(c + q, c + n);
sort(c, c + q);
for (long long i = 0; i < n; i++) {
if (aa[i] != b[i]) {
ok = 0;
break;
}
}
for (long long i = 0; i < n; i++) {
if (bb[i] != c[i]) {
OK = 0;
break;
}
}
if (ok == 0 and OK == 0) {
cout << 0 << "\n";
return;
}
long long flag = 0;
for (long long i = q; i < p; i++) {
if (a[i] <= q) {
flag = 1;
break;
}
}
if (flag == 0 and p != q) {
cout << 2 << "\n";
cout << q << " " << p << "\n";
cout << p << " " << q << "\n";
} else {
cout << 1 << "\n";
long long check = 0;
for (long long i = 0; i < q; i++) {
if (a[i] > q) {
check = 1;
break;
}
}
if (check)
cout << p << " " << q << "\n";
else
cout << q << " " << p << "\n";
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p);
template <class T>
ostream &operator<<(ostream &os, vector<T> &v);
template <class T>
ostream &operator<<(ostream &os, set<T> &v);
const long long mod = 1e9 + 7;
const int N = 2e5 + 5;
void Solve(int cas) {
int n;
cin >> n;
vector<int> a(n);
vector<pair<int, int> > ans;
map<int, int> mp;
bool flg = true;
for (int i = 0; i < n; i++) {
cin >> a[i];
mp[a[i]]++;
if (mp[a[i]] > 2) {
flg = false;
}
}
if (!flg) {
cout << 0 << "\n";
return;
}
mp.clear();
vector<bool> pref(n, 0), suf(n, 0);
int mex = 1;
for (int i = 0; i < n; i++) {
mp[a[i]]++;
if (mp[a[i]] == 2) break;
if (a[i] == mex) {
while (mp[mex] == 1) {
mex++;
}
}
if (i + 1 == mex - 1) pref[i] = 1;
}
mp.clear();
mex = 1;
for (int i = n - 1, j = 0; i >= 0; i--, j++) {
mp[a[i]]++;
if (mp[a[i]] == 2) break;
if (a[i] == mex) {
while (mp[mex] == 1) {
mex++;
}
}
if (j + 1 == mex - 1) suf[i] = 1;
}
for (int i = 0; i < n - 1; i++) {
int l = i, r = i + 1;
if (pref[l] && suf[r]) {
ans.push_back({i + 1, n - i - 1});
}
}
cout << ans.size() << endl;
for (auto it : ans) {
cout << it.first << " " << it.second << endl;
}
}
int main() {
int t = 1, cas = 0;
scanf("%d", &t);
while (t--) {
Solve(++cas);
}
return 0;
}
template <class T1, class T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p) {
os << "{" << p.first << ", " << p.second << "} ";
return os;
}
template <class T>
ostream &operator<<(ostream &os, vector<T> &v) {
os << "[ ";
for (int i = 0; i < v.size(); i++) {
os << v[i] << " ";
}
os << " ]";
return os;
}
template <class T>
ostream &operator<<(ostream &os, set<T> &v) {
os << "[ ";
for (T i : v) {
os << i << " ";
}
os << " ]";
return os;
}
|
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
multiset<long long> s;
multiset<long long> r;
long long a[n];
set<long long> store;
map<long long, long long> m;
for (long long i = 0; i < n; i++) {
long long x;
cin >> x;
a[i] = x;
s.insert(x);
m[x]++;
}
long long k = 0;
vector<pair<long long, long long>> ans;
for (long long i = 0; i < n - 1; i++) {
s.erase(s.find(a[i]));
r.insert(a[i]);
store.insert(a[i]);
m[a[i]]--;
if (m[a[i]] == 0) {
m.erase(a[i]);
}
if (s.size() + r.size() == n && *s.rbegin() == s.size() &&
*r.rbegin() == r.size() && store.size() == r.size() &&
m.size() == s.size()) {
ans.push_back({r.size(), s.size()});
}
}
cout << ans.size() << '\n';
for (long long i = 0; i < ans.size(); i++) {
cout << ans[i].first << " " << ans[i].second << '\n';
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n, i;
cin >> n;
long long int a[n + 2];
vector<pair<long long int, long long int> > ans;
set<long long int> sa, sb;
long long int c1[200005], c2[200005];
for (i = 0; i < n; i++) {
cin >> a[i];
c1[a[i]] = 0;
c2[a[i]] = 0;
}
sa.insert(-a[0]);
c1[a[0]]++;
for (i = 1; i < n; i++) {
sb.insert(-a[i]);
c2[a[i]]++;
}
long long int l1 = 1, l2 = n - 1;
while (l1 < n) {
long long int e1 = *sa.begin(), e2 = *sb.begin();
if (e1 == -l1 && e2 == -l2 && sa.size() == l1 && sb.size() == l2) {
ans.push_back({l1, l2});
}
sa.insert(-a[l1]);
c2[a[l1]]--;
if (c2[a[l1]] == 0) sb.erase(-a[l1]);
l1++;
l2--;
}
cout << ans.size() << "\n";
for (i = 0; i < ans.size(); i++)
cout << ans[i].first << " " << ans[i].second << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename t>
bool ckmin(t& a, const t& b) {
return a > b ? a = b, true : false;
}
template <typename t>
bool ckmax(t& a, const t& b) {
return a < b ? a = b, true : false;
}
bitset<200000> l, r, seen;
void solve() {
l.reset();
r.reset();
int n;
cin >> n;
vector<int> a(n);
for (auto((i)) = (0); ((i)) < ((n)); ++((i))) cin >> a[i];
seen.reset();
for (int i = 0, m = 0; i < n; ++i) {
ckmax(m, a[i]);
if (seen[a[i]]) break;
seen[a[i]] = true;
l[i] = i + 1 == m;
}
seen.reset();
for (int i = n - 1, m = 0; ~i; --i) {
ckmax(m, a[i]);
if (seen[a[i]]) break;
seen[a[i]] = true;
r[i] = n - i == m;
}
vector<pair<int, int> > res;
for (auto((i)) = (0); ((i)) < ((n - 1)); ++((i)))
if (l[i] && r[i + 1]) res.emplace_back(i + 1, n - i - 1);
cout << (res).size() << '\n';
for (auto [a, b] : res) cout << a << ' ' << b << '\n';
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int tc;
cin >> tc;
while (tc--) solve();
}
|
#include <bits/stdc++.h>
using namespace std;
bool f(long long a[], long long idx, long long n) {
map<long long, long long> mp, mp1;
vector<long long> v1, v2;
long long mx1 = INT_MIN, mx2 = INT_MIN;
for (long long i = 0; i < idx + 1; i++) {
if (mp[a[i]] > 0) return false;
mp[a[i]]++;
mx1 = max(mx1, a[i]);
}
for (long long i = idx + 1; i < n; i++) {
if (mp1[a[i]] > 0) return false;
mp1[a[i]]++;
mx2 = max(mx2, a[i]);
}
if (mx1 > idx + 1) return false;
if (mx2 > n - idx - 1) return false;
return true;
}
int main() {
long long t;
cin >> t;
while (t--) {
map<long long, long long> mp, mp1;
long long n;
cin >> n;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
vector<pair<long long, long long> > v;
long long cnt = 0;
long long te = 0;
for (long long i = 0; i < n; i++) {
if (mp[a[i]] == 0) {
mp[a[i]]++;
continue;
}
bool c = f(a, i - 1, n);
te = i;
if (c) cnt = cnt + 1, v.push_back({i, n - i});
break;
}
for (long long i = n - 1; i >= 0; i--) {
if (mp1[a[i]] == 0) {
mp1[a[i]]++;
continue;
}
bool c = f(a, i, n);
if (c && te != i + 1) cnt = cnt + 1, v.push_back({i + 1, n - i - 1});
break;
}
cout << cnt << endl;
if (cnt != 0) {
n = v.size();
for (long long i = 0; i < n; i++)
cout << v[i].first << " " << v[i].second << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[200010];
int main() {
int t;
cin >> t;
while (t--) {
int n, ans = 0, ma = 0;
queue<pair<int, int> > q;
while (!q.empty()) q.pop();
set<int> s1, s2;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
ma = max(a[i], ma);
}
int mi = 0;
for (int i = 0; i < n; i++) {
if (i < ma)
s1.insert(a[i]);
else
s2.insert(a[i]), mi = max(mi, a[i]);
}
if (s1.size() == ma && s2.size() == mi && mi + ma == n)
ans++, q.push({ma, mi});
mi = 0;
s1.clear(), s2.clear();
for (int i = 0; i < n; i++) {
if (i < n - ma)
s1.insert(a[i]), mi = max(mi, a[i]);
else
s2.insert(a[i]);
}
if (s1.size() == mi && s2.size() == ma && mi + ma == n && mi != ma)
ans++, q.push({mi, ma});
if (ans) {
cout << ans << '\n';
while (!q.empty()) {
cout << q.front().first << ' ' << q.front().second << '\n';
q.pop();
}
} else
cout << 0 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
char c = getchar();
int x = 0;
bool op = 0;
while (!isdigit(c)) op |= (c == '-'), c = getchar();
while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return op ? -x : x;
}
const int N = 200010;
int t, n;
int a[N], f[N], tot[N];
bool ans[N], vis[N];
void init() {
for (int i = 1; i <= n; i++) {
tot[i] = 1;
f[i] = i;
}
return;
}
int find(int x) {
if (f[x] == x) {
return x;
}
return f[x] = find(f[x]);
}
void unionn(int x, int y) {
int fx = find(x), fy = find(y);
if (fx != fy) {
f[fy] = fx;
tot[fx] += tot[fy];
}
return;
}
int main() {
t = read();
while (t--) {
memset(ans, false, sizeof(ans));
n = read();
for (int i = 1; i <= n; i++) {
a[i] = read();
}
bool flag = false;
init();
for (int i = 1; i <= n; i++) {
if (a[i] == 1)
flag = true;
else
unionn(a[i], a[i] - 1);
if (flag == true && tot[find(1)] == i) ans[i] = true;
}
init();
flag = false;
int cnt = 0;
for (int i = n; i >= 1; i--) {
if (a[i] == 1)
flag = true;
else
unionn(a[i], a[i] - 1);
if (flag == false || tot[find(1)] != n - i + 1) ans[i - 1] = false;
}
for (int i = 1; i <= n; i++) {
if (ans[i] == true) cnt++;
}
printf("%d\n", cnt);
for (int i = 1; i <= n; i++) {
if (ans[i] == true) {
printf("%d %d\n", i, n - i);
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class c>
struct rge {
c b, e;
};
template <class c>
rge<c> range(c i, c j) {
return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
template <class c>
debug& operator<<(const c&) {
return *this;
}
};
template <typename T>
void setmax(T& x, T y) {
x = max(x, y);
}
template <typename T>
void setmin(T& x, T y) {
x = min(x, y);
}
int main() {
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
vector<long long> a(n);
vector<long long> pref(n);
vector<long long> pref_mx(n);
vector<long long> pref_cnt(n);
vector<long long> suf(n);
vector<long long> suf_mx(n);
vector<long long> suf_cnt(n);
for (int i = 0; i < int(n); i++) cin >> a[i];
set<long long> cnt;
for (int i = 0; i < int(n); i++) {
if (i)
pref[i] = pref[i - 1] + a[i];
else
pref[i] = a[i];
if (i)
pref_mx[i] = max(pref_mx[i - 1], a[i]);
else
pref_mx[i] = a[i];
cnt.insert(a[i]);
pref_cnt[i] = (int)cnt.size();
}
reverse(a.begin(), a.end());
set<long long> cnt1;
for (int i = 0; i < int(n); i++) {
if (i)
suf[i] = suf[i - 1] + a[i];
else
suf[i] = a[i];
if (i)
suf_mx[i] = max(suf_mx[i - 1], a[i]);
else
suf_mx[i] = a[i];
cnt1.insert(a[i]);
suf_cnt[i] = (int)cnt1.size();
}
reverse(suf.begin(), suf.end());
reverse(suf_mx.begin(), suf_mx.end());
reverse(suf_cnt.begin(), suf_cnt.end());
vector<pair<int, int>> ans;
for (int i = 0; i < int(n - 1); i++) {
long long l1 = i + 1;
long long l2 = n - l1;
if (pref[i] == (l1 * (l1 + 1) / 2) and pref_mx[i] == l1 and
pref_cnt[i] == l1 and suf[i + 1] == (l2 * (l2 + 1) / 2) and
suf_mx[i + 1] == l2 and suf_cnt[i + 1] == l2) {
ans.push_back({l1, l2});
}
}
cout << (int)ans.size() << '\n';
if ((int)ans.size()) {
for (auto pp : ans) {
cout << pp.first << ' ' << pp.second << '\n';
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N], b[N], c[N];
int main() {
ios::sync_with_stdio(false);
int t;
scanf("%d", &t);
while (t--) {
int n;
vector<pair<int, int> > z;
scanf("%d", &n);
memset(b, 0, sizeof(b));
memset(c, 0, sizeof(c));
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
int l = n + 1, r = 0;
for (int i = 1; i <= n; i++) {
if (b[a[i]]) break;
l = min(l, a[i]);
r = max(r, a[i]);
if (l == 1 && r == i) c[i] = 1;
b[a[i]] = 1;
}
l = n + 1;
r = 0;
memset(b, 0, sizeof(b));
for (int i = n; i >= 1; i--) {
if (b[a[i]]) break;
l = min(l, a[i]);
r = max(r, a[i]);
if (l == 1 && r == n - i + 1 && c[i - 1]) z.push_back({i - 1, n - i + 1});
b[a[i]] = 1;
}
printf("%d\n", z.size());
for (int i = 0; i < z.size(); i++)
printf("%d %d\n", z[i].first, z[i].second);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[200199];
int b[200199];
int pan(int i, int j, int maxx) {
int k;
for (k = 1; k <= maxx + 1; k++) b[k] = 0;
for (k = i; k <= j; k++) {
if (a[k] <= maxx) b[a[k]]++;
if (a[k] > maxx || b[a[k]] == 2) return 0;
}
return 1;
}
int main() {
int i, t, n;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
int maxx = 0;
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] >= maxx) maxx = a[i];
}
if (n == 2 && maxx == 1)
printf("1\n1 1\n");
else if (maxx >= n)
printf("0\n");
else {
int num = 0, ans1 = 0, ans2 = 0;
if (pan(1, maxx, maxx)) {
if (pan(maxx + 1, n, n - maxx)) {
ans1 = maxx;
num++;
}
}
if (pan(1, n - maxx, n - maxx)) {
if (pan(n - maxx + 1, n, maxx)) {
ans2 = n - maxx;
if (ans1 != ans2) num++;
}
}
printf("%d\n", num);
if (ans1) printf("%d %d\n", ans1, n - ans1);
if (ans2 && ans1 != ans2) printf("%d %d\n", ans2, n - ans2);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long aa[11] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
const long long mod = 1e9 + 7;
int main() {
long long f, g, n, m, i, x, t, p, h, y, h3, j, d, k, l = 0;
cin >> t;
while (t--) {
cin >> n;
set<int> s;
map<long long, long long> mp;
vector<long long> v[n + 7];
d = 0;
long long a[n + 7], c[n + 7], b[n];
for (i = 0; i < n; i++) {
cin >> a[i];
b[i] = a[i];
if (a[i] > d) d = a[i];
}
k = 0;
h = 0;
sort(a, a + d);
for (i = 0, p = 1; i < d; i++, p++) {
if (a[i] != p) {
h++;
break;
}
}
sort(a + n - d, a + n);
for (i = n - d, p = 1; i < n; i++, p++) {
if (a[i] != p) {
h++;
break;
}
}
if (h == 0) k++;
h = 0;
y = 0;
sort(b + n - d, b + n);
for (i = n - d, p = 1; i < n; i++, p++) {
if (b[i] != p) {
h++;
break;
}
}
sort(b, b + n - d);
for (i = 0, p = 1; i < n - d; i++, p++) {
if (b[i] != p) {
h++;
break;
}
}
if (h == 0) y++;
if (2 * d >= n) {
if (k == 1 && y == 1) {
if (d == n - d)
cout << 1 << endl << d << " " << d << endl;
else {
cout << 2 << endl;
cout << d << " " << n - d << endl;
cout << n - d << " " << d << endl;
}
} else if (k == 1) {
cout << 1 << endl;
cout << d << " " << n - d << endl;
} else if (y == 1) {
cout << 1 << endl;
cout << n - d << " " << d << endl;
} else {
cout << 0 << endl;
}
} else
cout << 0 << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e16;
const double PI = acos(-1);
const long long N = 1e6 + 7;
long long mod = 1e9 + 7;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n, m, i, j, p, q, tests, t;
string s;
cin >> tests;
long long l, r, k, x, y;
while (tests--) {
cin >> n;
long long a[n];
for (i = 0; i < n; i++) cin >> a[i];
map<long long, long long> m1, m2;
long long l1, l2;
for (i = 0; i < n; i++) {
if (m1[a[i]]) {
l1 = i;
break;
}
++m1[a[i]];
}
for (i = n - 1; i >= 0; i--) {
if (m2[a[i]]) {
l2 = n - i - 1;
break;
}
++m2[a[i]];
}
if (l1 < l2) {
l1 = n - l2;
sort(a, a + l1);
for (i = 0; i < l1; i++) {
if (a[i] != i + 1) break;
}
sort(a + l1, a + n);
for (j = 0; j < l2; j++) {
if (a[j + l1] != j + 1) break;
}
if (i != l1 || j != l2) {
cout << "0\n";
continue;
}
cout << 1 << "\n";
cout << (n - l2) << " " << l2 << "\n";
} else if (l1 > l2) {
l2 = n - l1;
sort(a, a + l1);
for (i = 0; i < l1; i++) {
if (a[i] != i + 1) break;
}
sort(a + l1, a + n);
for (j = 0; j < l2; j++) {
if (a[j + l1] != j + 1) break;
}
if (i != l1 || j != l2) {
cout << "0\n";
continue;
}
cout << 1 << "\n";
cout << l1 << " " << (n - l1) << "\n";
} else if (l1 == n / 2 && n % 2 == 0) {
l1 = n - l2;
sort(a, a + l1);
for (i = 0; i < l1; i++) {
if (a[i] != i + 1) break;
}
sort(a + l1, a + n);
for (j = 0; j < l2; j++) {
if (a[j + l1] != j + 1) break;
}
if (i != l1 || j != l2) {
cout << "0\n";
continue;
}
cout << 1 << "\n";
cout << l1 << " " << l1 << "\n";
} else {
l1 = n - l2;
sort(a, a + l1);
for (i = 0; i < l1; i++) {
if (a[i] != i + 1) break;
}
sort(a + l1, a + n);
for (j = 0; j < l2; j++) {
if (a[j + l1] != j + 1) break;
}
if (i != l1 || j != l2) {
cout << "0\n";
continue;
}
cout << 2 << "\n";
cout << (n - l2) << " " << l2 << "\n";
cout << (l2) << " " << n - l2 << "\n";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long N = 500005;
const long long mod = 1e9 + 7;
void solve() {
long long x = 0, y = 0, c = 0, ans = 0;
long long n, m, k;
cin >> n;
set<long long> s, t;
vector<pair<long long, long long> > v;
vector<long long> cnt(n + 500);
long long a[n];
for (long long i = 0; i < n; ++i) {
cin >> a[i];
cnt[a[i]]++;
s.insert(a[i]);
}
for (long long i = 0; i < n - 1; ++i) {
t.insert(a[i]);
cnt[a[i]]--;
if (cnt[a[i]] == 0) s.erase(s.find(a[i]));
x = *(--s.end());
y = *(--t.end());
if (*s.begin() == 1 and *t.begin() == 1 and
x - *s.begin() + 1 == n - i - 1 and
n - i - 1 == (long long)(s.size()) and y - *t.begin() + 1 == i + 1 and
(long long)(t.size()) == i + 1) {
v.push_back({i + 1, n - i - 1});
}
}
cout << v.size() << "\n";
for (long long i = 0; i < v.size(); ++i) {
cout << v[i].first << " " << v[i].second << '\n';
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T;
cin >> T;
while (T--) solve();
return 0;
}
|
#include <bits/stdc++.h>
const int SIZE = 200000;
int p[SIZE];
int ans[SIZE][2];
int ans_cnt;
bool judge(int a[], int n) {
static int used[SIZE + 1];
for (int i = 1; i <= n; i++) used[i] = 0;
for (int i = 0; i < n; i++) used[a[i]] = 1;
for (int i = 1; i <= n; i++) {
if (!used[i]) return 0;
}
return 1;
}
bool judge(int len1, int n) {
return judge(p, len1) && judge(p + len1, n - len1);
}
int main() {
int t = 0;
scanf("%d", &t);
while (t--) {
ans_cnt = 0;
int n;
scanf("%d", &n);
int ma = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &p[i]);
if (ma < p[i]) ma = p[i];
}
if (judge(n - ma, n)) {
ans[ans_cnt][0] = n - ma;
ans[ans_cnt++][1] = ma;
}
if (ma * 2 != n && judge(ma, n)) {
ans[ans_cnt][0] = ma;
ans[ans_cnt++][1] = n - ma;
}
printf("%d\n", ans_cnt);
for (int i = 0; i < ans_cnt; i++) {
printf("%d %d\n", ans[i][0], ans[i][1]);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int t, n, a[N], pre[N], ed[N], cnt, ans[N][2], prema[N], edma[N], ma;
unordered_set<int> se;
int main() {
ios::sync_with_stdio(false);
cin >> t;
for (int i = 0; i < t; i++) {
cin >> n;
cnt = 0;
se.clear();
ma = 0;
for (int j = 1; j <= n; j++) {
cin >> a[j];
ma = max(ma, a[j]);
se.insert(a[j]);
pre[j] = se.size();
prema[j] = ma;
}
se.clear();
ma = 0;
for (int j = n; j >= 1; j--) {
ma = max(ma, a[j]);
se.insert(a[j]);
ed[j] = se.size();
edma[j] = ma;
}
for (int j = 1; j <= n - 1; j++)
if (pre[j] == prema[j] && ed[j + 1] == edma[j + 1] &&
pre[j] + ed[j + 1] == n)
ans[cnt][0] = j, ans[cnt][1] = n - j, cnt++;
cout << cnt << endl;
for (int j = 0; j < cnt; j++) {
cout << ans[j][0] << " " << ans[j][1] << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double PI = acos(-1);
const int knightDir[8][2] = {{-2, -1}, {-2, 1}, {-1, 2}, {1, 2},
{2, -1}, {2, 1}, {-1, -2}, {1, -2}};
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const long long MOD = 1000000000 + 7;
vector<int> arr;
int n, mx;
bool check(int l, int r) {
vector<int> c;
c.resize(mx + 5);
for (int i = 1; i <= l; i++) c[arr[i]]++;
for (int i = 1; i <= l; i++)
if (c[i] != 1) return false;
c.clear();
c.resize(mx + 5);
for (int i = l + 1; i <= n; i++) c[arr[i]]++;
for (int i = 1; i <= r; i++)
if (c[i] != 1) return false;
return true;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
cin >> n;
arr.resize(n + 10);
mx = 0;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
mx = max(mx, arr[i]);
}
bool chck1 = check(mx, n - mx);
bool chck2 = check(n - mx, mx);
if (chck1 && chck2 && mx != n - mx) {
cout << 2 << endl;
cout << n - mx << " " << mx << endl;
cout << mx << " " << n - mx << endl;
} else if (chck1) {
cout << 1 << endl;
cout << mx << " " << n - mx << endl;
} else if (chck2) {
cout << 1 << endl;
cout << n - mx << " " << mx << endl;
} else {
cout << 0 << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
bool check(vector<long long int> a, vector<bool> l, long long int len) {
for (long long int i = 0; i < len; i++) {
l[a[i]] = true;
}
for (long long int i = 1; i <= len; i++) {
if (!l[i]) {
return false;
}
}
return true;
}
bool check1(vector<long long int> a, vector<bool> l, long long int len) {
for (long long int i = 0; i < len; i++) {
l[a[a.size() - i - 1]] = true;
}
for (long long int i = 1; i <= len; i++) {
if (!l[i]) {
return false;
}
}
return true;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
vector<long long int> a(n);
vector<bool> l(n + 1, false);
long long int maxi = -1;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
maxi = max(a[i], maxi);
}
vector<pair<long long int, long long int> > ans;
if (check(a, l, maxi) && check1(a, l, n - maxi)) {
ans.push_back(make_pair(maxi, n - maxi));
}
if (2 * maxi != n && check(a, l, n - maxi) && check1(a, l, maxi)) {
ans.push_back(make_pair(n - maxi, maxi));
}
cout << ans.size() << '\n';
for (long long int i = 0; i < ans.size(); i++) {
cout << ans[i].first << " " << ans[i].second << '\n';
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 2e5 + 3;
long long arr[N];
int main() {
long long t, n, mx = INT_MIN, mn = INT_MAX, u, v, a, b, d, l = 0;
cin >> t;
int abcde = 0;
while (t--) {
cin >> n;
abcde++;
unordered_map<long long, long long> m1, m2, a1, a2;
for (long long i = 1; i <= n; i++) cin >> arr[i];
l = 1;
for (long long i = 1; i <= n; i++) {
m1[arr[i]]++;
while (m1[l] == 1) l++;
if (i == l - 1) {
a1[i] = l - 1;
}
}
l = 1;
for (long long i = n; i >= 1; i--) {
m2[arr[i]]++;
while (m2[l] == 1) l++;
if (n - i + 1 == l - 1) {
a2[i] = l - 1;
}
}
vector<pair<long long, long long> > ans;
for (auto x : a1) {
if (a2[x.first + 1]) ans.push_back({a1[x.first], a2[x.first + 1]});
}
cout << ans.size() << "\n";
sort(ans.begin(), ans.end());
for (auto p : ans) cout << p.first << " " << p.second << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
bool check(map<int, int> t1, int maxi) {
for (int i = 1; i <= maxi; i++) {
if (t1.count(i) == 0 || t1[i] == 0) {
return false;
}
}
return true;
}
void Permutations(int n, vector<int> a, int maxi) {
map<int, int> t1, t2;
map<pair<int, int>, int> ans;
int k = 0;
for (int i = 0; i < maxi; i++) {
t1[a[i]]++;
}
for (int i = maxi; i < n; i++) {
t2[a[i]]++;
}
if (check(t1, maxi) && check(t2, n - maxi)) {
k++;
ans[{maxi, n - maxi}]++;
}
maxi = n - maxi;
t1.clear();
t2.clear();
for (int i = 0; i < maxi; i++) {
t1[a[i]]++;
}
for (int i = maxi; i < n; i++) {
t2[a[i]]++;
}
if (check(t1, maxi) && check(t2, n - maxi)) {
ans[{maxi, n - maxi}]++;
}
k = ans.size();
cout << k << endl;
if (k > 0) {
for (auto it : ans) {
pair<int, int> temp = it.first;
cout << temp.first << " " << temp.second << endl;
}
}
}
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
int maxi = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > maxi) maxi = a[i];
}
Permutations(n, a, maxi);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 5;
int a[maxn], num[maxn], x[maxn], y[maxn];
int ans;
set<int> s1, s2;
int main() {
int t, n;
cin >> t;
while (t--) {
cin >> n;
ans = 0;
s1.clear();
s2.clear();
memset(num, 0, sizeof(num));
for (int i = 0; i < n; i++) {
cin >> a[i];
num[a[i]]++;
s2.insert(a[i]);
}
for (int i = 0; i < n; i++) {
s1.insert(a[i]);
num[a[i]]--;
if (num[a[i]] == 0) {
s2.erase(a[i]);
}
if (s1.size() == i + 1 && s2.size() == n - i - 1 && *s1.begin() == 1 &&
s1.size() != 0 && *(--s1.end()) == i + 1 && *s2.begin() == 1 &&
s2.size() != 0 && *(--s2.end()) == n - i - 1) {
x[ans] = i + 1;
y[ans++] = n - i - 1;
}
}
cout << ans << endl;
if (ans)
for (int i = 0; i < ans; i++) cout << x[i] << ' ' << y[i] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void IO() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
long long binary_exponention(long long a, long long b) {
if (b == 0) return 1;
long long res = binary_exponention(a, b / 2);
if (b % 2) return res * res * a;
return res * res;
}
void read(long long a[], int n, int which = 0) {
if (which == 0)
for (int i = 0; i < n; i++) cin >> a[i];
else
for (int i = 1; i <= n; i++) cin >> a[i];
}
void solve() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
vector<int> ans;
map<int, int> m;
set<int> second;
priority_queue<int> mx;
priority_queue<int, vector<int>, greater<int>> mn;
for (int i = 0; i < n - 1; i++) {
if (second.find(a[i]) != second.end()) break;
mn.push(a[i]);
mx.push(a[i]);
second.insert(a[i]);
if (mn.top() == 1 && mx.top() == i + 1) m[i] = 1;
}
second.clear();
mn = priority_queue<int, vector<int>, greater<int>>();
mx = priority_queue<int>();
for (int i = n - 1; i; i--) {
if (second.find(a[i]) != second.end()) break;
mn.push(a[i]);
second.insert(a[i]);
mx.push(a[i]);
if (mn.top() == 1 && mx.top() == n - i) {
if (m[i - 1]) ans.push_back(n - i);
}
}
cout << int(ans.size()) << "\n";
for (int i : ans) {
cout << n - i << " " << i << "\n";
}
}
int main() {
IO();
int t;
cin >> t;
while (t--) solve();
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, a[200000], cf[200000], l = 0, ans[2] = {0};
map<int, int> cnt;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
cf[i] = a[i];
cnt[a[i]]++;
}
for (int i = 1; i <= n; i++) {
if (cnt[i] < 2)
break;
else if (cnt[i] == 2)
l = i;
}
{
int flag = 0;
sort(a, a + l);
sort(a + l, a + n);
for (int i = 0; i < l; i++) {
if (a[i] != i + 1) {
flag = 1;
break;
}
}
for (int i = l; i < n; i++) {
if (a[i] != i + 1 - l) {
flag = 1;
break;
}
}
if (flag == 0) ans[0] = 1;
}
if (l != n - l) {
int flag = 0;
sort(cf, cf + n - l);
sort(cf + n - l, cf + n);
for (int i = 0; i < n - l; i++) {
if (cf[i] != i + 1) {
flag = 1;
break;
}
}
for (int i = n - l; i < n; i++) {
if (cf[i] != i + 1 - (n - l)) {
flag = 1;
break;
}
}
if (flag == 0) ans[1] = 1;
}
cout << ans[0] + ans[1] << "\n";
if (ans[0] == 1) cout << l << " " << n - l << "\n";
if (ans[1] == 1) cout << n - l << " " << l << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, i, j, k, f, f1, arr[200001], pt[200000];
cin >> t;
while (t--) {
cin >> n;
int temp[200000] = {0};
for (i = 0; i < n; i++) {
cin >> arr[i];
temp[arr[i]]++;
}
i = 1;
while (temp[i] == 2) i++;
if (temp[i] > 1)
cout << 0 << endl;
else {
i--;
j = n - i;
for (k = 1; k <= i; k++) pt[k] = 0;
k = 0;
f = 0;
while (k < i) {
pt[arr[k]]++;
k++;
}
for (k = 1; k <= i; k++) {
if (pt[k] != 1) {
f++;
break;
}
}
if (f == 0) {
for (k = 1; k <= j; k++) pt[k] = 0;
k = i;
while (k < n) {
pt[arr[k]]++;
k++;
}
for (k = 1; k <= j; k++) {
if (pt[k] != 1) {
f++;
break;
}
}
}
for (k = 1; k <= j; k++) pt[k] = 0;
k = 0;
f1 = 0;
while (k < j) {
pt[arr[k]]++;
k++;
}
for (k = 1; k <= j; k++) {
if (pt[k] != 1) {
f1++;
break;
}
}
if (f1 == 0) {
for (k = 1; k <= i; k++) pt[k] = 0;
k = j;
while (k < n) {
pt[arr[k]]++;
k++;
}
for (k = 1; k <= i; k++) {
if (pt[k] != 1) {
f1++;
break;
}
}
}
if (f1 == 0 && f == 0) {
if (i == j) {
cout << 1 << endl;
cout << i << " " << j << endl;
} else {
cout << 2 << endl;
cout << i << " " << j << endl;
cout << j << " " << i << endl;
}
} else if (f == 0) {
cout << 1 << endl;
cout << i << " " << j << endl;
} else if (f1 == 0) {
cout << 1 << endl;
cout << j << " " << i << endl;
} else
cout << 0 << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool check(int a[], int start, int end) {
int len = end - start;
vector<bool> used(len + 1, false);
for (int i = start; i < end; i++) {
if (a[i] > len || used[a[i]]) return false;
used[a[i]] = true;
}
}
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n];
int l2 = 0;
for (int i = 0; i < (n); ++i) {
cin >> a[i];
l2 = max(l2, a[i]);
}
int l1 = n - l2;
vector<pair<int, int>> ans;
if (check(a, 0, l1) && check(a, l1, n)) {
ans.push_back({l1, n - l1});
}
if (l1 != l2 && check(a, 0, l2) && check(a, l2, n)) {
ans.push_back({l2, n - l2});
}
cout << ans.size() << endl;
for (auto p : ans) {
cout << p.first << " " << p.second << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int sz = 100005;
const long long int szz = 1000006;
set<long long int> s1, s2;
long long int n;
bool check1(long long int ar[]) {
bool flag = true;
for (long long int i = 0; i < n; i++) {
if (s1.find(ar[i]) == s1.end() and flag) {
s1.insert(ar[i]);
} else {
flag = false;
s2.insert(ar[i]);
}
}
long long int ptr = 1;
for (auto x : s1) {
if (x != ptr) return false;
ptr++;
}
ptr = 1;
for (auto x : s2) {
if (x != ptr) return false;
ptr++;
}
return true;
}
bool check2(long long int ar[]) {
bool flag = true;
for (long long int i = n - 1; i >= 0; i--) {
if (s2.find(ar[i]) == s2.end() and flag) {
s2.insert(ar[i]);
} else
s1.insert(ar[i]), flag = false;
}
long long int ptr = 1;
for (auto x : s1) {
if (x != ptr) return false;
ptr++;
}
ptr = 1;
for (auto x : s2) {
if (x != ptr) return false;
ptr++;
}
return true;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int t;
cin >> t;
while (t--) {
cin >> n;
long long int ar[n];
s1.clear();
s2.clear();
for (long long int i = 0; i < n; i++) {
cin >> ar[i];
}
long long int sz11 = -1, sz12 = -1, sz21 = -1, sz22 = -1;
long long int ans = 0;
if (check1(ar) and
(long long int) s1.size() + (long long int)s2.size() == n) {
sz11 = s1.size();
sz12 = s2.size();
ans++;
}
s1.clear();
s2.clear();
if (check2(ar) and
(long long int) s1.size() + (long long int)s2.size() == n and
(long long int) s1.size() != sz11) {
sz21 = s1.size();
sz22 = s2.size();
ans++;
}
cout << ans << "\n";
if (ans != 0) {
if (sz11 != -1) {
cout << sz11 << " " << sz12 << "\n";
}
if (sz21 != -1) {
cout << sz21 << " " << sz22 << "\n";
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
long long mod = 1000000007;
const int MX = 0x3f3f3f3f;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n, i;
cin >> n;
int a[n];
for (i = 0; i <= n - 1; i++) cin >> a[i];
set<int> f, l;
long long sum = 0;
long long j = 0;
vector<int> l1(n), l2(n);
for (i = 0; i <= n - 2; i++) {
sum += a[i];
if (f.find(a[i]) != f.end()) break;
f.insert(a[i]);
j = f.size();
if (j * (j + 1) / 2 == sum) l1[i] = 1;
}
sum = 0;
for (i = n - 1; i >= 1; i--) {
sum += a[i];
if (l.find(a[i]) != l.end()) break;
l.insert(a[i]);
j = l.size();
if (j * (j + 1) / 2 == sum) l2[i] = 1;
}
int ans = 0;
vector<pair<int, int> > vp;
for (i = 0; i <= n - 2; i++) {
if (l1[i] && l2[i + 1])
ans++, vp.emplace_back(make_pair(i + 1, n - i - 1));
}
cout << ans << "\n";
for (i = 0; i <= int(vp.size()) - 1; i++)
cout << vp[i].first << " " << vp[i].second << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int t;
cin >> t;
while (t--) {
int n, maxn = 0;
bool repetido = 0, tem = 1;
cin >> n;
vector<int> funciona(n + 1, 0), ans;
vector<int> numeros(n + 1, 0), percorrido(n + 1, 0);
for (int i = 1; i <= n; i++) {
int aux;
cin >> aux;
if (numeros[aux] == 1) repetido = 1;
if (aux > maxn) maxn = aux;
numeros[aux]++;
if (maxn == i && repetido == 0) funciona[i] = 1;
if (numeros[aux] == 3) tem = 0;
}
int aux = 0;
int i = 1;
while (numeros[i] == 2) {
i++;
}
if ((n - i + 1) != maxn) {
tem = 0;
}
int j = i;
while (numeros[j] == 1) {
j++;
}
if (j != maxn + 1) tem = 0;
if (tem) {
if (funciona[i - 1]) ans.push_back(i - 1);
if (funciona[n - i + 1] && (n - i + 1) != (i - 1))
ans.push_back(n - i + 1);
}
cout << ans.size() << '\n';
for (int i = 0; i < ans.size(); i++) {
cout << ans[i] << ' ' << n - ans[i] << '\n';
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long tt;
cin >> tt;
while (tt--) {
long long n = 0, m = 0, k = 0, x = 0, y = 0, z = 0, i = 0, j = 0;
cin >> n;
long long a[n];
for (i = 0; i < n; i++) cin >> a[i];
vector<long long> v;
y = 0;
map<long long, long long> mp;
for (i = 0; i < n; i++) {
if (mp[a[i]]) break;
mp[a[i]]++;
}
x = i;
set<long long> s, s1;
for (i = 0; i < x; i++) s.insert(a[i]);
for (i = x; i < n; i++) s1.insert(a[i]);
set<long long>::iterator it, it1;
it = s.end();
it1 = s1.end();
it--;
it1--;
if (((*it) != s.size()) || ((*it1) != s1.size())) {
s.clear();
s1.clear();
} else if (s.size() + s1.size() != n) {
s.clear();
s1.clear();
} else {
y++;
v.push_back(s.size());
v.push_back(s1.size());
}
mp.clear();
s.clear();
s1.clear();
reverse(a, a + n);
for (i = 0; i < n; i++) {
if (mp[a[i]]) break;
mp[a[i]]++;
}
x = i;
for (i = 0; i < x; i++) s.insert(a[i]);
for (i = x; i < n; i++) s1.insert(a[i]);
it = s.end();
it1 = s1.end();
it--;
it1--;
if (((*it) != s.size()) || ((*it1) != s1.size())) {
s.clear();
s1.clear();
} else if (s.size() + s1.size() != n) {
s.clear();
s1.clear();
} else {
v.push_back(n - s.size());
v.push_back(n - s1.size());
}
if (v.size() == 4)
if (v[3 - 1] == v[1 - 1] && v[2 - 1] == v[4 - 1]) {
v.erase(v.end() - 1);
v.erase(v.end() - 1);
}
cout << v.size() / 2 << '\n';
for (i = 0; i < v.size(); i++) {
cout << v[i] << ' ';
if (i % 2) cout << '\n';
}
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
using ll = long long;
const bool dbg_flg = 1;
const int inf = 1e9 + 7;
const int MAXN = 2e5 + 5;
int n;
int a[MAXN];
bool check(int l1, int l2) {
if (l1 + l2 != n) return 0;
if (l1 <= 0 || l2 <= 0) return 0;
vector<int> v1, v2;
for (int i = 1; i <= l1; i++) {
v1.push_back(a[i]);
}
for (int i = l1 + 1; i <= l1 + l2; i++) {
v2.push_back(a[i]);
}
sort((v1).begin(), (v1).end());
sort((v2).begin(), (v2).end());
for (int i = 0; i < (int)(v1).size(); i++) {
if (i + 1 != v1[i]) return 0;
}
for (int i = 0; i < (int)(v2).size(); i++) {
if (i + 1 != v2[i]) return 0;
}
return 1;
}
void solve() {
cin >> n;
int mx = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
mx = max(mx, a[i]);
}
set<pair<int, int>> res;
if (check(mx, n - mx)) res.insert(make_pair(mx, n - mx));
if (check(n - mx, mx)) res.insert(make_pair(n - mx, mx));
cout << (int)(res).size() << '\n';
for (auto i : res) {
cout << i.first << ' ' << i.second << '\n';
}
}
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
int tt = 1;
cin >> tt;
while (tt--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MOD7 = 1000000000 + 7;
const int MOD9 = 1000000000 + 9;
int perm(int s, int e, vector<int>& a) {
int l = e - s;
map<int, int> m;
for (int i = (s); i < (e); i += (1)) {
m[a[i]] = 1;
}
for (int i = (1); i < (l + 1); i += (1)) {
if (!m[i]) {
return 0;
}
}
return 1;
}
void _main() {
int n = ({
int x;
scanf("%d", &x);
x;
});
vector<int> a(n);
for (int i = (0); i < (n); i += (1)) {
a[i] = ({
int x;
scanf("%d", &x);
x;
});
a[i]--;
}
vector<int> vis(n - 1);
map<int, int> m1, m2;
int r = -1;
for (int i = (0); i < (n); i += (1)) {
if (vis[a[i]]) {
break;
}
vis[a[i]] = 1;
r = max(r, a[i]);
if (r == i) {
m1[i + 1] = 1;
}
}
vis = vector<int>(n - 1);
r = -1;
for (int i = (n - 1); i >= (1); i--) {
if (vis[a[i]]) {
break;
}
vis[a[i]] = 1;
r = max(r, a[i]);
if (r == n - 1 - i) {
m2[n - i] = 1;
}
}
vector<pair<int, int> > ans;
for (auto e : m1) {
int l1 = e.first;
if (m2[n - l1]) {
ans.push_back(make_pair(l1, n - l1));
}
}
cout << ((int)ans.size()) << "\n";
for (auto p : ans) {
cout << p.first << " " << p.second << "\n";
}
}
int main() {
int t = ({
int x;
scanf("%d", &x);
x;
});
while (t--) {
_main();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int findperm(vector<int> &v) {
sort(v.begin(), v.end());
for (int i = 0; i < v.size(); ++i) {
if (v[i] != i + 1) return 0;
}
return *(v.end() - 1);
}
int main() {
int t;
cin >> t;
while (t--) {
int n, aux;
vector<int> v;
cin >> n;
while (n--) {
cin >> aux;
v.push_back(aux);
}
vector<pair<int, int>> ans;
auto it = max_element(v.begin(), v.end());
if (it != v.end()) {
int dmax = ((int)v.size()) - (*it);
if (dmax > 0) {
pair<int, int> pal;
auto itv = v.begin() + dmax;
vector<int> auxv{v.begin(), itv};
pal.first = findperm(auxv);
if (pal.first != 0) {
auxv = vector<int>(itv, v.end());
pal.second = findperm(auxv);
if (pal.second != 0) {
ans.push_back(pal);
}
}
auto itv2 = v.end() - dmax;
if (dmax != v.size() / 2 || v.size() % 2 != 0) {
auxv = vector<int>(v.begin(), itv2);
pal.first = findperm(auxv);
if (pal.first != 0) {
auxv = vector<int>(itv2, v.end());
pal.second = findperm(auxv);
if (pal.second != 0) {
ans.push_back(pal);
}
}
}
}
}
cout << ans.size() << "\n";
for (auto val : ans) {
cout << val.first << " " << val.second << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t, n, p, q, ans, x, y;
cin >> t;
while (t--) {
x = 0;
y = 0;
ans = 0;
p = 0;
cin >> n;
long long int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
if (p < a[i]) p = a[i];
}
int b[p + 1];
if (p < n)
q = n - p;
else
goto here2;
for (int i = 0; i <= p; i++) b[i] = 0;
for (int i = 0; i < p; i++) {
b[a[i]]++;
}
for (int i = 1; i <= p; i++) {
if (b[i] != 1) {
goto here1;
}
}
for (int i = 0; i <= q; i++) b[i] = 0;
for (int i = p; i < n; i++) b[a[i]]++;
for (int i = 1; i <= q; i++) {
if (b[i] != 1) {
goto here1;
}
}
ans++;
x = 1;
here1:
for (int i = 0; i <= q; i++) b[i] = 0;
for (int i = 0; i < q; i++) {
b[a[i]]++;
}
for (int i = 1; i <= q; i++) {
if (b[i] != 1) {
goto here2;
}
}
for (int i = 0; i <= p; i++) b[i] = 0;
for (int i = q; i < n; i++) b[a[i]]++;
for (int i = 1; i <= p; i++) {
if (b[i] != 1) {
goto here2;
}
}
y = 1;
ans++;
here2:
if (ans == 0)
cout << ans << endl;
else if (ans == 1) {
if (x == 1)
cout << ans << endl << p << " " << q << endl;
else
cout << ans << endl << q << " " << p << endl;
} else {
if (p == q)
cout << "1\n" << p << " " << q << endl;
else {
cout << ans << endl;
cout << p << " " << q << endl;
cout << q << " " << p << endl;
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
set<int> s;
int solve(vector<int> v, int k, int n) {
s.clear();
for (int i = 0; i < k; i++) s.insert(v[i]);
if (s.size() == k && *(s.begin()) == 1 && *(s.rbegin()) == k) {
s.clear();
for (int i = k; i < n; i++) s.insert(v[i]);
if (s.size() == n - k && *(s.begin()) == 1 && *(s.rbegin()) == (n - k))
return 1;
else
return -1;
} else
return -1;
}
int main() {
int t, n, m;
cin >> t;
vector<int> ans;
while (t--) {
cin >> n;
vector<int> a(n);
m = 0;
ans.clear();
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > m) m = a[i];
}
if (m > n - 1) {
cout << "0\n";
continue;
} else {
if (solve(a, m, n) != -1) ans.push_back(m);
if (solve(a, n - m, n) != -1 && m != n - m) ans.push_back(n - m);
cout << ans.size() << endl;
if (ans.size()) {
for (auto tl = ans.begin(); tl != ans.end(); tl++)
cout << *tl << " " << n - *tl << endl;
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
vector<int> inpVec(int n) {
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
return v;
}
void printVec(vector<int> v) {
for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
cout << endl;
}
int main() {
std::ios_base::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
auto v = inpVec(n);
unordered_map<int, bool> m1;
unordered_map<int, bool> m2;
vector<pair<int, int>> ans;
set<int> s;
for (int i = 0; i < n; i++) {
s.insert(v[i]);
if (*s.rbegin() == s.size() && s.size() == i + 1) {
m1[*s.rbegin()] = true;
}
}
s.clear();
reverse(v.begin(), v.end());
for (int i = 0; i < n; i++) {
s.insert(v[i]);
if (*s.rbegin() == s.size() && s.size() == i + 1) {
m2[*s.rbegin()] = true;
}
}
for (auto e : m1) {
if (m2.find(n - e.first) != m2.end()) {
ans.push_back(make_pair(e.first, n - e.first));
}
}
cout << ans.size() << endl;
for (auto e : ans) cout << e.first << " " << e.second << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
bool FLAG = 0;
using namespace std;
const long long MOD = (long long)1e9 + 7, N = (long long)2e6 + 222;
const long long INF = (long long)1e18;
long long dx[] = {0, -1, 0, 1, 0};
long long dy[] = {0, 0, 1, 0, -1};
long long n, used[N], a[N], x, mn[N], mx[N], mx1[N], mn1[N], pref[N];
inline void solve() {
cin >> n;
for (long long i = 1; i <= n; ++i) {
cin >> a[i];
}
for (long long i = n; i >= 1; --i) {
if (used[a[i]] == 0) {
pref[i] = pref[i + 1] + 1;
} else {
pref[i] = pref[i + 1];
}
used[a[i]] = 1;
}
mn1[n + 1] = mn[0] = INF;
mx1[n + 1] = mx[0] = -INF;
for (long long i = 1; i <= n; ++i) {
used[a[i]] = 0;
mn[i] = min(a[i], mn[i - 1]);
mx[i] = max(a[i], mx[i - 1]);
}
for (long long i = n; i >= 1; --i) {
mn1[i] = min(a[i], mn1[i + 1]);
mx1[i] = max(a[i], mx1[i + 1]);
}
vector<pair<long long, long long> > v;
set<long long> s;
for (long long i = 1; i <= n - 1; ++i) {
s.insert(a[i]);
if (mn[i] == 1 && mx[i] - mn[i] + 1 == i && (long long)(s.size()) == i) {
if (mn1[i + 1] == 1 && mx1[i + 1] - mn[i + 1] + 1 == n - i &&
n - i == pref[i + 1]) {
v.push_back({i, n - i});
}
}
}
for (long long i = 1; i <= n; ++i) pref[i] = 0;
cout << (long long)(v.size()) << endl;
for (long long i = 0; i < (long long)(v.size()); ++i)
cout << v[i].first << " " << v[i].second << endl;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, flg = 0, mx = 0;
cin >> n;
vector<int> vv;
map<int, int> mp;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
vv.push_back(a);
if (mx < a) mx = a;
mp[a]++;
if (mp[a] > 2) flg = 1;
}
int f1 = 0, f2 = 0, f3 = 0, f4 = 0;
int i;
for (i = 1; i <= mx; ++i) {
if (mp[i] != 2 && !f1) f1 = i - 1;
if (mp[i] != 2 && i == 1) f4 = 1;
if (!mp[i]) f2 = 1;
if (mp[i] == 2 && f1) f3 = 1;
}
if (flg || f2 || f3 || f4) {
cout << 0 << "\n";
continue;
}
vector<int> vl, vr;
if (f1 == 0) f1 = n / 2;
f2 = 0;
for (int i = 0; i < f1; ++i) {
vl.push_back(vv[i]);
}
sort(vl.begin(), vl.end());
for (int i = 0; i < f1; ++i) {
if (vl[i] != i + 1) {
f2 = 1;
break;
}
}
for (int i = n - 1; i >= f1; --i) {
vr.push_back(vv[i]);
}
sort(vr.begin(), vr.end());
for (int i = 0; i < n - f1; ++i) {
if (vr[i] != i + 1) {
f2 = 1;
break;
}
}
vl.clear();
vr.clear();
f3 = 0;
for (int i = 0; i < n - f1; ++i) {
vl.push_back(vv[i]);
}
sort(vl.begin(), vl.end());
for (int i = 0; i < n - f1; ++i) {
if (vl[i] != i + 1) {
f3 = 1;
break;
}
}
for (int i = n - 1; i >= n - f1; --i) {
vr.push_back(vv[i]);
}
sort(vr.begin(), vr.end());
for (int i = 0; i < f1; ++i) {
if (vr[i] != i + 1) {
f3 = 1;
break;
}
}
if (f1 == n / 2 && f2 == 0 && n % 2 == 0)
printf("1\n%d %d\n", n / 2, n / 2);
else {
int xx = 0;
if (!f2) xx++;
if (!f3) xx++;
cout << xx << endl;
if (!f2) printf("%d %d\n", f1, n - f1);
if (!f3) printf("%d %d\n", n - f1, f1);
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int a[N], p[N], l[N], r[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
int n, m, k, q, s, c, i, j;
cin >> n;
for (i = 1; i <= n; i++) cin >> a[i];
c = 1;
for (i = 1; i <= n; i++) {
p[a[i]] = 1;
while (p[c] == 1) c++;
if (c == i + 1) l[i] = i;
}
c = 1;
for (i = 1; i <= n; i++) p[a[i]] = 0;
for (i = n; i >= 1; i--) {
p[a[i]] = 1;
while (p[c] == 1) c++;
if (c == n - i + 2) r[i] = n - i + 1;
}
c = 0;
for (i = 1; i <= n; i++) {
if (l[i] > 0 && r[i + 1] > 0) c++;
}
cout << c << endl;
for (i = 1; i < n; i++) {
if (l[i] > 0 && r[i + 1] > 0) cout << l[i] << " " << r[i + 1] << endl;
}
for (i = 1; i <= n; i++) {
p[a[i]] = 0;
l[i] = r[i] = 0;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int arr[200001];
int num[200001];
int visit[200001];
int n;
int main() {
int t;
scanf("%d", &t);
for (; t--;) {
int n;
memset(visit, 0, sizeof(visit));
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
vector<int> a, b;
vector<int> ans1, ans2;
int _max = 0;
for (int i = 0; i < n; i++) {
if (visit[arr[i]] == 0) {
a.push_back(arr[i]);
visit[arr[i]] = 1;
_max = max(_max, arr[i]);
if (a.size() == _max) {
ans1.push_back(i);
}
} else {
if (_max >= arr[i]) {
break;
}
}
}
_max = 0;
memset(visit, 0, sizeof(visit));
for (int i = n - 1; i > -1; i--) {
if (visit[arr[i]] == 0) {
b.push_back(arr[i]);
visit[arr[i]] = 1;
_max = max(_max, arr[i]);
if (b.size() == _max) {
ans2.push_back(i);
}
} else {
if (_max >= arr[i]) {
break;
}
}
}
if (ans1.size() == 0 || ans2.size() == 0) {
printf("0\n");
continue;
}
sort(ans2.begin(), ans2.end());
vector<pair<int, int> > v;
int _s1 = ans1.size();
int _s2 = ans2.size();
for (int i = 0; i < _s1; i++) {
auto it = lower_bound(ans2.begin(), ans2.end(), ans1[i] + 1);
if (it != ans2.end() && *it == ans1[i] + 1) {
v.push_back({ans1[i] + 1, n - ans1[i] - 1});
}
}
printf("%d\n", v.size());
for (int i = 0; i < v.size(); i++) {
printf("%d %d\n", v[i].first, v[i].second);
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
map<int, int> mm;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
int n;
cin >> t;
while (t--) {
cin >> n;
int ar[n + 1];
int m = 0, k = 0;
for (int i = 0; i < n; i++) {
cin >> ar[i];
mm[ar[i]]++;
if (mm[ar[i]] >= k) {
if (k == mm[ar[i]]) {
if (ar[i] > m) m = ar[i];
} else
m = ar[i];
k = mm[ar[i]];
}
}
if (k > 2)
cout << "0" << endl;
else {
if (k == 1) {
cout << "1" << endl;
cout << n << " "
<< "0" << endl;
} else {
int fl = 1, fg = 1;
int cn = 1, cm = 1;
vector<int> v(ar, ar + m);
vector<int> v1(ar + m, ar + n);
sort(v.begin(), v.end());
sort(v1.begin(), v1.end());
for (int i = 0; i < v.size(); i++)
if (v[i] != i + 1) {
fl = 0;
cn--;
break;
}
if (fl) {
for (int i = 0; i < v1.size(); i++)
if (v1[i] != i + 1) {
fl = 0;
cn--;
break;
}
}
vector<int> v2(ar, ar + n - m);
vector<int> v3(ar + n - m, ar + n);
sort(v2.begin(), v2.end());
sort(v3.begin(), v3.end());
for (int i = 0; i < v2.size(); i++)
if (v2[i] != i + 1) {
fg = 0;
cm--;
break;
}
if (fg)
for (int i = 0; i < v3.size(); i++)
if (v3[i] != i + 1) {
fg = 0;
cm--;
break;
}
if (m == n - m && cn == 1 && cm == 1) {
cout << cn << endl;
cout << m << " " << n - m << endl;
} else {
cout << cn + cm << endl;
if (cn == 1) cout << m << " " << n - m << endl;
if (cm == 1) cout << n - m << " " << m << endl;
}
v.clear();
v1.clear();
v2.clear();
v3.clear();
}
}
mm.clear();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long t;
cin >> t;
for (t; t > 0; --t) {
long long n;
long long l1 = 0, l2 = 0;
cin >> n;
long long sum = 0;
long long uss = 0;
bool ch = false;
bool can = 1;
long long uss2 = 0;
long long sum2 = 0;
vector<long long> used(n + 1, 0);
vector<long long> vec(n);
for (long long i = 0; i < n; ++i) {
long long a;
cin >> a;
vec[i] = a;
if (!ch) {
if (!used[a]) {
++uss;
sum += a;
used[a]++;
} else {
l1 = i;
if ((l1 + 1) * l1 / 2 != sum) {
can = 0;
}
ch = 1;
++uss2;
sum2 += a;
used[a]++;
l2 = n - i;
}
} else {
++used[a];
if (used[a] >= 3) {
can = 0;
}
sum2 += a;
++uss2;
if ((used[a] && a > l1) || (!used[a] && a <= l1)) {
can = 0;
}
}
}
if ((l2 + 1) * l2 / 2 != sum2) {
can = 0;
}
bool can2 = 1;
ch = 0;
sum = 0;
sum2 = 0;
used = vector<long long>(n + 1, 0);
long long l12 = 0, l22 = 0;
for (long long i = n - 1; i >= 0 && can2; --i) {
long long a = vec[i];
if (!ch) {
if (!used[a]) {
++uss;
sum += a;
used[a]++;
} else {
l12 = n - i - 1;
if ((l12 + 1) * l12 / 2 != sum) {
can2 = 0;
}
ch = 1;
++uss2;
sum2 += a;
used[a]++;
l22 = i + 1;
}
} else {
used[a]++;
if (used[a] >= 3) {
can2 = 0;
}
sum2 += a;
++uss2;
if ((used[a] && a > l12) || (!used[a] && a <= l12)) {
can2 = 0;
}
}
}
if ((l22 + 1) * l22 / 2 != sum2) {
can2 = 0;
}
if (can && can2) {
if (l1 == l22) {
cout << "1 \n" << l1 << ' ' << l2 << '\n';
} else {
cout << "2 \n";
cout << l1 << ' ' << l2 << '\n' << l22 << ' ' << l12 << '\n';
}
} else {
cout << can + can2 << '\n';
if (can) {
cout << l1 << ' ' << l2 << '\n';
}
if (can2) {
cout << l22 << ' ' << l12 << '\n';
}
}
}
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.