【31.42%】【CF 714A】Meeting of Old Friends
【题解】
求两个区间的交集。
很明显的线段树问题
(滑稽)
把两个区间的左端点的位置确定一下就好。
然后再看两个区间的右端点。
再判断k在不在交集中。
吧嗒吧嗒。。
【代码】
#include <cstdio> long long left1, right1, left2, right2, k,ans; void input_data() { scanf("%I64d%I64d%I64d%I64d%I64d", &left1, &right1, &left2, &right2, &k); } void get_ans() { if (left1 > left2) //固定两个区间的左端点为从左到右 { long long t = left1; left1 = left2; left2 = t; t = right1; right1 = right2; right2 = t; } if (right1 < left2) //这是没有交集的情况。 printf("0\n"); else if (right2 <= right1) { ans = right2 - left2 + 1; if (left2 <= k && k <= right2) ans--; printf("%I64d\n", ans); } else { ans = right1 - left2 + 1; if (left2 <= k && k <= right1) ans--; printf("%I64d\n", ans); } } int main() { //freopen("F:\\rush.txt", "r", stdin); input_data(); get_ans(); return 0; }