-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathD.cpp
82 lines (77 loc) · 1.55 KB
/
D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n) for(i=0;i<n;i++)
#define fo2(i,start,end) for(i=start;i<=end;i++)
#define rfo(i,n) for(i=n-1;i>=0;i--)
#define ll long long int
#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define tr(it,a) for(auto it=a.begin(); it!=a.end();it++)
#define nl '\n'
#define PI 3.1415926535897932384626
#define mod 1000000007
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
void solve(){
int i,j;
int n,temp;
cin>>n;
int pres[2*n+1]={0},l,r,ans;
fo(i,n){
cin>>temp;
pres[temp]++;
}
vi a,b;
fo2(i,1,2*n){
if(pres[i]==1){
a.pb(i);
}
else{
b.pb(i);
}
}
i=0;j=0;
while(i<n && j<n){
if(a[i]<b[j]){
i++;
j++;
}
else{
j++;
}
}
r=i;
i=0;j=0;
while(i<n && j<n){
if(b[j]<a[i]){
j++;
i++;
}
else{
i++;
}
}
l=n-j;
ans=r-l+1;
cout<<ans<<nl;
}
int main(){
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t=1;
cin>>t;
while(t--){
solve();
}
}