Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string>
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <set>
- #include <memory.h>
- #include <map>
- #include <math.h>
- #include <queue>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string>
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <set>
- #include <memory.h>
- #include <map>
- #include <math.h>
- #include <queue>
- #include <stack>
- #include <complex>
- #include <list>
- #include <deque>
- #include <pthread.h>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- #define mp make_pair
- #define pb push_back
- #define sz(x) (int)x.size()
- #define X first
- #define Y second
- #define all(x) x.begin(),x.end()
- class Task
- {
- public:
- Task(const int threadsNumber)
- {
- pthread_mutex_init(&mutex,NULL);
- }
- void push(const int value, const int timestamp)
- {
- pthread_mutex_lock(&mutex);
- commands.pb(mp(timestamp, mp(1, value)));
- pthread_mutex_unlock(&mutex);
- }
- void pop(const int timestamp)
- {
- pthread_mutex_lock(&mutex);
- commands.pb(mp(timestamp, mp(0, -1)));
- pthread_mutex_unlock(&mutex);
- }
- void finish()
- {
- freopen("output.txt", "w", stdout);
- vector<int> _stack;
- sort(all(commands));
- for (int i = 0; i < sz(commands); i++)
- {
- if (commands[i].Y.X == 1)
- {
- _stack.pb(commands[i].Y.Y);
- }
- else
- {
- printf("%d\n", _stack[sz(_stack)-1]);
- _stack.pop_back();
- }
- }
- }
- vector< pair< int, pair< int, int> > > commands;
- pthread_mutex_t mutex;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement