-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1366B codeforces solution.cpp
64 lines (58 loc) · 1.37 KB
/
1366B codeforces solution.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
#include<iostream>
#include<ctype.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<queue>
#include<list>
#include<set>
#include<algorithm>
#include<string>
using namespace std;
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define ull unsigned long long
#define ll long long int
#define pb push_back
#define for0(i,n) for (i=0; i<n; i++)
#define for1(i,n) for (i=1; i<=n; i++)
#define forab(i,a,b)for (i=a; i<=b; i++)
#define rof0(i,n) for (i=n-1; i>=0; i--)
#define rof1(i,n) for (i=n; i>=1; i--)
const int MOD = 1000000007;
const int MAX = 1000005;
/*int SetBit (int n, int x) { return n | (1 << x); }
int ClearBit (int n, int x) { return n & ~(1 << x); }
int ToggleBit (int n, int x) { return n ^ (1 << x); }
bool CheckBit (int n, int x) { return (bool)(n & (1 << x)); }*/
int main()
{
fast;
int t;
//freopen("input.txt", "r",stdin);
cin>>t;
ll n;
while(t--)
{
ll n,x,m;
cin>>n>>x>>m;
ll l=x,r=x;
for(ll i=0;i<m;i++)
{
ll p,q;
cin>>p>>q;
if(q<l || p>r)
{
continue;
cout<<"con"<<endl;
}
else
{
l=min(l,p);
r=max(r,q);
}
}
cout<<r-l+1<<endl;
}
return 0;
}