QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#311111#4780. 完美的队列hos_lyric#30 3257ms178124kbC++145.7kb2024-01-21 21:50:102024-07-04 03:20:29

Judging History

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

  • [2024-07-04 03:20:29]
  • 评测
  • 测评结果:30
  • 用时:3257ms
  • 内存:178124kb
  • [2024-01-21 21:50:10]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


//      k[0]    k[1]  ...       k[n-1]=kLim
// ------)[------)[-  ...  -)[------)[unpainted
//  v[0]    v[1]              v[n-1]
template <class K, class V> struct Painter : map<K, V> {
  const K kLim;
  Painter(K k, const V &v) : map<K, V>{{k, v}}, kLim(k) {}
  // Paint [a, b) with v, calling f(left, right, (old color)).
  template <class F> void paint(K a, K b, const V &v, F f) {
    assert(a < b); assert(b < kLim);
    auto it = this->lower_bound(a);
    if (b < it->first) {
      f(a, b, it->second);
      this->emplace(a, it->second);
      this->emplace(b, v);
    } else if (a < it->first) {
      const V va = it->second;
      K k = a;
      for (; it->first <= b; it = this->erase(it)) {
        f(k, it->first, it->second);
        k = it->first;
      }
      if (k < b) {
        f(k, b, it->second);
      }
      this->emplace(a, va);
      this->emplace(b, v);
    } else {
      ++it;
      K k = a;
      for (; it->first <= b; it = this->erase(it)) {
        f(k, it->first, it->second);
        k = it->first;
      }
      if (k < b) {
        f(k, b, it->second);
      }
      this->emplace(b, v);
    }
  }
  void paint(K a, K b, const V &v) {
    paint(a, b, v, [&](K, K, const V &) -> void {});
  }
  V get(K k) const {
    assert(k < kLim);
    return this->upper_bound(k)->second;
  }
};

////////////////////////////////////////////////////////////////////////////////


int N, Q;
vector<int> A;
vector<int> L, R, X;


namespace brute {
vector<int> run() {
  vector<vector<int>> ques(N);
  vector<int> poss(N, 0);
  for (int i = 0; i < N; ++i) {
    ques[i].assign(A[i], 0);
  }
  const int limX = *max_element(X.begin(), X.end()) + 1;
  vector<int> now(limX, 0);
  vector<int> ans(Q, 0);
  for (int q = 0; q < Q; ++q) {
    for (int i = L[q]; i < R[q]; ++i) {
      --now[ques[i][poss[i]]];
      ++now[ques[i][poss[i]] = X[q]];
      if (++poss[i] == A[i]) poss[i] = 0;
    }
    for (int x = 1; x < limX; ++x) if (now[x]) {
      ++ans[q];
    }
  }
  return ans;
}
}  // brute


namespace slow {
vector<int> run() {
  Int sumA = 0;
  for (int i = 0; i < N; ++i) sumA += A[i];
  // const int K = max<int>(sqrt(sumA / 20), 1);
const int K=1;
cerr<<"K = "<<K<<endl;
  vector<int> large;
  vector<vector<int>> small(K);
  for (int i = 0; i < N; ++i) {
    if (A[i] > K) {
      large.push_back(i);
    } else {
      for (int k = 0; k < A[i]; ++k) {
        small[k].push_back(i);
      }
    }
  }
  
  vector<vector<int>> ques(N);
  vector<int> poss(N, 0);
  for (const int i : large) {
    ques[i].assign(A[i], -1);
  }
  vector<Painter<int, int>> painters(K, Painter<int, int>(N + 1, -1));
  
  const int limX = *max_element(X.begin(), X.end()) + 1;
  vector<Int> now(limX, 0);
  int kind = 0;
  auto add = [&](int x, Int val) -> void {
    if (now[x]) --kind;
    now[x] += val;
    if (now[x]) ++kind;
  };
  
  vector<int> ans(Q, 0);
  for (int q = 0; q < Q; ++q) {
    for (const int i : large) if (L[q] <= i && i < R[q]) {
      int &x = ques[i][poss[i]];
      if (~x) add(x, -1);
      add(x = X[q], +1);
      if (++poss[i] == A[i]) poss[i] = 0;
    }
    {
      vector<pair<pair<int, int>, int>> crt;
      crt.emplace_back(make_pair(L[q], R[q]), q);
      for (int k = 0; k < K; ++k) {
        vector<pair<pair<int, int>, int>> nxt;
        for (const auto &p : crt) {
          const int l = lower_bound(small[k].begin(), small[k].end(), p.first.first) - small[k].begin();
          const int r = lower_bound(small[k].begin(), small[k].end(), p.first.second) - small[k].begin();
          if (l < r) {
            painters[k].paint(l, r, p.second, [&](int ll, int rr, int qq) -> void {
              if (~qq) {
                add(X[qq], -(rr - ll));
                nxt.emplace_back(make_pair(ll, rr), qq);
              }
            });
            add(X[p.second], +(r - l));
          }
        }
        crt.swap(nxt);
      }
    }
    ans[q] = kind;
  }
  return ans;
}
}  // slow


int main() {
  for (; ~scanf("%d%d", &N, &Q); ) {
    A.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("%d", &A[i]);
    }
    L.resize(Q);
    R.resize(Q);
    X.resize(Q);
    for (int q = 0; q < Q; ++q) {
      scanf("%d%d%d", &L[q], &R[q], &X[q]);
      --L[q];
    }
    
    vector<int> ans;
    ans = slow::run();
    for (int q = 0; q < Q; ++q) {
      printf("%d\n", ans[q]);
    }
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 65ms
memory: 24468kb

input:

5000 4999
99 36 47 78 58 58 64 12 42 54 29 56 57 32 99 21 1 6 42 97 82 8 79 92 3 56 19 41 29 59 23 34 76 34 82 20 44 51 60 73 89 65 51 65 15 87 65 70 51 26 40 95 44 62 97 81 43 13 20 81 76 64 47 95 54 56 99 62 91 63 98 58 70 60 47 97 31 74 76 70 10 30 99 33 52 100 14 65 4 6 87 4 8 1 8 87 18 70 76 43...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
10...

result:

ok 4999 numbers

Subtask #2:

score: 5
Accepted

Dependency #1:

100%
Accepted

Test #2:

score: 5
Accepted
time: 347ms
memory: 81876kb

input:

9999 10000
60 75 4 70 26 87 8 77 16 6 20 88 95 44 60 10 71 93 68 33 30 71 21 19 88 61 26 93 21 83 35 83 25 72 33 75 40 14 92 54 10 42 60 93 73 82 13 50 50 25 99 16 68 38 78 14 4 1 58 72 2 96 69 57 43 71 68 100 5 49 50 58 50 61 53 22 88 55 95 37 67 96 50 46 55 97 84 28 62 56 44 35 80 5 59 45 50 14 48...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...

result:

ok 10000 numbers

Subtask #3:

score: 5
Accepted

Dependency #2:

100%
Accepted

Test #3:

score: 5
Accepted
time: 950ms
memory: 178124kb

input:

15000 15000
8 2 78 69 72 23 22 79 69 75 63 19 90 94 45 5 1 44 53 34 80 80 26 43 9 86 85 38 71 88 90 2 22 46 60 7 14 18 77 44 5 80 80 48 9 51 38 49 7 2 73 64 67 84 44 7 53 9 84 21 90 35 69 46 5 74 27 73 78 91 10 68 50 5 98 55 17 99 99 81 38 20 99 81 91 19 87 26 71 19 49 44 70 29 5 33 21 49 75 5 79 84...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...

result:

ok 15000 numbers

Subtask #4:

score: 0
Memory Limit Exceeded

Dependency #3:

100%
Accepted

Test #4:

score: 0
Memory Limit Exceeded

input:

20000 20000
96 95 34 72 28 92 86 48 37 22 76 41 18 23 56 52 32 48 37 96 75 17 69 22 81 79 60 82 79 12 69 15 58 79 7 7 63 70 58 69 68 18 96 29 69 70 4 7 75 27 18 44 49 53 89 15 10 97 75 58 52 54 65 91 48 33 5 91 59 12 2 6 30 99 79 45 91 14 36 15 98 88 11 73 98 3 8 22 45 41 42 71 31 29 16 44 72 100 57...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...

result:


Subtask #5:

score: 5
Accepted

Test #5:

score: 5
Accepted
time: 13ms
memory: 5008kb

input:

25000 25000
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 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 ...

output:

1
2
3
4
5
5
5
3
3
4
4
4
5
4
4
5
6
7
6
6
7
8
9
6
7
8
8
7
8
9
7
8
9
10
8
8
9
10
10
11
12
12
5
6
7
8
9
4
5
6
7
5
6
7
8
6
7
8
7
8
9
10
11
10
11
12
13
13
12
12
9
10
7
8
7
8
8
6
7
8
8
9
9
10
7
8
9
9
9
10
11
10
11
12
12
13
13
14
15
16
15
15
11
4
5
6
7
8
8
9
9
8
9
9
10
11
10
8
8
8
9
9
10
10
10
6
6
7
8
9
4
5...

result:

ok 25000 numbers

Subtask #6:

score: 0
Skipped

Dependency #4:

0%

Subtask #7:

score: 5
Accepted

Test #7:

score: 5
Accepted
time: 3030ms
memory: 6360kb

input:

34999 35000
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
11
7
7
8
9
10
10
11
12
11
12
12
11
9
8
9
4
5
6
7
8
9
10
10
11
12
13
13
14
15
16
17
17
17
16
14
11
11
12
13
14
15
14
14
13
14
14
15
14
15
16
17
18
19
19
19
20
19
16
16
15
15
15
12
13
14
15
16
17
18
19
18
19
19
19
19
17
18
18
19
20
21
21
21
22
18
19
20
21
20
20
19
20
21
2...

result:

ok 35000 numbers

Subtask #8:

score: 0
Skipped

Dependency #6:

0%

Subtask #9:

score: 5
Accepted

Test #9:

score: 5
Accepted
time: 3257ms
memory: 8156kb

input:

45000 45000
10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 ...

output:

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

result:

ok 45000 numbers

Subtask #10:

score: 0
Skipped

Dependency #8:

0%

Subtask #11:

score: 0
Time Limit Exceeded

Dependency #5:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #9:

100%
Accepted

Test #11:

score: 0
Time Limit Exceeded

input:

54444 55000
3 5 10 6 4 10 10 6 2 10 5 2 6 9 10 6 5 9 3 4 7 6 9 1 1 2 6 10 5 2 6 3 10 3 4 7 3 3 3 5 9 2 2 8 6 10 6 9 1 1 3 2 6 8 9 3 10 4 10 5 6 5 7 6 9 4 7 4 10 8 5 10 1 5 8 4 4 5 9 3 9 3 2 1 2 7 5 10 3 4 6 10 4 8 6 9 6 6 6 8 8 3 3 2 9 9 7 3 8 9 4 4 3 5 10 5 10 6 7 2 10 1 1 10 6 1 6 3 7 1 8 7 9 4 5 ...

output:


result:


Subtask #12:

score: 0
Skipped

Dependency #11:

0%

Subtask #13:

score: 0
Time Limit Exceeded

Test #13:

score: 0
Time Limit Exceeded

input:

65000 65000
5 7 8 6 3 6 8 7 2 3 5 10 9 9 4 3 9 1 2 9 1 1 6 10 1 10 5 4 7 1 9 6 6 8 10 5 8 3 2 5 2 3 6 8 7 3 2 3 6 5 1 10 6 2 4 7 8 1 3 3 5 4 2 5 2 5 3 3 6 7 6 9 5 3 10 3 6 2 8 10 9 10 2 5 4 10 3 3 6 3 5 7 141 3 6 3 10 2 7 6 3 5 9 4 10 1 3 9 9 8 2 5 10 1 7 1 8 5 3 3 7 7 9 7 4 1 9 2 2 4 8 6 10 5 7 3 3...

output:


result:


Subtask #14:

score: 0
Skipped

Dependency #12:

0%

Subtask #15:

score: 0
Skipped

Dependency #13:

0%

Subtask #16:

score: 0
Skipped

Dependency #14:

0%

Subtask #17:

score: 0
Skipped

Dependency #16:

0%

Subtask #18:

score: 0
Skipped

Dependency #17:

0%

Subtask #19:

score: 0
Skipped

Dependency #18:

0%

Subtask #20:

score: 0
Skipped

Dependency #19:

0%