SHARE
TWEET

Untitled

lalalalalalalaalalla Nov 10th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <iomanip>
  5. #include <queue>
  6. #include <cmath>
  7. #include <algorithm>
  8. #include <tuple>
  9. #include <iomanip>
  10. #include <stdio.h>
  11. #include <map>
  12. #include <bitset>
  13. #include <set>
  14. #include <stack>
  15. #include <queue>
  16. #include <unordered_set>
  17. #include <cassert>
  18. #include <stdlib.h>
  19. #include <time.h>
  20. #include <random>
  21.  
  22.  
  23. //#pragma GCC optimize("Ofast,no-stack-protector")
  24. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
  25. //#pragma GCC optimize("unroll-loops")
  26. //#pragma GCC optimize("fast-math")
  27. //#pragma GCC optimize("section-anchors")
  28. //#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
  29. //#pragma GCC optimize("vpt")
  30. //#pragma GCC optimize("rename-registers")
  31. //#pragma GCC optimize("move-loop-invariants")
  32. //#pragma GCC optimize("unswitch-loops")
  33. //#pragma GCC optimize("function-sections")
  34. //#pragma GCC optimize("data-sections")
  35. //#pragma GCC optimize("branch-target-load-optimize")
  36. //#pragma GCC optimize("branch-target-load-optimize2")
  37. //#pragma GCC optimize("btr-bb-exclusive")
  38.  
  39.  
  40. #define int long long
  41. #define ll long long
  42. #define ull unsigned long long
  43. #define all(a) a.begin(), a.end()
  44. #define pii pair<int, int>
  45. #define pb push_back
  46. #define ld long double
  47.  
  48.  
  49. using namespace std;
  50.  
  51. const int INF = 1e17;
  52. //const int mod = 2600000069;
  53. //const int p = 179;
  54. const int MAXN = 100001;
  55.  
  56. mt19937 my_rand(163721);
  57.  
  58. struct node {
  59.     int y = my_rand(), size = 0;
  60.     node *l, *r;
  61.     node() {
  62.         x = INF;
  63.         l = r = 0;
  64.     }
  65. };
  66.  
  67. typedef node* pnode;
  68. typedef pair<pnode, pnode> Pair;
  69.  
  70. vector<node> a(MAXN);
  71. int ind = 0;
  72.  
  73. void recalc(pnode a) {
  74.     a->sum = 1;
  75.     if (a->l) a->sum += a->l->sum;
  76.     if (a->r) a->sum += a->r->sum;
  77. }
  78.  
  79. pnode merge(pnode a, pnode b) {
  80.     if (!a) return b;
  81.     if (!b) return a;
  82.     if (a->y > b->y) {
  83.         a->r = merge(a->r, b);
  84.         recalc(a);
  85.         return a;
  86.     } else {
  87.         b->l = merge(a, b->l);
  88.         recalc(b);
  89.         return b;
  90.     }
  91. }
  92.  
  93. pnode root = 0;
  94.  
  95. void split(pnode a, int k, pnode &l, pnode &r) {
  96.     if (!a) {
  97.         l = r = 0;
  98.         return;
  99.     }
  100.     if (a->l->size < k) {
  101.         split(a->r, k - a->r->size - 1, l, r);
  102.         a->r = l;
  103.         l = a;
  104.     } else {
  105.         split(a->l, k, l, r);
  106.         a->l = r;
  107.         r = a;
  108.     }
  109. }
  110.  
  111. void change(int l, int r) {
  112.     Pair q, q1;
  113.     split(root, r, q.first, q.second);
  114.     split(q.first, min(r - l + 1, l - 1), q1.first, q1.second);
  115.     root = merge(merge(q1.second, q1.first), q.second);
  116. }
  117.  
  118. signed main() {
  119.     ios_base::sync_with_stdio(0);
  120.     cin.tie(0);
  121.     cout.tie(0);
  122.     int n, m;
  123.     cin >> n >> m;
  124.     for (int i = 0; i < n; i++) {
  125.         pnode t = &a[ind++];
  126.         merge(root, t);
  127.     }
  128.     int l, r;
  129.     for (int i = 0; i < m; i++) {
  130.         cin >> l >> r;
  131.         change(l, r);
  132.     }
  133. }
  134. /*
  135.  
  136. */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top