Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <cassert>
- using namespace std;
- struct event
- {
- int x, id, typ;
- };
- bool cmp( const event &a, const event &b )
- {
- return a.x < b.x;
- }
- class Task{
- private:
- event sm[1005000];
- int arr[1005000];
- int beg, en;
- int num;
- int count;
- public:
- Task( const int );
- void push( const int , const int );
- void pop( const int );
- void finish();
- };
- Task::Task( const int threadNumber )
- : num( 0 )
- {
- count = threadNumber;
- }
- void Task::push( const int value, const int timestamp)
- {
- //printf("val = %d, time = %d\n", value, timestamp);
- sm[ num ].x = timestamp;
- sm[ num ].typ = 1;
- sm[ num++ ].id = value;
- }
- void Task::pop( const int timestamp )
- {
- //printf("time = %d\n", timestamp);
- sm[ num ].x = timestamp;
- sm[ num++ ].typ = -1;
- }
- void Task::finish()
- {
- --count;
- //if (count > 0) return;
- FILE * stream = fopen("output.txt", "w");
- sort( sm, sm + num, cmp );
- beg = 0;
- en = 0;
- for (int i = 0; i < num; ++i) {
- if (sm[i].typ == -1) {
- while(sm[beg].typ == -1) ++beg;
- fprintf(stream, "%d\n", sm[beg].id);
- ++beg;
- }
- }
- fclose(stream);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement