Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author: Mirza Mohammad Azwad
- Islamic University of Technology(IUT)
- If you're looking at my code, enjoy :)
- */
- /// Header files, namespaces defined here
- #include<bits/stdc++.h>
- using namespace std;
- //#include <ext/pb_ds/assoc_container.hpp>
- //#include <ext/pb_ds/tree_policy.hpp>
- //using namespace __gnu_pbds;
- ///Custom macros used throughout the code defined here
- #define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);
- #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
- #define EL printf("\n")
- #define el '\n'
- #define OK printf("OK")
- #define pb push_back
- #define mp make_pair
- #define ep emplace_back
- #define X first
- #define Y second
- #define fillchar(a,x) memset(a, x, sizeof(a))
- #define OK printf("OK")
- #define pf push_front
- #define X first
- #define Y second
- #define int64 long long int
- #define fillchar(a,x) memset(a, x, sizeof(a))
- #define FOR(i,l,r) for (int i=l;i<=r;i++)
- #define FORD(i,r,l) for (int i=r;i>=l;i--)
- #define FORx(i,l,r,x) for (int i=l;i<=r;i+=x)
- #define FORDx(i,r,l,x) for (int i=r;i>=l;i-=x)
- ///Custom macro definition ends here
- ///Some type definitions
- //typedef int64_t ll; ///Use this for int64_t
- //typedef long long ll;
- //typedef pair<ll,ll> lll;
- //typedef pair<ll,int> lli;
- //typedef pair<int,int> ii;
- //using int128 = signed __int128;
- //using uint128 = unsigned __int128;
- ///Some type definitions ends here
- ///BIG INT START
- //const int base = 1e9;
- //typedef vector<int> BigInt;
- //
- //void Set(BigInt &a) {
- // while (a.size() > 1 && a.back() == 0) a.pop_back();
- //}
- //
- //void Print(BigInt a) {
- // Set(a);
- // printf("%d", (a.size() == 0) ? 0 : a.back());
- // FORD(i,a.size()-2,0) printf("%09d", a[i]); EL;
- //}
- //
- //
- //
- //BigInt Integer(string s) {
- // BigInt ans;
- // if (s[0] == '-') return ans;
- // if (s.size() == 0) {ans.pb(0); return ans;}
- // while (s.size()%9 != 0) s = '0'+s;
- // for (int i=0;i<s.size();i+=9) {
- // int v = 0;
- // for (int j=i;j<i+9;j++) v = v*10+(s[j]-'0');
- // ans.insert(ans.begin(),v);
- // }
- // Set(ans);
- // return ans;
- //}
- //
- //BigInt Integer(char c[]) {
- // string s = "";
- // FOR(i,0,strlen(c)-1) s = s + c[i];
- // return Integer(s);
- //}
- //
- //BigInt Integer(ll x) {
- // string s = "";
- // while (x > 0) s = char(x%10+'0') + s, x /= 10;
- // return Integer(s);
- //}
- //
- //BigInt Integer(int x) {
- // return Integer((ll) x);
- //}
- //
- //
- //
- //
- //void operator >> (istream &in, BigInt &a) {
- // string s;
- // getline(cin, s);
- // a = Integer(s);
- //}
- //
- //void operator << (ostream &out, BigInt a) {
- // Print(a);
- //}
- //
- //
- //
- //
- //bool operator < (BigInt a, BigInt b) {
- // Set(a);
- // Set(b);
- // if (a.size() != b.size()) return (a.size() < b.size());
- // FORD(i,a.size()-1,0)
- // if (a[i] != b[i]) return (a[i] < b[i]);
- // return false;
- //}
- //
- //bool operator > (BigInt a, BigInt b) {
- // return (b < a);
- //}
- //
- //bool operator == (BigInt a, BigInt b) {
- // return (!(a < b) && !(b < a));
- //}
- //
- //bool operator <= (BigInt a, BigInt b) {
- // return (a < b || a == b);
- //}
- //
- //bool operator >= (BigInt a, BigInt b) {
- // return (b < a || b == a);
- //}
- //
- //bool operator < (BigInt a, int b) {
- // return (a < Integer(b));
- //}
- //
- //bool operator > (BigInt a, int b) {
- // return (a > Integer(b));
- //}
- //
- //bool operator == (BigInt a, int b) {
- // return (a == Integer(b));
- //}
- //
- //bool operator >= (BigInt a, int b) {
- // return (a >= Integer(b));
- //}
- //
- //bool operator <= (BigInt a, int b) {
- // return (a <= Integer(b));
- //}
- //
- //
- //
- //BigInt max(BigInt a, BigInt b) {
- // if (a > b) return a;
- // return b;
- //}
- //
- //BigInt min(BigInt a, BigInt b) {
- // if (a < b) return a;
- // return b;
- //}
- //
- //
- //
- //
- //BigInt operator + (BigInt a, BigInt b) {
- // Set(a);
- // Set(b);
- // BigInt ans;
- // int carry = 0;
- // FOR(i,0,max(a.size(), b.size())-1) {
- // if (i < a.size()) carry += a[i];
- // if (i < b.size()) carry += b[i];
- // ans.pb(carry%base);
- // carry /= base;
- // }
- // if (carry) ans.pb(carry);
- // Set(ans);
- // return ans;
- //}
- //
- //BigInt operator + (BigInt a, int b) {
- // return a + Integer(b);
- //}
- //
- //BigInt operator ++ (BigInt &a) { // ++a
- // a = a + 1;
- // return a;
- //}
- //
- //void operator += (BigInt &a, BigInt b) {
- // a = a + b;
- //}
- //
- //void operator += (BigInt &a, int b) {
- // a = a + b;
- //}
- //
- //
- //
- //
- //BigInt operator - (BigInt a, BigInt b) {
- // Set(a);
- // Set(b);
- // BigInt ans;
- // int carry = 0;
- // FOR(i,0,a.size()-1) {
- // carry += a[i] - (i < b.size() ? b[i] : 0);
- // if (carry < 0) ans.pb(carry+base), carry = -1;
- // else ans.pb(carry), carry = 0;
- // }
- // Set(ans);
- // return ans;
- //}
- //
- //BigInt operator - (BigInt a, int b) {
- // return a - Integer(b);
- //}
- //
- //void operator -- (BigInt &a) { // --a
- // a = a - 1;
- //}
- //
- //void operator -= (BigInt &a, BigInt b) {
- // a = a + b;
- //}
- //
- //void operator -= (BigInt &a, int b) {
- // a = a - b;
- //}
- //
- //
- //
- //
- //BigInt operator * (BigInt a, BigInt b) {
- // Set(a);
- // Set(b);
- // BigInt ans;
- // ans.assign(a.size()+b.size(), 0);
- // FOR(i,0,a.size()-1) {
- // ll carry = 0ll;
- // for (int j=0;j<b.size() || carry > 0;j++) {
- // ll s = ans[i+j] + carry + (ll)a[i]*(j<b.size()?(ll)b[j]:0ll);
- // ans[i+j] = s%base;
- // carry = s/base;
- // }
- // }
- // Set(ans);
- // return ans;
- //}
- //
- //BigInt operator * (BigInt a, int b) {
- // return a * Integer(b);
- //}
- //
- //void operator *= (BigInt &a, BigInt b) {
- // a = a * b;
- //}
- //
- //void operator *= (BigInt &a, int b) {
- // a = a * b;
- //}
- //
- //
- //
- //BigInt operator / (BigInt a, BigInt b) {
- // Set(a);
- // Set(b);
- // if (b == Integer(0)) return Integer("-1");
- // BigInt ans, cur;
- // FORD(i,a.size()-1,0) {
- // cur.insert(cur.begin(), a[i]);
- // int x = 0, L = 0, R = base;
- // while (L <= R) {
- // int mid = (L+R)>>1;
- // if (b*Integer(mid) > cur) {
- // x = mid;
- // R = mid-1;
- // }
- // else
- // L = mid+1;
- // }
- // cur = cur - Integer(x-1)*b;
- // ans.insert(ans.begin(),x-1);
- // }
- // Set(ans);
- // return ans;
- //}
- //
- //BigInt operator / (BigInt a, int b) {
- // Set(a);
- // BigInt ans;
- // ll cur = 0ll;
- // FORD(i,a.size()-1,0) {
- // cur = (cur*(ll)base + (ll)a[i]);
- // ans.insert(ans.begin(),cur/b);
- // cur %= b;
- // }
- // Set(ans);
- // return ans;
- //}
- //
- //void operator /= (BigInt &a, BigInt b) {
- // a = a / b;
- //}
- //
- //void operator /= (BigInt &a, int b) {
- // a = a / b;
- //}
- //
- //
- //
- //BigInt operator % (BigInt a, BigInt b) {
- // Set(a);
- // Set(b);
- // if (b == Integer(0)) return Integer("-1");
- // BigInt ans;
- // FORD(i,a.size()-1,0) {
- // ans.insert(ans.begin(), a[i]);
- // int x = 0, L = 0, R = base;
- // while (L <= R) {
- // int mid = (L+R)>>1;
- // if (b*Integer(mid) > ans) {
- // x = mid;
- // R = mid-1;
- // }
- // else
- // L = mid+1;
- // }
- // ans = ans - Integer(x-1)*b;
- // }
- // Set(ans);
- // return ans;
- //}
- //
- //int operator % (BigInt a, int b) {
- // Set(a);
- // if (b == 0) return -1;
- // int ans = 0;
- // FORD(i,a.size()-1,0)
- // ans = (ans*(base%b) + a[i]%b)%b;
- // return ans;
- //}
- //
- //void operator %= (BigInt &a, BigInt b) {
- // a = a % b;
- //}
- //
- //void operator %= (BigInt &a, int b) {
- // a = a % Integer(b);
- //}
- //
- //BigInt gcd(BigInt a, BigInt b) {
- // Set(a);
- // Set(b);
- // while (b > Integer(0)) {
- // BigInt r = a%b;
- // a = b;
- // b = r;
- // }
- // Set(a);
- // return a;
- //}
- //
- //BigInt lcm(BigInt a, BigInt b) {
- // return (a*b/gcd(a,b));
- //}
- //
- //
- //BigInt sqrt(BigInt a) {
- // BigInt x0 = a, x1 = (a+1)/2;
- // while (x1 < x0) {
- // x0 = x1;
- // x1 = (x1+a/x1)/2;
- // }
- // return x0;
- //}
- //
- //
- //BigInt pow(BigInt a, BigInt b) {
- // if (b == Integer(0)) return Integer(1);
- // BigInt tmp = pow(a, b/2);
- // if (b%2 == 0) return tmp * tmp;
- // return tmp * tmp * a;
- //}
- //
- //
- //BigInt pow(BigInt a, int b) {
- // return pow(a,(Integer(b)));
- //}
- //
- //
- //int log(int n, BigInt a) { // log_n(a)
- // Set(a);
- // int ans = 0;
- // while (a > Integer(1)) {
- // ans++;
- // a /= n;
- // }
- // return ans;
- //}
- ///BIG INT END
- ///INT128 definition starts here
- //template<class integer>
- //inline integer to_int(const string& s, size_t* idx = 0, int base = 10) {
- // size_t n = s.size(), i = idx ? *idx : 0; bool sign = false; integer x = 0;
- // if (s[i] == '-')
- // ++i, sign = true;
- // function<int(char)> char_to_digit = [&](char c) {
- // static const int d[] = {'a'-10,'0'};
- // return tolower(c)-d[isdigit(c)]; };
- // while (i < n)
- // x *= base, x += char_to_digit(s[i++]);
- // if (idx)
- // *idx = i;
- // return sign ? -x : x; }
- //
- //template<class integer>
- //inline string to_string(integer x, int base = 10) {
- // bool sign = false; string s;
- // if (x < 0)
- // x = -x, sign = true;
- // function<char(int)> digit_to_char = [](int d) {
- // static const char c[] = {'a'-10,'0'};
- // return c[d < 10]+d; };
- // do
- // s += digit_to_char(x%base), x /= base;
- // while (x > 0);
- // if (sign)
- // s += '-';
- // reverse(s.begin(),s.end());
- // return s; }
- //
- //template<class integer>
- //inline istream& read(istream& is, integer& x) {
- // string s; is >> s, x = to_int<integer>(s); return is; }
- //
- //template<class integer>
- //inline ostream& write(ostream& os, integer x) { return os << to_string(x); }
- //
- //using int128 = signed __int128;
- //using uint128 = unsigned __int128;
- //
- //inline istream& operator>>(istream& is, int128 &x) { return read(is,x); }
- //inline istream& operator>>(istream& is, uint128 &x) { return read(is,x); }
- //inline ostream& operator<<(ostream& os, int128 x) { return write(os,x); }
- //inline ostream& operator<<(ostream& os, uint128 x) { return write(os,x); }
- ///INT128 definition ends
- ///Another definition for int128
- /*
- __int128 read()
- {
- __int128 x = 0, f = 1;
- char ch = getchar();
- while (ch < '0' || ch > '9')
- {
- if (ch == '-') f = -1;
- ch = getchar();
- }
- while (ch >= '0' && ch <= '9')
- {
- x = x * 10 + ch - '0';
- ch = getchar();
- }
- return x * f;
- }
- void print(__int128 x)
- {
- if (x < 0)
- {
- putchar('-');
- x = -x;
- }
- if (x > 9) print(x / 10);
- putchar(x % 10 + '0');
- //printf("\n");
- }
- std::ostream& operator<<(std::ostream& os, __int128 x)
- {
- if(x<0) return os << "-" << -x;
- if(x<10) return os << (char)(x+'0');
- return os << x/10 << (char)(x%10+'0');
- }*/
- ///int128 definition ends here
- ///KMP algorithm starts here
- //vector<int> prefix_function(string s) {
- // int n = (int)s.length();
- // vector<int> pi(n);
- // for (int i = 1; i < n; i++) {
- // int j = pi[i-1];
- // while (j > 0 && s[i] != s[j])
- // j = pi[j-1];
- // if (s[i] == s[j])
- // j++;
- // pi[i] = j;
- // }
- // return pi;
- //}
- //
- //int KMPSearch(string pat, string txt){
- // int lenp=(int)pat.length();
- // int lent=(int)txt.length();
- // vector<int>lps=prefix_function(pat);
- //
- // int i=0;
- // int j=0;
- // int total=0;
- // while(i<lent){
- // if(pat[j]==txt[i]){
- // j++;
- // i++;
- // }
- //
- // if(j==lenp){
- // total++;
- // j=lps[j-1];
- // }
- // else if(i<lent && pat[j]!=txt[i]){
- // if(j!=0){
- // j=lps[j-1];
- // }
- // else i++;
- // }
- //}
- //return total;
- //}
- ///KMP algorithm ends here
- ///Some custom function definitions
- //vector<long long int>vec(int n){
- // vector<long long int>v(n);
- // for(int i=0;i<n;i++){
- // cin>>v[i];
- // }
- // return v;
- //}
- //deque<int>deq(deque<int>v,int n){
- // int x;
- // for(int i=0;i<n;i++){
- // cin>>x;
- // v.push_back(x);
- // }
- // return v;
- //}
- //void a(int (&arr)[], int n){
- //// arr[n]=*arr;
- // for(int i=0;i<n;i++){
- // cin>>arr[i];
- // }
- //}
- //void printArray(int (arr)[],int n){
- // for(int i=0;i<n;i++){
- // cout<< arr[i]<<" ";
- // }
- // cout<<endl;
- //}
- //void printVec(vector<int>v){
- // for(auto u:v){
- // cout<<u<<" ";
- // }
- // cout<<endl;
- //}
- //void printDeq(deque<int>v){
- // for(auto u:v){
- // cout<<u<<" ";
- // }
- // cout<<endl;
- //}
- ///custom function definition ends here
- bool cmp(pair<int,int>p,pair<int,int>q){
- return p.first>=q.second;
- }
- int main() {///main function starts here
- fastio
- int t;
- int x;
- int cnt;
- int y;
- int k=0;
- while(cin>>t,t!=0){
- unordered_map<int,int>mp1;
- cnt=0;
- cout<<"Scenario #"<<++k<<el;
- for(int i=0;i<t;i++){
- cin>>x;
- for(int j=0;j<x;j++){
- cin>>y;
- mp1[y]=cnt;
- }
- cnt++;
- }
- unordered_map<int,queue<int>>mp2;
- string z;
- int tmp=cnt;
- cnt=0;
- while(cin>>z,z!="STOP"){
- if(z=="ENQUEUE"){
- cin>>y;
- if(mp1.find(y)!=mp1.end()){
- mp2[mp1[y]].push(y);
- }
- else{
- mp2[tmp].push(y);
- }
- }
- else if(z=="DEQUEUE"){
- if(!mp2[cnt].empty()){
- cout<<mp2[cnt].front()<<el;
- mp2[cnt].pop();
- }
- else{
- cnt++;
- if(!mp2[cnt].empty()){
- cout<<mp2[cnt].front()<<el;
- mp2[cnt].pop();
- }
- }
- }
- }
- cout<<el;
- }
- return 0;
- }///main function ends here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement