Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- // #include <iostream>
- // #include <cstdio>
- // #include <cstdlib>
- // #include <algorithm>
- // #include <cmath>
- // #include <vector>
- // #include <set>
- // #include <map>
- // #include <queue>
- // #include <ctime>
- // #include <cassert>
- // #include <complex>
- // #include <string>
- // #include <cstring>
- // #include <queue>
- // #include <bitset>
- using namespace std;
- // #pragma GCC optimize("Ofast,no-stack-protector")
- // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
- // #pragma GCC optimize("unroll-loops")
- #define ll long long int
- #define vi vector< int >
- #define vll vector< ll >
- #define sc scanf
- #define pf printf
- #define cspf(i) pf("Case %d: ", i)
- #define spc pf(" ")
- #define line pf("\n")
- #define ff first
- #define ss second
- #define mp make_pair
- #define pb push_back
- #define ppb pop_back
- #define tp(v,j) get<j>(v)
- #define Log(b,x) (log(x)/log(b))
- #define FOR(i,x,y) for(int i = int(x); i < int(y); i++)
- #define ROF(i,x,y) for(int i = int(x)-1; i >= int(y); i--)
- #define clr(arr,x) memset(arr, x, sizeof arr)
- #define vout(v,sz) for(int w=0;w<sz;w++){if(w) spc; cout<<v[w];}
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define unq(v) sort(all(v)),(v).resize(unique(all(v))-v.begin())
- #define fastIO ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
- #define sc1(x) sc("%d",&x)
- #define sc2(x,y) sc("%d %d", &x, &y)
- #define sc3(x,y,z) sc("%d %d %d", &x, &y, &z)
- #define scl1(x) sc("%lld",&x);
- #define scl2(x,y) sc("%lld %lld", &x, &y)
- #define scf1(x) sc("%lf",&x)
- #define scf2(x,y) sc("%lf %lf", &x, &y)
- #define pf1(x) pf("%d",x)
- #define pf2(x,y) pf("%d %d", x, y)
- #define pf3(x,y,z) pf("%d %d %d", x, y, z)
- #define pfl1(x) pf("%lld",x)
- #define pfl2(x,y) pf("%lld %lld",x,y)
- #define MOD 10056
- #define MaxN 10000001
- #define MAX (int)(1e9+7)
- #define inf 0x3f3f3f3f
- #define PI acos(-1.0) // 3.1415926535897932
- #define eps 1e-9
- template <class T> inline T bigMod(T p,T e,T M){T ret=1; for(;e>0;e>>=1){ if(e&1) ret=(ret*p)%M; p=(p*p)%M;} return (T)ret;}
- template <class T> inline T modInverse(T a,T M){return bigMod(a,M-2,M);}
- template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
- template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
- template <class T> inline T SQR(T a){return a*a;}
- int dx[] = { 1,-1, 0, 0};
- int dy[] = { 0, 0, 1,-1};
- vector< int > v;
- int top;
- map< int, int > cnt;
- void add(){
- int u; sc1(u);
- for(int i=0; i<v.size(); i++){
- if(v[i]==u){
- pf("same priority.\n");
- return;
- }
- }
- v.pb(u);
- cnt[u]=0;
- pf("success.\n");
- }
- void close(){
- int u; sc1(u);
- for(int i=0; i<v.size(); i++){
- if(u==v[i]){
- pf("close %d with %d.\n",u,cnt[u]);
- v.erase(v.begin()+i);
- cnt[u]=0;
- if(u==top) top=-1;
- return;
- }
- }
- pf("invalid priority.\n");
- }
- void chat(){
- int w; sc1(w);
- if(top!=-1){
- cnt[top]+=w;
- pf("success.\n");
- return;
- }
- if(v.size()){
- cnt[v[0]]+=w;
- pf("success.\n");
- return;
- }
- pf("empty.\n");
- }
- void rotate(){
- int x; sc1(x);
- if(v.size()<x){
- pf("out of range.\n");
- return;
- }
- int u = v[x-1];
- v.erase(v.begin()+(x-1));
- v.insert(v.begin(), u);
- pf("success.\n");
- }
- void prior(){
- if(v.size()==0){
- pf("empty.\n");
- return;
- }
- int mx = v[0], in = 0;
- for(int i=1; i<v.size(); i++){
- if(v[i]>mx){
- mx = v[i];
- in = i;
- }
- }
- v.erase(v.begin()+in);
- v.insert(v.begin(), mx);
- pf("success.\n");
- }
- void choose(){
- int u; sc1(u);
- for(int i=0; i<v.size(); i++){
- if(v[i]==u){
- v.erase(v.begin()+i);
- v.insert(v.begin(), u);
- pf("success.\n");
- return;
- }
- }
- pf("invalid priority.\n");
- }
- void topp(){
- int u; sc1(u);
- for(int i=0; i<v.size(); i++){
- if(v[i]==u){
- top=u;
- pf("success.\n");
- return;
- }
- }
- pf("invalid priority.\n");
- }
- void untop(){
- if(top==-1){
- pf("no such person.\n");
- return;
- }
- top = -1;
- pf("success.\n");
- }
- void bye(){
- if(top!=-1){
- if(cnt[top]){
- pf("Bye %d: %d\n",top,cnt[top]);
- }
- }
- for(int i=0; i<v.size(); i++){
- if(cnt[v[i]] && v[i]!=top){
- pf("Bye %d: %d\n",v[i],cnt[v[i]]);
- }
- }
- }
- int main(){
- #ifndef ONLINE_JUDGE
- clock_t tStart = clock();
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int t; sc1(t);
- while(t--){
- v.clear();
- cnt.clear();
- top = -1;
- int n; sc1(n);
- for(int i=1; i<=n; i++){
- pf("Operation #%d: ",i);
- string s;
- cin>>s;
- if(s=="Add") add();
- else if(s=="Close") close();
- else if(s=="Chat") chat();
- else if(s=="Rotate") rotate();
- else if(s=="Prior") prior();
- else if(s=="Choose") choose();
- else if(s=="Top") topp();
- else if(s=="Untop") untop();
- }
- bye();
- }
- #ifndef ONLINE_JUDGE
- fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement