QOJ.ac

QOJ

حد الوقت: 4.0 s حد الذاكرة: 1024 MB مجموع النقاط: 100 الصعوبة: [عرض]

#12012. Yosupo's Algorithm

الإحصائيات

你能在 5 小时内复刻我的硕士论文吗?

在二维平面上有 $N$ 个红点和 $N$ 个蓝点。第 $i$ 个红点的坐标为 $(r^x_i, r^y_i)$,权重为 $r^w_i$。第 $i$ 个蓝点的坐标为 $(b^x_i, b^y_i)$,权重为 $b^w_i$。

处理 $Q$ 个查询。在第 $i$ 个查询中,给定两个整数 $L_i$ 和 $R_i$,你需要选择一个红点 $j$ 和一个蓝点 $k$,需满足以下条件:

  • $r^y_j < b^y_k$
  • $(r^x_j < L_i \text{ 且 } R_i < b^x_k)$ 或 $(L_i < r^x_j \text{ 且 } b^x_k < R_i)$

你的任务是最大化这两个点的权重之和,如果无法选择出满足条件的两个点,则输出 $-1$。

输入格式

输入通过标准输入按以下格式给出:

$N$ $r^x_1 \ r^y_1 \ r^w_1$ $\vdots$ $r^x_N \ r^y_N \ r^w_N$ $b^x_1 \ b^y_1 \ b^w_1$ $\vdots$ $b^x_N \ b^y_N \ b^w_N$ $Q$ $L_1 \ R_1$ $\vdots$ $L_Q \ R_Q$

数据范围

  • $1 \le N \le 100,000$
  • $1 \le Q \le 500,000$
  • $-1,000,000,000 \le r^x_i, L_i \le -1$
  • $1 \le b^x_i, R_i \le 1,000,000,000$
  • $1 \le r^y_i, b^y_i \le 1,000,000,000$
  • $1 \le r^w_i, b^w_i \le 1,000,000,000$
  • $r^x_1, \dots, r^x_N, b^x_1, \dots, b^x_N, L_1, \dots, L_Q, R_1, \dots, R_Q$ 互不相同
  • $r^y_1, \dots, r^y_N, b^y_1, \dots, b^y_N$ 互不相同
  • 输入中的所有值均为整数。

输出格式

对于每个查询,输出一行,表示所选点的最大权重之和;如果无法选择两个点,则输出 $-1$。

样例

输入 1

2
-3 1 1
-6 3 10
3 4 100
5 2 1000
5
-5 4
-2 6
-4 1
-10 10
-1 2

输出 1

101
-1
110
1001
1001

输入 2

10
-389 786 414303478
-159 301 976196121
-268 599 754785437
-605 652 597104844
-199 841 214521748
-192 8 581825989
-515 898 509582353
-297 36 854072992
-489 616 41481895
-665 876 378086770
869 583 376652629
509 222 380009514
354 693 428231281
519 738 608396032
100 811 220629740
960 708 928349711
324 89 710139852
716 897 771429659
647 203 72269757
368 699 540753047
10
-350 499
-956 639
-287 504
-915 742
-777 135
-176 487
-150 987
-133 10
-852 147
-476 106

输出 2

1564212844
1584592153
1782422703
1747625780
1196825861
1782422703
-1
1904545832
1196825861
1525454555

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1865EditorialOpen其实是一个log的incent2026-06-03 16:19:31View

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.