func_code_string: #include <bits/stdc++.h>   const int MaxN = 100000, inf = 0x3f3f3f3f;   inline void read(int &ans) {     ans = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) ans = ans * 10 + c - 48, c = getchar();     return;   }   int n, P;   struct Node {     int pos, t;     friend inline bool operator==(const Node &a, const Node &b) {       return a.pos == b.pos && a.t == b.t;     }   };   struct cmp_time {     inline bool operator()(const Node &a, const Node &b) const {       return a.t == b.t ? a.pos > b.pos : a.t > b.t;     }   };   struct cmp_pos {     inline bool operator()(const Node &a, const Node &b) const {       return a.pos > b.pos;     }   };   template <typename Element, typename cmp>   struct Exque {    private:     std::priority_queue<Element, std::vector<Element>, cmp> que, del;       public:     inline int size() { return que.size() - del.size(); }     inline void pop() {       if (del.size() && que.top() == del.top()) del.pop();       return que.pop();     }     inline void push(const Element &x) { return que.push(x); }     inline void delete_(const Element &x) {       return que.top() == x ? que.pop() : del.push(x);     }     inline Element top() {       while (del.size() && que.top() == del.top()) que.pop(), del.pop();       return que.top();     }   };   std::priority_queue<Node, std::vector<Node>, cmp_time> sitting;   std::priority_queue<Node, std::vector<Node>, cmp_pos> preparing;   Exque<Node, cmp_pos> inque;   std::queue<Node> queorder;   long long ans[MaxN + 1];   int cnt = 0;   int main() {     int i, t;     long long curtime = inf;     read(n), read(P);     for (i = 1; i <= n; ++i) {       read(t), sitting.push((Node){i, t});       if (t < curtime) curtime = t;     }     while (sitting.size() && sitting.top().t <= curtime)       preparing.push(sitting.top()), sitting.pop();     if (preparing.size() &&         (!inque.size() || preparing.top().pos < inque.top().pos))       inque.push(preparing.top()), queorder.push(preparing.top()),           preparing.pop();     while (cnt < n) {       ++cnt, ans[queorder.front().pos] = (curtime += P);       while (sitting.size() && sitting.top().t <= curtime)         if (sitting.top().pos < inque.top().pos)           inque.push(sitting.top()), queorder.push(sitting.top()), sitting.pop();         else           preparing.push(sitting.top()), sitting.pop();       inque.delete_(queorder.front()), queorder.pop();       while (sitting.size() && sitting.top().t <= curtime)         preparing.push(sitting.top()), sitting.pop();       if (preparing.size() &&           (!inque.size() || preparing.top().pos < inque.top().pos))         inque.push(preparing.top()), queorder.push(preparing.top()),             preparing.pop();       if (!inque.size() && sitting.size()) {         curtime = sitting.top().t;         while (sitting.size() && sitting.top().t <= curtime)           preparing.push(sitting.top()), sitting.pop();         inque.push(preparing.top()), queorder.push(preparing.top()),             preparing.pop();       }     }     for (i = 1; i <= n; ++i) printf( %I64d  , ans[i]);     putchar(  n );     return 0;   }   