美文网首页
Kuriyama Mirai's Stones

Kuriyama Mirai's Stones

作者: 河里的咸鱼 | 来源:发表于2017-01-15 13:15 被阅读0次

                                             Kuriyama Mirai's Stones

Kuriyama Mirai has killed many monsters and got many (namelyn) stones. She numbers the stones from1ton. The cost of thei-th stone isvi. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions:

She will tell you two numbers,landr(1 ≤lrn), and you should tell her

.

Letuibe the cost of thei-th cheapest stone (the cost that will be on thei-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers,landr(1 ≤lrn), and you should tell her

.

For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy.

Input

The first line contains an integern(1 ≤n≤ 105). The second line containsnintegers:v1,v2, ...,vn(1 ≤vi≤ 109)— costs of the stones.

The third line contains an integerm(1 ≤m≤ 105)— the number of Kuriyama Mirai's questions. Then followmlines, each line contains three integerstype,landr(1 ≤lrn; 1 ≤type≤ 2), describing a question. Iftypeequal to1, then you should output the answer for the first question, else you should output the answer for the second one.

Output

Printmlines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.

Example

Input

6

6 4 2 7 2 7

3

2 3 6

1 3 4

1 1 6

Output

24

9

28

Input

4

5 5 2 3

10

1 2 4

2 1 4

1 1 1

2 1 4

2 1 2

1 1 1

1 3 3

1 1 3

1 4 4

1 2 2

Output

10

15

5

15

5

5

2

12

3

5

```

#include<cstdio>

#include<iostream> 

#include<algorithm>

using namespace std;  

int n;

long long int a[100010],b[100010],c[100010]; 

int main()  

{  

    int m,o,p,q,i;    

    scanf("%d",&n);  

    for( i=0; i<n; i++)  

    {  

        scanf("%lld",&a[i]);  

        b[i+1] = a[i] + b[i];  

    }  

    sort(a,a+n);  

    for( i=0; i<n; i++)  

    {  

        c[i+1] = a[i] + c[i];  

    }  

    scanf("%d",&m);  

    while(m--)  

    {  

        scanf("%d%d%d",&o,&p,&q);  

        if(o==1)  

        {  

            printf("%lld\n",b[q]-b[p-1]);  

        }  

        else  

        {  

            printf("%lld\n",c[q]-c[p-1]);  

        }  

    }  

    return 0;  

}  

```

相关文章

  • Kuriyama Mirai's Stones

    Kuriyama Mirai's Stones Kuriyama Mi...

  • E - Kuriyama Mirai's Stones

    这道题的题意大概是,输入一串数字,没排序之前编号为1,从小到大排完序编号为2.然后再输入编号,计算从第l个数字到第...

  • Mirai源码解析

    Mirai概述 mirai,2016年一个备受关注的DDoS攻击程序,与传统的僵尸网络不同的是,mirai的控制的...

  • ACM(three)

    Stones on the Table There are n stones on the table in a ...

  • STONE

    Stones on the Table There are n stones on the table in a ...

  • 《One second every day》

    https://ted2srt.org/talks/cesar_kuriyama_one_second_every...

  • 「Stones」

    今天是笔者的生日。祝自己生日快乐~ 找了很多首歌,还是这一首最合适,那么就再听一遍吧。 2015年1月动画《旋转少...

  • 灵海拾珠7

    Renunciation is the stepping stones to the spiritual path...

  • LeetCode 1033. Moving Stones Unt

    DescriptionThree stones are on a number line at positions...

  • [The Rolling Stones]Paint It Bla

    分享The Rolling Stones的单曲《Paint It Black 》

网友评论

      本文标题:Kuriyama Mirai's Stones

      本文链接:https://www.haomeiwen.com/subject/wtiybttx.html