Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.62 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. using ll = long long;
  6. using ld = long double;
  7. using pii = pair<int, int>;
  8. using pdd = pair<ld, ld>;
  9.  
  10. int __intend = 0;
  11. void nextIntend(){__intend++;}
  12. void prevIntend(){__intend--;}
  13. string getIntend(){
  14.     string r;
  15.     for (int i = 0; i < __intend; ++i){
  16.         r += '\t';
  17.     }
  18.     return r;
  19. }
  20.  
  21. template<typename T>
  22. void print(const char s[], bool intend, T & v){
  23.     if (intend) cout << getIntend();
  24.     cout << s << " = " << v << endl;
  25. }
  26.  
  27. template<typename T, typename... TA>
  28. void print(const char s[], bool intend, T & v, TA&... args){
  29.     if (intend) cout << getIntend();
  30.     while(*s != ','){
  31.         if (*s != ' ') cout << *s;
  32.         s++;
  33.     }
  34.     while(*s == ',' || *s == ' ') s++;
  35.     cout << " = " << v << " | ";
  36.     print(s, false, args...);
  37. }
  38.  
  39. #if _DEBUG
  40. #define de if (1)
  41. #define dbg(...) print(#__VA_ARGS__, 1, __VA_ARGS__)
  42. #else
  43. #define de if (0)
  44. #define dbg(...)
  45. #endif
  46.  
  47.  
  48.  
  49. #define ho(x) #x << " = " << x << " | "
  50. #define gint getIntend
  51. #define nint nextIntend
  52. #define pint prevIntend
  53.  
  54.  
  55. void solve(){
  56.     de cout << "Started app" << endl;
  57.     de cout.flush();
  58.     int n, w, l;
  59.     cin >> n >> w >> l;
  60.     de cout << "Readed n w l" << endl;
  61.     de cout << ho(n) << ho(w) << ho(l) << endl;
  62.     multiset<int> curBatary;
  63.     curBatary.insert(0);
  64.     curBatary.insert(l);
  65.     vector<vector<int>> startBatary(w + 2);
  66.     vector<vector<int>> endBatary(w + 2);
  67.     vector<int> mxLen(l);
  68.     mxLen[0] = l;
  69.     priority_queue<pii, vector<pii>, less<pii>> curMax;
  70.     curMax.push({l, 0});
  71.     for (int i = 0; i < n; ++i){
  72.         int x, a, b;
  73.         cin >> x >> a >> b;
  74.         b++; // to [a, b)
  75.         startBatary[a].push_back(x);
  76.         endBatary[b].push_back(x);
  77.     }
  78.     de cout << "Readed batary" << endl;
  79.     for (int i = 0; i <= w; ++i){
  80.         de cout << gint() << ho(i) << endl;
  81.         nint();
  82.         for (int x : endBatary[i]){
  83.             de cout << gint() << "delete " << ho(x) << endl;
  84.             auto it = curBatary.erase(curBatary.find(x));
  85.             int rx = *it;
  86.             int lx = *--it;
  87.             mxLen[lx] = rx - lx;
  88.             de cout << gint() << "on " << lx << " put " << mxLen[lx] << endl;
  89.             curMax.push({mxLen[lx], lx});
  90.         }
  91.         for (int x : startBatary[i]){
  92.             de cout << gint() << "add " << ho(x) << endl;
  93.             auto it = curBatary.insert(x);
  94.             int lx = *--it;
  95.             int rx = *++++it;
  96.             mxLen[lx] = x - lx;
  97.             mxLen[x] = rx - x;
  98.             de cout << gint() << "on " << lx << " put " << mxLen[lx] << endl;
  99.             de cout << gint() << "on " << x << " put " << mxLen[x] << endl;
  100.             curMax.push({mxLen[lx], lx});
  101.             curMax.push({mxLen[x], x});
  102.         }
  103.         while(curMax.size() && mxLen[curMax.top().second] != curMax.top().first){
  104.             de cout << gint() << "false " << ho(curMax.top().first) << ho(curMax.top().second) << endl;
  105.             curMax.pop();
  106.         }
  107.         pint();
  108.         cout << curMax.top().first << endl;
  109.     }
  110. }
  111.  
  112. const bool fastIO = true;
  113. const bool withTest = false;
  114. const bool fileIO = false;
  115. #define file "file"
  116.  
  117. int main(){
  118.     #if _STRESS
  119.         const bool fileIO = false;
  120.     #endif
  121.     #if !_DEBUG
  122.         if (fileIO){
  123.             freopen(file".in", "r", stdin);
  124.             freopen(file".out", "w", stdout);
  125.         }
  126.     #endif
  127.     if (fastIO){
  128.         cin.tie(0);
  129.         cout.tie(0);
  130.         ios_base::sync_with_stdio(0);
  131.     }
  132.     if (withTest){
  133.         int t;
  134.         cin >> t;
  135.         while(t--) solve();
  136.     }
  137.     else solve();
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement