QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#644735#9465. 基础 01 练习题JWRuixi0 0ms0kbC++205.8kb2024-10-16 15:18:382024-10-16 15:18:40

Judging History

你现在查看的是最新测评结果

  • [2024-10-16 15:18:40]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-10-16 15:18:38]
  • 提交

answer

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#ifdef LOCAL
#include "stdafx.h"
#else
#include <bits/stdc++.h>
#define IL inline
#define LL long long
#define eb emplace_back
#define sz(v) ((int) (v).size())
#define me(f, x) memset(f, x, sizeof(f))
#define mc(f, g) memcpy(f, g, sizeof(g))
#define L(i, j, k) for (int i = (j); i <= (k); ++i)
#define R(i, j, k) for (int i = (j); i >= (k); --i)
#define FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)
using namespace std;

using vi = vector<int>;
#endif

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

using ull = unsigned long long;

constexpr int N = 2e5 + 9;
int n, m, typ;

struct mat {
  int x1, x2, y1, y2;
} a[N];

vi lis[N];

int p[N], q[N];

namespace F1 {

ull sum[N];

#define m ((l + r) >> 1)
#define ls(p) t[p].ch[0]
#define rs(p) t[p].ch[1]

struct info {
  ull a, b;
  info (ull _a = 0, ull _b = 0) : a(_a), b(_b) {}
  info operator + (const info &rhs) const {
    return info(a + rhs.a, b + rhs.b);
  }
};

int tot;

struct nd {
  info x;
  bool lz;
  int ch[2], L, R;
} t[N * 200];

int R, rt[N];

void up (int p) {
  int L = t[p].L, R = t[p].R;
  int M = (L + R) >> 1;
  t[p].x = (ls(p) ? t[ls(p)].x : info(0, sum[M] - sum[L - 1])) 
    + (rs(p) ? t[rs(p)].x : info(0, sum[R] - sum[M]));
}

void pp (int p) {
  t[p].lz ^= 1;
  swap(t[p].x.a, t[p].x.b);
}

int New (int L, int R) {
  ++tot;
  t[tot].x = info(0, sum[R] - sum[L - 1]);
  t[tot].L = L;
  t[tot].R = R;
  return tot;
}

int cp (int p) {
  t[++tot] = t[p];
  return tot;
}

void down (int &p) {
  if (t[p].lz) {
    int L = t[p].L, R = t[p].R;
    int M = (L + R) >> 1;
    p = cp(p);
    ls(p) = ls(p) ? cp(ls(p)) : New(L, M);
    rs(p) = rs(p) ? cp(rs(p)) : New(M + 1, R);
    pp(ls(p));
    pp(rs(p));
    t[p].lz = false;
  }
}

void flp (int ql, int qr, int l, int r, int &p) {
  p = p ? cp(p) : New(l, r);
  if (ql <= l && r <= qr) {
    pp(p);
    return;
  }
  down(p);
  if (ql <= m) {
    flp(ql, qr, l, m, ls(p));
  }
  if (m < qr) {
    flp(ql, qr, m + 1, r, rs(p));
  }
  up(p);
}

bool cmp (int l, int r, int p, int q) {
  if (l == r) {
    return t[p].x.a > t[q].x.a;
  }
  down(p);
  down(q);
  info x = ls(p) ? t[ls(p)].x : info(0, sum[m] - sum[l - 1]);
  info y = ls(q) ? t[ls(q)].x : info(0, sum[m] - sum[l - 1]);
  if (x.a == y.a) {
    return cmp(m + 1, r, rs(p), rs(q));
  } else {
    return cmp(l, m, ls(p), ls(q));
  }
}

#undef m
#undef ls
#undef rs

void main () {
  L (i, 1, n) {
    sum[i] = sum[i - 1] + rng();
  }
  L (i, 1, m) {
    lis[a[i].x1].eb(i);
    lis[a[i].x2 + 1].eb(i);
  }
  L (i, 1, n) {
    for (int k : lis[i]) {
      flp(a[k].y1, a[k].y2, 1, n, R);
    }
    rt[i] = R;
  }
  L (i, 1, n) {
    p[i] = i;
  }
  sort(p + 1, p + n + 1, [] (int x, int y) {
    return cmp(1, n, rt[x], rt[y]);
  });
  L (i, 1, n) {
    q[p[i]] = i;
  }
}

}

namespace F2 {

LL cur;

__gnu_pbds::priority_queue<int, greater<int>> Q[N];

struct DSU {
  int p[N], sz[N], L[N], R[N], c[N];

  void init () {
    L (i, 1, n) {
      p[i] = i, sz[i] = 1;
      L[i] = i, R[i] = i;
    }
  }

  int gf (int x) {
    return x == p[x] ? x : p[x] = gf(p[x]);
  }
  
  void mdy (int x, int y) {
    cur += y * max(0LL, (LL)sz[x] * c[x] - 1);
  }

  int unite (int x, int y) {
    x = gf(x), y = gf(y);
    if (sz[x] > sz[y]) {
      swap(x, y);
    }
    mdy(x, -1);
    mdy(y, -1);
    sz[y] += sz[x];
    c[y] += c[x];
    mdy(y, 1);
    p[x] = y;
    L[y] = min(L[y], L[x]);
    R[y] = max(R[y], R[x]);
    Q[y].join(Q[x]);
    return y;
  }

  void add (int x) {
    mdy(x, -1);
    ++c[x];
    mdy(x, 1);
  }
} S;

#define ls p << 1
#define rs p << 1 | 1
#define m ((l + r) >> 1)

struct inter {
  int l, r;
  inter (int a = N, int b = 0) : l(a), r(b) {}
  inter operator + (const inter &rhs) const {
    return inter(min(l, rhs.l), max(r, rhs.r));
  }
};

struct info {
  inter a, b;
  info (inter _a = inter(), inter _b = inter()) : a(_a), b(_b) {}
  info operator + (const info &rhs) const {
    return info(a + rhs.a, b + rhs.b);
  }
} t[N << 2];

bool lz[N << 2];

void up (int p) {
  t[p] = t[ls] + t[rs];
}

void pp (int p) {
  lz[p] ^= 1;
  swap(t[p].a, t[p].b);
}

void down (int p) {
  if (lz[p]) {
    pp(ls);
    pp(rs);
    lz[p] = false;
  }
}

void bld (int l, int r, int p) {
  if (l == r) {
    t[p].a = inter(q[l], q[l]);
    return;
  }
  bld(l, m, ls);
  bld(m + 1, r, rs);
  up(p);
}

void flp (int ql, int qr, int l, int r, int p) {
  if (ql <= l && r <= qr) {
    pp(p);
    return;
  }
  down(p);
  if (ql <= m) {
    flp(ql, qr, l, m, ls);
  }
  if (m < qr) {
    flp(ql, qr, m + 1, r, rs);
  }
  up(p);
}

#undef m
#undef ls
#undef rs

void main () {
  S.init();
  bld(1, n, 1);
  L (i, 1, m) {
    lis[a[i].y1].eb(i);
    lis[a[i].y2 + 1].eb(i);
  }
  L (i, 1, n) {
    for (int k : lis[i]) {
      flp(a[k].x1, a[k].x2, 1, n, 1);
    }
    int l = t[1].a.l, r = t[1].b.r;
    if (l < r) {
      int u = S.gf(l);
      while (S.R[u] < r) {
        u = S.unite(u, S.R[u] + 1);
      }
      S.add(u);
      while (!Q[u].empty() && S.R[u] >= Q[u].top()) {
        S.add(u);
        Q[u].pop();
      }
    } else {
      r = S.gf(r), l = S.gf(l);
      if (l == r) {
        S.add(l);
      } else {
        Q[r].push(l);
      }
    }
    if (i < n && !typ) {
      continue;
    }
    cout << (LL)i * n - cur << " \n"[i == n];
  }
}

}

int main () {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m >> typ;
  L (i, 1, m) {
    cin >> a[i].x1 >> a[i].x2 >> a[i].y1 >> a[i].y2;
  }
  F1::main();
  L (i, 1, n + 1) {
    lis[i].clear();
  }
  F2::main();
}
// I love WHQ!

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Memory Limit Exceeded

Test #1:

score: 0
Memory Limit Exceeded

input:

4 1000 0
2 3 1 2
1 3 1 3
1 2 1 2
1 2 3 4
1 4 2 4
1 3 1 2
1 4 1 2
1 3 1 4
3 3 2 3
1 2 2 4
4 4 1 3
3 3 3 4
3 4 3 4
2 3 1 1
1 2 2 4
1 4 3 4
3 4 1 2
1 2 2 3
3 4 3 3
1 2 4 4
4 4 2 4
1 4 1 1
1 1 1 3
2 3 2 3
1 1 2 4
2 3 2 4
3 3 1 4
3 3 3 3
1 3 3 3
2 3 2 4
3 3 2 2
1 3 2 4
1 3 1 2
3 4 1 2
2 3 1 3
1 1 1 2
1 2...

output:

1

result:


Subtask #2:

score: 0
Memory Limit Exceeded

Test #4:

score: 0
Memory Limit Exceeded

input:

50 200000 0
1 45 2 6
29 44 2 6
31 37 2 50
2 37 1 19
7 13 8 38
38 46 19 38
10 30 30 46
22 42 1 45
5 35 24 27
10 36 19 31
20 47 17 35
7 9 23 42
15 26 31 42
7 8 7 42
1 26 33 48
2 5 30 36
17 44 21 44
5 44 24 36
19 47 15 17
29 36 2 42
31 34 11 41
9 24 12 30
30 43 8 20
2 12 13 20
11 12 10 15
14 22 3 29
2 ...

output:

1

result:


Subtask #3:

score: 0
Memory Limit Exceeded

Test #8:

score: 0
Memory Limit Exceeded

input:

5000 200000 0
1438 2561 3478 4930
1740 4634 87 3003
590 3275 1376 1681
2035 2793 2004 4945
567 3159 550 4470
61 3039 3431 3519
2654 3834 3460 4960
591 3560 409 443
345 2599 746 2891
1288 4570 1577 4402
249 377 1951 4534
2411 2455 294 1192
1679 3153 1645 4259
1735 1856 601 668
477 4881 411 2094
424 1...

output:

1

result:


Subtask #4:

score: 0
Memory Limit Exceeded

Test #14:

score: 0
Memory Limit Exceeded

input:

5000 200000 1
565 4401 1659 1826
429 1640 2999 3495
572 3994 9 3863
3844 4284 2307 3144
1054 1943 358 2592
727 4248 29 1171
1685 2392 4559 4929
1149 2787 1204 1947
2349 2619 405 998
1910 2786 25 1275
912 3475 4384 4387
3822 4895 1849 4548
3082 4749 3457 4220
3174 4885 117 1085
2517 3919 4325 4869
17...

output:

5000 5653 3715 1781 1031 823 540 185 190 71 56 61 66 71 76 81 86 91 96 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

result:


Subtask #5:

score: 0
Memory Limit Exceeded

Test #21:

score: 0
Memory Limit Exceeded

input:

200000 200000 1
1 2 1 6
3 4 1 1
5 6 1 5
7 8 1 3
9 10 1 3
11 12 1 6
13 14 1 5
15 16 1 6
17 18 1 6
19 20 1 1
21 22 1 4
23 24 1 5
25 26 1 2
27 28 1 4
29 30 1 3
31 32 1 2
33 34 1 6
35 36 1 3
37 38 1 2
39 40 1 2
41 42 1 3
43 44 1 1
45 46 1 2
47 48 1 3
49 50 1 4
51 52 1 5
53 54 1 1
55 56 1 5
57 58 1 5
59 ...

output:

200000 400000 532619 597930 598645 533081 733081 933081 631687 831687 1031687 1064777 1264777 1464777 1664777 1864777 1897874 2097874 2297874 2330961 2530961 2730961 2764057 2964057 3164057 3364057 3564057 3764057 3964057 3997153 4197153 4397153 4597153 4797153 4997153 5197153 5230249 5430249 563024...

result:


Subtask #6:

score: 0
Memory Limit Exceeded

Test #28:

score: 0
Memory Limit Exceeded

input:

200000 200000 0
91264 123676 6826 154505
121351 188051 108158 131448
65413 163961 26771 116304
93852 110556 34929 187363
31794 142162 33578 38712
26574 67763 178013 197235
46436 146042 95 122860
11683 50463 60177 195245
60862 194711 37817 97212
144366 176271 113551 171098
120095 170517 73555 167299
...

output:


result:


Subtask #7:

score: 0
Memory Limit Exceeded

Test #37:

score: 0
Memory Limit Exceeded

input:

100000 200000 1
1 22878 1 2
1 7957 3 4
1 21779 5 6
1 34321 7 8
1 41692 9 10
1 49473 11 12
1 10254 13 14
1 43995 15 16
1 46975 17 18
1 668 19 20
1 25996 21 22
1 24975 23 24
1 43259 25 26
1 4174 27 28
1 39330 29 30
1 35462 31 32
1 27523 33 34
1 5574 35 36
1 47955 37 38
1 47013 39 40
1 3846 41 42
1 276...

output:

100000 200000 195499 260665 271141 281125 247871 244233 167815 186461 119505 130369 136332 146819 139966 149297 158628 167959 38799 40841 42883 44925 46967 49009 51051 53093 55135 57177 59219 61261 63303 65345 67387 69429 71471 73513 75555 77597 79639 81681 83723 85765 87807 89849 82711 75257 69937 ...

result: