#abc207c. C - Many Segments

C - Many Segments

Score : 300300 points

问题描述

给定NN个区间,编号为从1到NN,它们分别为:

  • 如果ti=1t_i=1,则第ii个区间为[li,ri][l_i,r_i]
  • 如果ti=2t_i=2,则第ii个区间为[li,ri)[l_i,r_i)
  • 如果ti=3t_i=3,则第ii个区间为(li,ri](l_i,r_i]
  • 如果ti=4t_i=4,则第ii个区间为(li,ri)(l_i,r_i)

请问有多少对整数(i,j)(i,j)满足1i<jN1 \leq i < j \leq N,使得第ii个区间和第jj个区间相交?

什么是[X,Y],[X,Y),(X,Y],(X,Y)[X,Y],[X,Y),(X,Y],(X,Y)

  • 闭区间[X,Y][X,Y]是一个包含所有实数xx的区间,满足XxYX \leq x \leq Y
  • 半开区间[X,Y)[X,Y)是一个包含所有实数xx的区间,满足Xx<YX \leq x < Y
  • 半开区间(X,Y](X,Y]是一个包含所有实数xx的区间,满足X<xYX < x \leq Y
  • 开区间(X,Y)(X,Y)是一个包含所有实数xx的区间,满足X<x<YX < x < Y

简单来说,方括号[]表示端点被包含在内,圆括号()表示端点被排除在外。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given NN intervals numbered 11 through NN, that are as follows:

  • if ti=1t_i=1, Interval ii is [li,ri][l_i,r_i];
  • if ti=2t_i=2, Interval ii is [li,ri)[l_i,r_i);
  • if ti=3t_i=3, Interval ii is (li,ri](l_i,r_i];
  • if ti=4t_i=4, Interval ii is (li,ri)(l_i,r_i).

How many pairs of integers (i,j)(i,j) satisfying 1i<jN1 \leq i \lt j \leq N are there such that Interval ii and Interval jj intersect?

What are [X,Y],[X,Y),(X,Y],(X,Y)[X,Y],[X,Y),(X,Y],(X,Y)?

  • A closed interval [X,Y][X,Y] is an interval consisting of all real numbers xx such that XxYX \leq x \leq Y.
  • A half-open interval [X,Y)[X,Y) is an interval consisting of all real numbers xx such that Xx<YX \leq x < Y.
  • A half-open interval (X,Y](X,Y] is an interval consisting of all real numbers xx such that X<xYX < x \leq Y.
  • A open interval (X,Y)(X,Y) is an interval consisting of all real numbers xx such that X<x<YX < x < Y.

Roughly speaking, square brackets [][] mean the endpoint is included, and curly brackets ()() mean the endpoint is excluded.

Constraints

  • 2N20002 \leq N \leq 2000
  • 1ti41 \leq t_i \leq 4
  • 1li<ri1091 \leq l_i \lt r_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

t1t_1 l1l_1 r1r_1

t2t_2 l2l_2 r2r_2

\hspace{1cm}\vdots

tNt_N lNl_N rNr_N

Output

Print the number of pairs of integers (i,j)(i,j) such that Interval ii and Interval jj intersect.

Sample Input 1

3
1 1 2
2 2 3
3 2 4

Sample Output 1

2

As defined in the Problem Statement, Interval 11 is [1,2][1,2], Interval 22 is [2,3)[2,3), and Interval 33 is (2,4](2,4].

There are two pairs of integers (i,j)(i,j) such that Interval ii and Interval jj intersect: (1,2)(1,2) and (2,3)(2,3). For the first pair, the intersection is [2,2][2,2], and for the second pair, the intersection is (2,3)(2,3).

Sample Input 2

19
4 210068409 221208102
4 16698200 910945203
4 76268400 259148323
4 370943597 566244098
1 428897569 509621647
4 250946752 823720939
1 642505376 868415584
2 619091266 868230936
2 306543999 654038915
4 486033777 715789416
1 527225177 583184546
2 885292456 900938599
3 264004185 486613484
2 345310564 818091848
1 152544274 521564293
4 13819154 555218434
3 507364086 545932412
4 797872271 935850549
2 415488246 685203817

Sample Output 2

102

update @ 2024/3/10 09:20:37