1 A, get a good question for practiced hand.
Use a priority queue to cook the time from small to large order, cooked to play out.
Using n vectors to maintain the cooked time of each food is clearly orderly.
Maintain the quantity of each cooked food in a tree-like array.
The priority queue is cooked before each operation <= the current time of the popup, bit on the +1.
Each 0 operation puts food into priority queue and vector
Each time 1 operation first look at the tree array there is no number, no output angry, some words in the tree array to find the smallest number of two points.
Each time 2 operation first look at the tree array there is no such a number, some words output and-1, no word to see if vector, some words output time difference, no words output angry.
No, the writing is flowing smoothly.
#include <iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<queue>#include<vector>#definell Long Longusing namespacestd;Const intmaxn=500010;structpoi{intPos, Tim;}; Priority_queue<poi>Q;BOOL operator< (poi A, poi b) {returnA.tim>B.tim;}intN, Q, mx, t, Ty, X, L, R, T;inttree[1<< -], FIR[MAXN], S[maxn];vector<int>V[maxn];inlinevoidReadint&k) { intf=1; k=0;CharC=GetChar (); while(c<'0'|| C>'9') c=='-'&& (f=-1), c=GetChar (); while(c<='9'&& c>='0') k=k*Ten+c-'0', c=GetChar (); K*=F;} InlinevoidAddintXintDelta) { for(; x<=mx;x+=x&-x) tree[x]+=Delta;} InlineintQueryintx) {intsum=0; for(; x;x-=x&-x) sum+=tree[x];returnsum;} InlinevoidYazid () {if(!TREE[MX]) {Puts ("Yazid is angry.");return;} intL=0, R=MX, k=1; while(l<r) {intMid= (l+r) >>1; if(tree[mid]>=k) r=mid; ElseK-=tree[mid], l=mid+1; } Add (L,-1); printf"%d\n", L); return;} InlinevoidYjqqaq (intTintID) { if(Query (ID)-query (id-1) {puts ("succeeded!"); Add (ID,-1);return;} if(V[id].size () ==fir[id]) {Puts ("Yjqqqaq is angry.");return;} printf ("%d\n", v[id][fir[id]]-t);return;} InlinevoidClear () {memset (tree,0, (mx+1) <<2); memset (Fir,0, (n+1) <<2); while(!q.empty ()) Q.pop (); for(intI=1; i<=n;i++) V[i].clear ();}intMain () {read (T); while(t--) {read (n); MX=1; while(mx<=n) mx<<=1; clear (); for(intI=1; i<=n;i++) read (s[i]); Read (Q); for(intI=1; i<=q;i++) {read (t); read (Ty); while(!Q.empty ()) {POI now=Q.top (); if(now.tim<=t) Q.pop (), Add (Now.pos,1), fir[now.pos]++; Else Break; } if(!ty) Read (x), Q.push ((POI) {x, t+s[x]}), V[x].push_back (t+s[x]); Else if(ty==1) Yazid (); Else if(ty==2) Read (x), Yjqqaq (t, x); ElseRead (l), read (R), printf ("%d\n", query (R)-query (l1)); } }}
View Code
"codeplus 2017 December" Hot Pot Feast "(Analog + Tree array)