Advertisement
triclops200

solt'

Aug 13th, 2012
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <string>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cstdlib>
  5. using namespace std;
  6. unsigned int values[100000];
  7. unsigned short indecies[100000];
  8. int top[1000];
  9. inline int getValue(unsigned index)
  10. {
  11.     return values[index] & 0x7FFFFFFF;
  12. }
  13. void setValue(unsigned index, unsigned val)
  14. {
  15.     (values[index] &= 0x80000000)|=val;
  16. }
  17. inline int getIndex(unsigned index)
  18. {
  19.     return indecies[index] | ((values[index]>>31)<<16);
  20. }
  21. void setIndex(unsigned index, unsigned value)
  22. {
  23.     indecies[index] = value;
  24.     values[index] &= 0x7FFFFFFF;
  25.     values[index] |= (value>>16)<<31;
  26. }
  27. int main()
  28. {
  29.     int counter = 0;
  30.     int max;
  31.     scanf("%d",&max);
  32.     int id;
  33.     int val;
  34.     int len = 1;
  35.     for(int i = 0; i < max; i++)
  36.     {
  37.         char op[5];
  38.         scanf("%s %d",op,&id);
  39.         id-=1;
  40.         if(!strcmp(op,"PUSH"))
  41.         {
  42.             scanf("%d",& val);
  43.             setValue(counter,val);
  44.             setIndex(counter,top[id]);
  45.             top[id] = counter;
  46.             counter++;
  47.             continue;
  48.         }
  49.         printf("%d\n",getValue(top[id]));
  50.         top[id] = getIndex(top[id]);
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement