Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <bits/stdc++.h>
- using namespace std;
- #define all(x) x.begin(), x.end()
- #define endl '\n'
- #define sz(x) (int)(x).size()
- #define mp(x, y) make_pair(x, y)
- #define pb push_back
- #define pii pair<int, int>
- #define rep(i, f, t) for (auto i = (f); i < (t); ++i)
- #define ui unsigned int
- #define ll long long
- #define int long long
- #define double long double
- #define ull unsigned long long
- const int inf = (int)(2e9);
- const ll INF = (ll)(1e18);
- const int MOD = (int)(1e9 + 7);
- const double eps = (double)(1e-9);
- const double pi = acos(-1);
- const int maxn = (int)(1e5 + 10);
- const int maxm = (int)(2e5 + 10);
- void solve();
- template <typename A> inline void print(A x) { cout << x << endl; }
- template <typename A, typename B> inline void print(A x, B y) { cout << x << ' ' << y << endl; }
- template <typename A, typename B, typename C> inline void print(A x, B y, C z) { cout << x << ' ' << y << ' ' << z << endl; }
- template <typename A> inline void in(A &x) { cin >> x; }
- template <typename A, typename B> inline void in(A &x, B &y) { cin >> x >> y; }
- template <typename A, typename B, typename C> inline void in(A &x, B &y, C &z) { cin >> x >> y >> z; }
- template <typename A, typename B, typename C, typename D> inline void in(A &x, B &y, C &z, D &p) { cin >> x >> y >> z >> p; }
- template <typename A> inline void read(A begin, A end) { while (begin != end) cin >> *(begin++); }
- template <typename A> inline void write(A begin, A end) { while (begin != end) { cout << *(begin++) << ' '; } cout << endl; }
- signed main()
- {
- std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- srand((ui)(time(0)));
- cout << fixed << setprecision(20);
- solve();
- return 0;
- }
- //Tom Soier and his friends
- struct clr {
- int x;
- int col;
- int t;
- int q;
- clr(){}
- clr(int a, int b, int c, int d) {
- col = a, x = b, t = c, q = d;
- }
- };
- bool operator < (const clr& a, const clr& b) {
- return a.t < b.t;
- }
- bool comb(clr& a, clr& b)
- {
- if (a.col == b.col)
- return a.q > b.q;
- return a.x < b.x;
- }
- void solve()
- {
- int n, k;
- cin >> n >> k;
- vector<int> colors(k + 1, 0);
- vector<clr> query;
- int m;
- cin >> m;
- map<clr, clr> q;
- map<int, clr> z;
- for (int i = 1; i <= m; ++i) {
- int col, x1, x2;
- cin >> col >> x1 >> x2;
- clr a(col, x1, i, 1), b(col, x2, i, -1);
- z[i] = a;
- q[b] = a;
- query.push_back(a);
- query.push_back(b);
- }
- sort(query.begin(), query.end(), comb);
- for (int i = 0; i < sz(query); ++i)
- cout << query[i].x << ' ' << query[i].t << endl;
- cout << endl;
- set<int> s;
- int start = 0;
- for (int i = 0; i < sz(query); ++i) {
- if (query[i].q == 1) {
- if (start == 0) {
- start = query[i].x;
- cout << start << endl;
- s.insert(query[i].t);
- }
- else {
- if (s.size()) {
- set<int>::iterator o = s.end(); o--;
- int t_last = *o;
- clr last = z[t_last];
- cout << last.x << endl;
- colors[last.col] += query[i].x - start;
- }
- start = query[i].x;
- s.insert(query[i].t);
- }
- }
- else {
- set<int>::iterator o = s.end(); o--;
- int t_last = *o;
- clr last = z[t_last];
- cout << last.x << endl;
- if (last.t != q[query[i]].t) {
- s.erase(q[query[i]].t);
- }
- else {
- colors[query[i].col] += query[i].x - start;
- start = query[i].x;
- s.erase(q[query[i]].t);
- }
- }
- }
- for (int i = 1; i < sz(colors); ++i)
- cout << colors[i] << ' ';
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement