SGU,sguonline

來源:互聯網
上載者:User

SGU,sguonline

Description



You've recently started an ice-cream business in a local school. During a day you have many suppliers delivering the ice-cream for you, and many students buying it from you. You are not allowed to set the prices, as you are told the price for each piece of ice-cream by the suppliers. 

The day is described with a sequence of queries. Each query can be either 
ARRIVE nc
, meaning that a supplier has delivered  n pieces of ice-cream priced  c each to you, or 
BUY nt
, meaning that a student wants to buy  n pieces of ice-cream, having a total of  t money. The latter is processed as follows: in case  n cheapest pieces of ice-cream you have cost no more than  t (together), you sell those  n cheapest pieces to the student; in case they cost more, she gets nothing. You start the day with no ice-cream. 

For each student, output 
HAPPY
 if she gets her ice-cream, and 
UNHAPPY
if she doesn't.

Input

The input file contains between 1 and 10 5 queries (inclusive), each on a separate line. The queries are formatted as described above, either 
ARRIVE nc
 or 
BUY nt
, 1 ≤  nc ≤ 10 6, 1 ≤  t ≤ 10 12.

Output

For each 
BUY
-query output one line, containing either the word 
HAPPY
 or the word 
UNHAPPY
 (answers should be in the same order as the corresponding queries).

Sample Input

sample input
sample output
ARRIVE 1 1ARRIVE 10 200BUY 5 900BUY 5 900BUY 5 1000
HAPPYUNHAPPYHAPPY


題意:一個商店,有兩種操作:(1)ARRIVE n c表示進貨n個,每個c元。(2)BUY n t表示一個買貨的人要買n個,一共拿了t元錢。如果現在店裡的貨的數量大於等於n且最便宜的n個的價格小於等於t則將最便宜的賣給他。否則不賣。

思路:離線的線段樹,我們以價格作為結點,然後離散化,好久沒做,看了final爺kuangbing的題解,注意的是優先處理最小的n個

#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <queue>#define lson(x) (x<<1)#define rson(x) ((x<<1)|1)typedef long long ll;using namespace std;const int maxn = 100010;struct Node {int l, r;ll num;ll sum;int flag;} segTree[maxn<<2];int x[maxn];void pushdown(int x) {if (segTree[x].l == segTree[x].r) return;if (segTree[x].flag != -1) {segTree[lson(x)].sum = segTree[rson(x)].sum = 0;segTree[lson(x)].num = segTree[rson(x)].num = 0;segTree[lson(x)].flag = segTree[rson(x)].flag = 0;segTree[x].flag = -1;}}void pushup(int x) {if (segTree[x].l == segTree[x].r) return;segTree[x].sum = segTree[lson(x)].sum + segTree[rson(x)].sum;segTree[x].num = segTree[lson(x)].num + segTree[rson(x)].num;}void build(int x, int l, int r) {segTree[x].r = r;segTree[x].l = l;segTree[x].sum = segTree[x].num = 0;segTree[x].flag = -1;if (l == r) return;int mid = l + r >> 1;build(lson(x), l, mid);build(rson(x), mid+1, r);}void Add(int i, int c, int n) {segTree[i].sum += (ll) c * n;segTree[i].num += n;if (x[segTree[i].l] == c && x[segTree[i].r] == c)return;pushdown(i);if (c <= x[segTree[lson(i)].r]) Add(lson(i), c, n);else Add(rson(i), c, n);}ll query(int i, int n) {if (segTree[i].l == segTree[i].r) {return (ll) n * x[segTree[i].l];}pushdown(i);if (segTree[lson(i)].num >= n) return query(lson(i), n);else return segTree[lson(i)].sum + query(rson(i), n-segTree[lson(i)].num);}void clear(int i, int n) {if (segTree[i].l == segTree[i].r) {segTree[i].num -= n;segTree[i].sum = segTree[i].num * x[segTree[i].l];return;}pushdown(i);if (segTree[lson(i)].num >= n)clear(lson(i), n);else {clear(rson(i), n-segTree[lson(i)].num);segTree[lson(i)].num = segTree[lson(i)].sum = 0;segTree[lson(i)].flag = 0;}pushup(i);}struct Query {char op[10];int n;ll c;} q[maxn];int main() {int n = 0;int tot = 0;while (scanf("%s%d%lld", q[n].op, &q[n].n, &q[n].c) != EOF) {if (q[n].op[0] == 'A')x[tot++] = q[n].c;n++;}sort(x, x+tot);tot = unique(x, x+tot) - x;build(1, 0, tot-1);for (int i = 0; i < n; i++) {if (q[i].op[0] == 'A')Add(1, q[i].c, q[i].n);else {if (segTree[1].num < q[i].n) printf("UNHAPPY\n");else {if (query(1, q[i].n) > q[i].c)printf("UNHAPPY\n");else {printf("HAPPY\n");clear(1, q[i].n);}}}}return 0;}



sgu是什?

Stargate Universe明年2月4號正式開拍
還是在前2部劇的拍攝地加拿大溫哥華的Bridge Studios片場進行拍攝
由SG劇2大創始人Brad Wright和Robert C. Cooper執筆SGU開篇2小時的pilot集
目前還未知此劇主演,pilot集標題和由誰來導演
預計明年夏季於SCIFI台播出

有傳言說SG1或SGA中的一位熟人將會成為第3系列的主角之一
SCIFI說新劇將會吸引更多年輕觀眾來收看,也就是意味著新劇將會有更多年輕人喜愛的元素在裡面
而且新劇中大多數演員也比前2部要來得年輕

更新了點劇情概要:
 
星際之門SG1SGA與SGU有什不同?

是星際之門的三部曲 1994年星際之門電影后開始了漫長的十季SG1 講述SG1這小強四人組利用星門在銀河系的探險 結識了Asgard小灰人 與寄生在人身體裡的蟲子抗爭 還有複製者的戰爭 尋找Ancient(亞特蘭蒂斯的締造者)的先進武器等故事 SGA是SG1的衍生劇 SGA是STAR GATE ATLANTIS的縮寫 是在另個星系的故事 主要講述以亞特蘭蒂斯城為基地 與幽靈這種生物戰鬥的故事 是SG1集的支線 SGU則是另則故事 是STAR GATE UNIVERSE 的縮寫 是一群人被困在ANCIENT建造的船裡穿梭在宇宙裡不能回家的故事 由於米高梅破產 出了二季就宣告星際之門全部結束了 淚奔啊~ 個人覺得SG1和SGA好看 灰常好看
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.