CodeForces - 1463D. Pares
Título
El 2 n 2n2 n número, dividido ennnn correcto. DondexxEl par x realiza la operación pequeña y el número restante realiza la operación grande. Darte unannsecuencia de n elementosaaa . PreguntartexxCuántos tipos de números puede ser x , puede obteneraauna matriz.
Ideas
Pon el numero que ha aparecido en aaNúmeros que no han aparecido en la una matriz se colocan enbbb matriz
Deje RRR es el número máximo de veces que se puede tomar para encontrarRRR
Deje LLL es el número máximo de veces que se puede tomar para encontrarLLL luegon - L n-Lnorte-L es el número mínimo de veces que se puede tomar
Finalmente xxx rango esR - (n - L) + 1 R- (n-L) + 1R-( n-L )+1
Código
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define mod 1000000007
using namespace std;
inline int gcd(int a, int b) {
return b ? gcd(b, a % b) : a; }
typedef long long LL;
typedef pair<int, int>PII;
const int N = 400100;
int n;
bool st[N];
vector<int>a, b;
void solve() {
cin >> n;
a.clear();
b.clear();
memset(st, 0, sizeof st);
for (int i = 1; i <= n; ++i) {
int x; scanf("%d", &x);
st[x] = true;
}
for (int i = 1; i <= 2 * n; ++i) {
if (st[i])a.push_back(i);
else b.push_back(i);
}
int l = 0, r = n, L, R;
while (l < r) {
//求出
int mid = l + r + 1 >> 1;
bool flag = true;
for (int i = 0; i < mid; ++i) {
if (a[i] > b[n - mid + i]) {
flag = false;
}
}
if (flag)l = mid;
else r = mid - 1;
}
R = l;
l = 0, r = n;
while (l < r) {
int mid = l + r + 1 >> 1;
bool flag = true;
for (int i = 0; i < mid; ++i) {
if (a[n - mid + i] < b[i]) {
flag = false;
}
}
if (flag)l = mid;
else r = mid - 1;
}
L = l;
cout << R - n + L + 1 << endl;
}
int main() {
int t; cin >> t;
while (t--)
solve();
return 0;
}