标签:operations d% Shuffle int contains CF li temp1 补题
You are given an array consisting of nn integers a1a1, a2a2, ..., anan. Initially ax=1ax=1, all other elements are equal to 00.
You have to perform mm operations. During the ii-th operation, you choose two indices cc and dd such that li≤c,d≤rili≤c,d≤ri, and swap acac and adad.
Calculate the number of indices kk such that it is possible to choose the operations so that ak=1ak=1 in the end.
Input
The first line contains a single integer tt (1≤t≤1001≤t≤100) — the number of test cases. Then the description of tt testcases follow.
The first line of each test case contains three integers nn, xx and mm (1≤n≤1091≤n≤109; 1≤m≤1001≤m≤100; 1≤x≤n1≤x≤n).
Each of next mm lines contains the descriptions of the operations; the ii-th line contains two integers lili and riri (1≤li≤ri≤n1≤li≤ri≤n).
Output
For each test case print one integer — the number of indices kk such that it is possible to choose the operations so that ak=1ak=1 in the end.
题目类型:没啥啊类型
解题目标:输出有多少个可能为1的点。
解题思路:不断扩充左边界与右边界,最后输出r-l+1.
AC代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
scanf("%d", &t);
while(t -- )
{
int n, m, x;
scanf("%d%d%d", &n, &x, &m);
int l = x, r= x;
int temp1, temp2;
rep(i, 1, m)
{
scanf("%d%d", &temp1, &temp2);
if( l>= temp1 && l<= temp2) l = temp1;
if( r>= temp1 && r<= temp2) r =temp2;
}
cout<<r-l+1<<endl;
}
return 0;
}
标签:operations,d%,Shuffle,int,contains,CF,li,temp1,补题 来源: https://blog.csdn.net/m0_54674275/article/details/121595498
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。