F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Just Another Data Structure Problem

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 33    Accepted Submission(s): 6


Problem Description
给定 $n, m$,以及序列 $a_1, a_2, \dots, a_n$ 和 $1, 2, \dots, n$ 的排列 $y_1, y_2, \dots, y_n$,你需要回答 $m$ 个询问。

对每个询问,给定 $l, r$,查询:

$\sum\limits_{i=1}^n\sum\limits_{j=i+1}^n [a_i=a_j]\cdot\prod_{k=i}^j [l\le y_k\le r]$

其中 $[\mathrm{cond}]$ 在条件 $\mathrm{cond}$ 为真时值为 $1$,否则值为 $0$。
 

Input
本题只有一组测试数据。

第一行包含两个数 $n, m(1\leq n\leq 10^5, 1\leq m\leq 10^6)$。

第二行包含 $n$ 个整数 $a_1, \dots, a_n (1 \leq a_i \leq n)$。

第三行包含 $n$ 个整数 $y_1, \dots, y_n(1 \leq y_i \leq n)$,保证 $y_i$ 互不相同。

接下来 $m$ 行,每行两个数 $l, r (1 \leq l \leq r \leq n)$ 表示一个询问。
 

Output
$m$ 行,每行一个整数,表示相应的答案。
 

Sample Input
3 4 1 1 3 2 3 1 1 2 1 3 2 3 1 1
 

Sample Output
0 1 1 0
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-20 14:57:32, Gzip enabled