Kuriyama Mirai's Stones

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?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; ?

} ?

```

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末铭乾,一起剝皮案震驚了整個(gè)濱河市强饮,隨后出現(xiàn)的幾起案子胎撇,更是在濱河造成了極大的恐慌钾恢,老刑警劉巖葫辐,帶你破解...
    沈念sama閱讀 222,183評(píng)論 6 516
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異铅鲤,居然都是意外死亡蕉朵,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,850評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門关顷,熙熙樓的掌柜王于貴愁眉苦臉地迎上來糊秆,“玉大人,你說我怎么就攤上這事议双《环” “怎么了?”我有些...
    開封第一講書人閱讀 168,766評(píng)論 0 361
  • 文/不壞的土叔 我叫張陵平痰,是天一觀的道長夫偶。 經(jīng)常有香客問我界睁,道長,這世上最難降的妖魔是什么兵拢? 我笑而不...
    開封第一講書人閱讀 59,854評(píng)論 1 299
  • 正文 為了忘掉前任翻斟,我火速辦了婚禮,結(jié)果婚禮上说铃,老公的妹妹穿的比我還像新娘访惜。我一直安慰自己,他們只是感情好腻扇,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,871評(píng)論 6 398
  • 文/花漫 我一把揭開白布债热。 她就那樣靜靜地躺著,像睡著了一般幼苛。 火紅的嫁衣襯著肌膚如雪窒篱。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,457評(píng)論 1 311
  • 那天舶沿,我揣著相機(jī)與錄音墙杯,去河邊找鬼。 笑死括荡,一個(gè)胖子當(dāng)著我的面吹牛高镐,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播畸冲,決...
    沈念sama閱讀 40,999評(píng)論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼嫉髓,長吁一口氣:“原來是場噩夢(mèng)啊……” “哼!你這毒婦竟也來了邑闲?” 一聲冷哼從身側(cè)響起算行,我...
    開封第一講書人閱讀 39,914評(píng)論 0 277
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎苫耸,沒想到半個(gè)月后纱意,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,465評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡鲸阔,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,543評(píng)論 3 342
  • 正文 我和宋清朗相戀三年偷霉,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片褐筛。...
    茶點(diǎn)故事閱讀 40,675評(píng)論 1 353
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡类少,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出渔扎,到底是詐尸還是另有隱情硫狞,我是刑警寧澤,帶...
    沈念sama閱讀 36,354評(píng)論 5 351
  • 正文 年R本政府宣布,位于F島的核電站残吩,受9級(jí)特大地震影響财忽,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜泣侮,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,029評(píng)論 3 335
  • 文/蒙蒙 一即彪、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧活尊,春花似錦隶校、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,514評(píng)論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至铜犬,卻和暖如春舞终,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背癣猾。 一陣腳步聲響...
    開封第一講書人閱讀 33,616評(píng)論 1 274
  • 我被黑心中介騙來泰國打工敛劝, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人煎谍。 一個(gè)月前我還...
    沈念sama閱讀 49,091評(píng)論 3 378
  • 正文 我出身青樓攘蔽,卻偏偏與公主長得像龙屉,于是被迫代替她去往敵國和親呐粘。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,685評(píng)論 2 360

推薦閱讀更多精彩內(nèi)容