Advertisement
erfanul007

LA 7047

Jul 16th, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.68 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. // #include <iostream>
  3. // #include <cstdio>
  4. // #include <cstdlib>
  5. // #include <algorithm>
  6. // #include <cmath>
  7. // #include <vector>
  8. // #include <set>
  9. // #include <map>
  10. // #include <queue>
  11. // #include <ctime>
  12. // #include <cassert>
  13. // #include <complex>
  14. // #include <string>
  15. // #include <cstring>
  16. // #include <queue>
  17. // #include <bitset>
  18.  
  19. using namespace std;
  20.  
  21. // #pragma GCC optimize("Ofast,no-stack-protector")
  22. // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  23. // #pragma GCC optimize("unroll-loops")
  24.  
  25.  
  26. #define ll long long int
  27. #define vi vector< int >
  28. #define vll vector< ll >
  29.  
  30. #define sc scanf
  31. #define pf printf
  32. #define cspf(i) pf("Case %d: ", i)
  33. #define spc pf(" ")
  34. #define line pf("\n")
  35.  
  36. #define ff first
  37. #define ss second
  38. #define mp make_pair
  39. #define pb push_back
  40. #define ppb pop_back
  41. #define tp(v,j) get<j>(v)
  42. #define Log(b,x) (log(x)/log(b))
  43.  
  44. #define FOR(i,x,y) for(int i = int(x); i < int(y); i++)
  45. #define ROF(i,x,y) for(int i = int(x)-1; i >= int(y); i--)
  46. #define clr(arr,x) memset(arr, x, sizeof arr)
  47. #define vout(v,sz) for(int w=0;w<sz;w++){if(w) spc; cout<<v[w];}
  48. #define all(v) v.begin(), v.end()
  49. #define rall(v) v.rbegin(), v.rend()
  50. #define unq(v) sort(all(v)),(v).resize(unique(all(v))-v.begin())
  51. #define fastIO ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
  52.  
  53. #define sc1(x) sc("%d",&x)
  54. #define sc2(x,y) sc("%d %d", &x, &y)
  55. #define sc3(x,y,z) sc("%d %d %d", &x, &y, &z)
  56. #define scl1(x) sc("%lld",&x);
  57. #define scl2(x,y) sc("%lld %lld", &x, &y)
  58. #define scf1(x) sc("%lf",&x)
  59. #define scf2(x,y) sc("%lf %lf", &x, &y)
  60.  
  61. #define pf1(x) pf("%d",x)
  62. #define pf2(x,y) pf("%d %d", x, y)
  63. #define pf3(x,y,z) pf("%d %d %d", x, y, z)
  64. #define pfl1(x) pf("%lld",x)
  65. #define pfl2(x,y) pf("%lld %lld",x,y)
  66.  
  67. #define MOD 10056
  68. #define MaxN 10000001
  69. #define MAX (int)(1e9+7)
  70. #define inf 0x3f3f3f3f
  71. #define PI acos(-1.0) // 3.1415926535897932
  72. #define eps 1e-9
  73.  
  74. 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;}
  75. template <class T> inline T modInverse(T a,T M){return bigMod(a,M-2,M);}
  76. template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
  77. template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
  78. template <class T> inline T SQR(T a){return a*a;}
  79.  
  80. int dx[] = { 1,-1, 0, 0};
  81. int dy[] = { 0, 0, 1,-1};
  82.  
  83. vector< int > v;
  84. int top;
  85. map< int, int > cnt;
  86.  
  87. void add(){
  88. int u; sc1(u);
  89. for(int i=0; i<v.size(); i++){
  90. if(v[i]==u){
  91. pf("same priority.\n");
  92. return;
  93. }
  94. }
  95. v.pb(u);
  96. cnt[u]=0;
  97. pf("success.\n");
  98. }
  99.  
  100. void close(){
  101. int u; sc1(u);
  102. for(int i=0; i<v.size(); i++){
  103. if(u==v[i]){
  104. pf("close %d with %d.\n",u,cnt[u]);
  105. v.erase(v.begin()+i);
  106. cnt[u]=0;
  107. if(u==top) top=-1;
  108. return;
  109. }
  110. }
  111. pf("invalid priority.\n");
  112. }
  113.  
  114. void chat(){
  115. int w; sc1(w);
  116. if(top!=-1){
  117. cnt[top]+=w;
  118. pf("success.\n");
  119. return;
  120. }
  121. if(v.size()){
  122. cnt[v[0]]+=w;
  123. pf("success.\n");
  124. return;
  125. }
  126. pf("empty.\n");
  127. }
  128.  
  129. void rotate(){
  130. int x; sc1(x);
  131. if(v.size()<x){
  132. pf("out of range.\n");
  133. return;
  134. }
  135. int u = v[x-1];
  136. v.erase(v.begin()+(x-1));
  137. v.insert(v.begin(), u);
  138. pf("success.\n");
  139. }
  140.  
  141. void prior(){
  142. if(v.size()==0){
  143. pf("empty.\n");
  144. return;
  145. }
  146. int mx = v[0], in = 0;
  147. for(int i=1; i<v.size(); i++){
  148. if(v[i]>mx){
  149. mx = v[i];
  150. in = i;
  151. }
  152. }
  153. v.erase(v.begin()+in);
  154. v.insert(v.begin(), mx);
  155. pf("success.\n");
  156. }
  157.  
  158. void choose(){
  159. int u; sc1(u);
  160. for(int i=0; i<v.size(); i++){
  161. if(v[i]==u){
  162. v.erase(v.begin()+i);
  163. v.insert(v.begin(), u);
  164. pf("success.\n");
  165. return;
  166. }
  167. }
  168. pf("invalid priority.\n");
  169. }
  170.  
  171. void topp(){
  172. int u; sc1(u);
  173. for(int i=0; i<v.size(); i++){
  174. if(v[i]==u){
  175. top=u;
  176. pf("success.\n");
  177. return;
  178. }
  179. }
  180. pf("invalid priority.\n");
  181. }
  182.  
  183. void untop(){
  184. if(top==-1){
  185. pf("no such person.\n");
  186. return;
  187. }
  188. top = -1;
  189. pf("success.\n");
  190. }
  191.  
  192. void bye(){
  193. if(top!=-1){
  194. if(cnt[top]){
  195. pf("Bye %d: %d\n",top,cnt[top]);
  196. }
  197. }
  198. for(int i=0; i<v.size(); i++){
  199. if(cnt[v[i]] && v[i]!=top){
  200. pf("Bye %d: %d\n",v[i],cnt[v[i]]);
  201. }
  202. }
  203. }
  204.  
  205. int main(){
  206.  
  207. #ifndef ONLINE_JUDGE
  208. clock_t tStart = clock();
  209. freopen("input.txt", "r", stdin);
  210. freopen("output.txt", "w", stdout);
  211. #endif
  212.  
  213. int t; sc1(t);
  214.  
  215. while(t--){
  216. v.clear();
  217. cnt.clear();
  218. top = -1;
  219.  
  220. int n; sc1(n);
  221.  
  222. for(int i=1; i<=n; i++){
  223. pf("Operation #%d: ",i);
  224. string s;
  225. cin>>s;
  226. if(s=="Add") add();
  227. else if(s=="Close") close();
  228. else if(s=="Chat") chat();
  229. else if(s=="Rotate") rotate();
  230. else if(s=="Prior") prior();
  231. else if(s=="Choose") choose();
  232. else if(s=="Top") topp();
  233. else if(s=="Untop") untop();
  234. }
  235. bye();
  236.  
  237. }
  238.  
  239. #ifndef ONLINE_JUDGE
  240. fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
  241. #endif
  242.  
  243. return 0;
  244. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement