Submission #68552


ソースコード

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
#include <iostream>
#include <vector>
using namespace std;
template< typename OperatorMonoid, typename H >
struct DualSegmentTree {
int sz, height;
vector< OperatorMonoid > lazy;
const H h;
const OperatorMonoid OM0;
DualSegmentTree(int n, const H h, const OperatorMonoid &OM0) : h(h), OM0(OM0) {
sz = 1;
height = 0;
while(sz < n) sz <<= 1, height++;
lazy.assign(2 * sz, OM0);
}
inline void propagate(int k) {
if(lazy[k] != OM0) {
lazy[2 * k + 0] = h(lazy[2 * k + 0], lazy[k]);
lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
lazy[k] = OM0;
}
}
inline void thrust(int k) {
for(int i = height; i > 0; i--) propagate(k >> i);
}
void update(int a, int b, const OperatorMonoid &x) {
thrust(a += sz);
thrust(b += sz - 1);
for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
if(l & 1) lazy[l] = h(lazy[l], x), ++l;
if(r & 1) --r, lazy[r] = h(lazy[r], x);
}
}
OperatorMonoid operator[](int k) {
thrust(k += sz);
return lazy[k];
}
};
template< typename OperatorMonoid, typename H >
DualSegmentTree< OperatorMonoid, H > get_dual_segment_tree(int N, const H& h, const OperatorMonoid& OM0) {
return {N, h, OM0};
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int> rating(m);
for (int i = 0; i < m; ++i) {
cin >> rating[i];
}
auto sum = get_dual_segment_tree(n, [](auto a, auto b) { return (a + b); }, 0LL);
auto cnt = get_dual_segment_tree(n, [](auto a, auto b) { return (a + b); }, 0);
for (int i = 0; i < m; ++i) {
int l, r;
cin >> l >> r;
--l, --r;
sum.update(l, r + 1, rating[i]);
cnt.update(l, r + 1, 1);
}
for (int i = 0; i < n; ++i) {
if (cnt[i] == 0) cout << -1 << '\n';
else cout << sum[i] / cnt[i] << '\n';
}
return (0);
}

ステータス

項目 データ
問題 1526 - Contest
ユーザー名 ei1903
投稿日時 2021-09-23 09:12:58
言語 C++17
状態 Accepted
得点 3
ソースコード長 2115 Byte
最大実行時間 219 ms
最大メモリ使用量 87356 KB

セット

セット 得点 Cases
1 ALL 3 / 3 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in01.txt AC 23 ms 604 KB
1
in02.txt AC 21 ms 428 KB
1
in03.txt AC 23 ms 380 KB
1
in04.txt AC 22 ms 588 KB
1
in05.txt AC 24 ms 644 KB
1
in06.txt AC 23 ms 656 KB
1
in07.txt AC 25 ms 548 KB
1
in08.txt AC 19 ms 568 KB
1
in09.txt AC 19 ms 616 KB
1
in10.txt AC 25 ms 720 KB
1
in11.txt AC 92 ms 15836 KB
1
in12.txt AC 61 ms 5372 KB
1
in13.txt AC 81 ms 4636 KB
1
in14.txt AC 161 ms 12252 KB
1
in15.txt AC 137 ms 13952 KB
1
in16.txt AC 47 ms 9256 KB
1
in17.txt AC 205 ms 24092 KB
1
in18.txt AC 214 ms 27084 KB
1
in19.txt AC 208 ms 30076 KB
1
in20.txt AC 219 ms 32936 KB
1
in21.txt AC 209 ms 35932 KB
1
in22.txt AC 217 ms 38920 KB
1
in23.txt AC 214 ms 41908 KB
1
in24.txt AC 209 ms 44648 KB
1
in25.txt AC 214 ms 47640 KB
1
in26.txt AC 212 ms 50764 KB
1
in27.txt AC 215 ms 54140 KB
1
in28.txt AC 162 ms 57260 KB
1
in29.txt AC 157 ms 60384 KB
1
in30.txt AC 196 ms 63632 KB
1
in31.txt AC 198 ms 66876 KB
1
in32.txt AC 182 ms 69872 KB
1
in33.txt AC 160 ms 72864 KB
1
in34.txt AC 148 ms 75600 KB
1
in35.txt AC 172 ms 78080 KB
1
in36.txt AC 139 ms 80556 KB
1
in37.txt AC 138 ms 83036 KB
1
in38.txt AC 148 ms 85256 KB
1
in39.txt AC 140 ms 87356 KB
1
in40.txt AC 72 ms 75116 KB
1
sample.txt AC 18 ms 74032 KB
1