Advertisement
Guest User

123123

a guest
Dec 16th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.41 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. #define all(x) x.begin(), x.end()
  6. #define endl '\n'
  7. #define sz(x) (int)(x).size()
  8. #define mp(x, y) make_pair(x, y)
  9. #define pb push_back
  10. #define pii pair<int, int>
  11. #define rep(i, f, t) for (auto i = (f); i < (t); ++i)
  12. #define ui unsigned int
  13. #define ll long long
  14. #define int long long
  15. #define double long double
  16. #define ull unsigned long long
  17.  
  18. const int inf = (int)(2e9);
  19. const ll INF = (ll)(1e18);
  20. const int MOD = (int)(1e9 + 7);
  21. const double eps = (double)(1e-9);
  22. const double pi = acos(-1);
  23.  
  24. const int maxn = (int)(1e5 + 10);
  25. const int maxm = (int)(2e5 + 10);
  26.  
  27. void solve();
  28.  
  29. template <typename A> inline void print(A x) { cout << x << endl; }
  30. template <typename A, typename B> inline void print(A x, B y) { cout << x << ' ' << y << endl; }
  31. template <typename A, typename B, typename C> inline void print(A x, B y, C z) { cout << x << ' ' << y << ' ' << z << endl; }
  32. template <typename A> inline void in(A &x) { cin >> x; }
  33. template <typename A, typename B> inline void in(A &x, B &y) { cin >> x >> y; }
  34. template <typename A, typename B, typename C> inline void in(A &x, B &y, C &z) { cin >> x >> y >> z; }
  35. 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; }
  36. template <typename A> inline void read(A begin, A end) { while (begin != end) cin >> *(begin++); }
  37. template <typename A> inline void write(A begin, A end) { while (begin != end) { cout << *(begin++) << ' '; } cout << endl; }
  38.  
  39.  
  40. signed main()
  41. {
  42.     std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  43.     srand((ui)(time(0)));
  44.     cout << fixed << setprecision(20);
  45.     solve();
  46.     return 0;
  47. }
  48.  
  49. //Tom Soier and his friends
  50.  
  51. struct clr {
  52.     int x;
  53.     int col;
  54.     int t;
  55.     int q;
  56.     clr(){}
  57.     clr(int a, int b, int c, int d) {
  58.         col = a, x = b, t = c, q = d;
  59.     }
  60.    
  61. };
  62.  
  63. bool operator < (const clr& a, const clr& b) {
  64.     return a.t < b.t;
  65. }
  66.  
  67. bool comb(clr& a, clr& b)
  68. {
  69.     if (a.col == b.col)
  70.         return a.q > b.q;
  71.     return a.x < b.x;
  72. }
  73.  
  74.  
  75.  
  76. void solve()
  77. {
  78.     int n, k;
  79.     cin >> n >> k;
  80.     vector<int> colors(k + 1, 0);
  81.     vector<clr> query;
  82.     int m;
  83.     cin >> m;
  84.     map<clr, clr> q;
  85.     map<int, clr> z;
  86.     for (int i = 1; i <= m; ++i) {
  87.         int col, x1, x2;
  88.         cin >> col >> x1 >> x2;
  89.         clr a(col, x1, i, 1), b(col, x2, i, -1);
  90.         z[i] = a;
  91.         q[b] = a;
  92.         query.push_back(a);
  93.         query.push_back(b);
  94.  
  95.     }
  96.     sort(query.begin(), query.end(), comb);
  97.     for (int i = 0; i < sz(query); ++i)
  98.         cout << query[i].x << ' ' << query[i].t << endl;
  99.     cout << endl;
  100.     set<int> s;
  101.    
  102.     int start = 0;
  103.     for (int i = 0; i < sz(query); ++i) {
  104.         if (query[i].q == 1) {
  105.             if (start == 0) {
  106.                 start = query[i].x;
  107.                 cout << start << endl;
  108.                 s.insert(query[i].t);
  109.             }
  110.             else {
  111.                 if (s.size()) {
  112.                     set<int>::iterator o = s.end(); o--;
  113.                     int t_last = *o;
  114.                     clr last = z[t_last];
  115.                     cout << last.x << endl;
  116.                     colors[last.col] += query[i].x - start;
  117.                 }
  118.                 start = query[i].x;
  119.                 s.insert(query[i].t);
  120.             }
  121.         }
  122.         else {
  123.             set<int>::iterator o = s.end(); o--;
  124.             int t_last = *o;
  125.             clr last = z[t_last];
  126.             cout << last.x << endl;
  127.             if (last.t != q[query[i]].t) {
  128.                 s.erase(q[query[i]].t);
  129.             }
  130.             else {
  131.                 colors[query[i].col] += query[i].x - start;
  132.                 start = query[i].x;
  133.                 s.erase(q[query[i]].t);
  134.             }
  135.         }
  136.     }
  137.     for (int i = 1; i < sz(colors); ++i)
  138.         cout << colors[i] << ' ';
  139.     cout << endl;
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement