Advertisement
agul

WSO 2012 :: Practice

Nov 4th, 2012
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <algorithm>
  2. #include <cassert>
  3.  
  4. using namespace std;
  5.  
  6. struct event
  7. {
  8.     int x, id, typ;
  9. };
  10.  
  11. bool cmp( const event &a, const event &b )
  12. {
  13.     return a.x < b.x;
  14. }
  15.  
  16. class Task{
  17.     private:
  18.         event sm[1005000];
  19.         int arr[1005000];
  20.         int beg, en;
  21.         int num;
  22.         int count;
  23.     public:
  24.         Task( const int );
  25.         void push( const int , const int );
  26.         void pop( const int );
  27.         void finish();
  28. };
  29.  
  30. Task::Task( const int threadNumber )
  31.     : num( 0 )
  32. {
  33.     count = threadNumber;
  34. }
  35.  
  36. void Task::push( const int value, const int timestamp)
  37. {
  38.     //printf("val = %d, time = %d\n", value, timestamp);
  39.     sm[ num ].x = timestamp;
  40.     sm[ num ].typ = 1;
  41.     sm[ num++ ].id = value;
  42. }
  43.  
  44. void Task::pop( const int timestamp )
  45. {
  46.     //printf("time = %d\n", timestamp);
  47.     sm[ num ].x = timestamp;
  48.     sm[ num++ ].typ = -1;
  49. }
  50.  
  51. void Task::finish()
  52. {
  53.     --count;
  54.     //if (count > 0) return;
  55.     FILE * stream = fopen("output.txt", "w");
  56.     sort( sm, sm + num, cmp );
  57.     beg = 0;
  58.     en = 0;
  59.     for (int i = 0; i < num; ++i) {
  60.         if (sm[i].typ == -1) {
  61.             while(sm[beg].typ == -1) ++beg;
  62.             fprintf(stream, "%d\n", sm[beg].id);
  63.             ++beg;
  64.         }
  65.     }
  66.     fclose(stream);
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement