QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#644727#9465. 基础 01 练习题JWRuixi20 1835ms548500kbC++205.8kb2024-10-16 15:16:342024-10-16 15:16:35

Judging History

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

  • [2024-10-16 15:16:35]
  • 评测
  • 测评结果:20
  • 用时:1835ms
  • 内存:548500kb
  • [2024-10-16 15:16:34]
  • 提交

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 << 6];

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: 5
Accepted

Test #1:

score: 5
Accepted
time: 23ms
memory: 521800kb

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:

ok 1 number(s): "1"

Test #2:

score: 5
Accepted
time: 11ms
memory: 524460kb

input:

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

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 5
Accepted
time: 15ms
memory: 521096kb

input:

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

output:

5

result:

ok 1 number(s): "5"

Subtask #2:

score: 0
Wrong Answer

Test #4:

score: 10
Accepted
time: 159ms
memory: 526464kb

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:

ok 1 number(s): "1"

Test #5:

score: 10
Accepted
time: 32ms
memory: 521712kb

input:

50 70 0
1 50 1 50
24 50 1 1
50 50 2 2
34 50 3 3
36 50 4 4
32 50 5 5
18 50 6 6
12 50 7 7
6 50 8 8
28 50 9 9
38 50 10 10
4 50 11 11
26 50 12 12
14 50 13 13
46 50 14 14
2 50 15 15
8 50 16 16
44 50 17 17
10 50 18 18
30 50 19 19
22 50 20 20
48 50 21 21
20 50 22 22
42 50 23 23
40 50 24 24
16 50 25 25
16 5...

output:

2280

result:

ok 1 number(s): "2280"

Test #6:

score: 10
Accepted
time: 20ms
memory: 521780kb

input:

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

output:

339

result:

ok 1 number(s): "339"

Test #7:

score: 0
Wrong Answer
time: 19ms
memory: 526208kb

input:

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

output:

1

result:

wrong answer 1st numbers differ - expected: '51', found: '1'

Subtask #3:

score: 0
Runtime Error

Test #8:

score: 0
Runtime Error

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:


result:


Subtask #4:

score: 0
Runtime Error

Test #14:

score: 0
Runtime Error

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:


result:


Subtask #5:

score: 15
Accepted

Test #21:

score: 15
Accepted
time: 1575ms
memory: 548456kb

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:

ok 200000 numbers

Test #22:

score: 15
Accepted
time: 1254ms
memory: 542900kb

input:

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

output:

200000 400000 599992 799992 999981 1199971 1399971 1599938 1799938 1999921 2199911 2399901 2599901 2799901 2999891 3199869 3399858 3599847 3799806 3999793 4199686 4399686 4599671 4799656 4999593 5199551 5399533 5599515 5799469 5999421 6199421 6399371 6599371 6799319 6999137 7199044 7399015 7598986 7...

result:

ok 200000 numbers

Test #23:

score: 15
Accepted
time: 1254ms
memory: 543704kb

input:

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

output:

200000 400000 600000 800000 1000000 1199971 1399965 1599952 1799945 1999929 2199901 2399869 2599833 2799819 2999819 3199819 3399777 3599746 3799729 3999712 4199695 4399659 4599641 4799602 4999539 5199518 5399497 5599476 5799476 5999476 6199429 6399353 6599301 6799276 6999221 7199195 7399137 7599110 ...

result:

ok 200000 numbers

Test #24:

score: 15
Accepted
time: 1609ms
memory: 548500kb

input:

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

output:

200000 244003 133246 133117 111726 66913 1 1 200001 200001 400001 400001 600001 800001 1000001 1200001 1400001 1400001 1400001 1600001 1800001 1800001 2000001 2200001 2400001 2600001 2600001 2600001 2800001 3000001 3000001 3000001 3200001 3200001 3400001 3600001 3600001 3800001 4000001 4000001 40000...

result:

ok 200000 numbers

Test #25:

score: 15
Accepted
time: 1835ms
memory: 544040kb

input:

200000 200000 1
62179 62180 166600 166600
168902 168904 109106 109107
71739 71741 40856 40856
68155 68155 50355 50355
82427 82427 131433 131435
134495 134497 97523 97524
100523 100523 163640 163642
103078 103078 39321 39321
75997 75997 52778 52780
141945 141946 67489 67489
20781 20782 198096 198098
...

output:

200000 399993 599993 799980 999965 1199946 1399935 1599889 1799873 1999848 2199848 2399848 2599801 2799801 2999801 3199759 3399759 3599725 3799611 3999581 4199551 4399457 4599372 4799263 4999165 5199061 5399014 5598923 5798828 5998828 6198633 6398501 6598311 6798165 6998013 7197942 7397721 7597645 7...

result:

ok 200000 numbers

Test #26:

score: 15
Accepted
time: 1751ms
memory: 544100kb

input:

200000 200000 1
172635 172635 165118 165120
182060 182062 140709 140711
79621 79622 120595 120597
22131 22132 38357 38357
15637 15637 73583 73583
163025 163027 90579 90579
98127 98129 186936 186938
15578 15580 67768 67769
170985 170986 105541 105542
166284 166285 199715 199715
179347 179347 86139 86...

output:

200000 400000 600000 799989 999965 1199941 1399911 1599889 1799849 1999794 2199771 2399771 2599715 2799677 2999611 3199611 3399511 3599416 3799345 3999270 4199227 4399070 4598981 4798867 4998813 5198713 5398585 5598451 5798207 5998057 6197985 6397826 6597826 6797691 6997521 7197377 7397377 7597163 7...

result:

ok 200000 numbers

Test #27:

score: 15
Accepted
time: 1816ms
memory: 544048kb

input:

200000 200000 1
192777 192779 177750 177752
143767 143769 170842 170843
26652 26654 75434 75435
43426 43427 188344 188345
139929 139929 172505 172506
176663 176665 58244 58246
32815 32815 193800 193801
148127 148127 103366 103368
136791 136793 152591 152591
33978 33979 63334 63334
108117 108117 1561...

output:

200000 400000 599993 799965 999946 1199929 1399917 1599881 1799821 1999801 2199737 2399653 2599533 2799469 2999356 3199281 3399236 3599137 3799089 3999041 4199041 4399041 4599041 4799041 4998972 5198879 5398713 5598657 5798551 5998389 6198327 6398181 6598087 6798087 6997991 7197800 7397729 7597394 7...

result:

ok 200000 numbers

Subtask #6:

score: 0
Runtime Error

Test #28:

score: 0
Runtime Error

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
Runtime Error

Test #37:

score: 0
Runtime Error

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:


result: