답안 #585217

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
585217 2022-06-28T12:41:05 Z GioChkhaidze Progression (NOI20_progression) C++14
100 / 100
954 ms 81152 KB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>

#define lf (h << 1)
#define mf ((l + r) >> 1)
#define rf ((h << 1) | 1)
#define tree int h, int l, int r 
#define left lf, l, mf
#define right rf, mf + 1, r
#define ll long long
#define f first
#define s second

using namespace std;

const int N = 3e5 + 5;

int n, m, q, L, R, id;
ll S, C, vl, a[N], b[N];

struct node {
	int ans;
	int len;
	int fr;
	int ls;
	int pr;
	int sf;
	ll add;
	ll sum;
	ll toggle;
	bool flag;
	node () {
		toggle = 0;
		flag = 0;
		sum = 0;
		ans = 0;
		len = 0;
		add = 0;
		fr = 0;
		ls = 0;
		pr = 0;
		sf = 0;
	}
};

node v[4 * N], bs;

node mrg(node a, node b) {
	node c;
	c.len = a.len + b.len;
	c.fr = a.fr, c.ls = b.ls;
	c.pr = a.pr, c.sf = b.sf;
	c.ans = max(a.ans, b.ans);
	c.sum = a.sum + b.sum;
	if (a.ls == b.fr) {
		if (a.len == c.pr) c.pr += b.pr;
		if (b.len == c.sf) c.sf += a.sf;
		c.ans = max(c.ans, a.sf + b.pr);
	}
	return c;
} 

void shift(tree) {
	if (v[h].flag) {
		//assert(v[h].add == 0);
		ll x = v[h].toggle;
		v[lf].sum = (mf - l + 1) * x, v[rf].sum = (r - mf) * x;
		v[lf].fr = v[lf].ls = v[rf].fr = v[rf].ls = x;
		v[lf].ans = v[lf].pr = v[lf].sf = mf - l + 1;
		v[rf].ans = v[rf].pr = v[rf].sf = r - mf;
		v[lf].toggle = v[rf].toggle = x;
		v[lf].flag = v[rf].flag = true;
		v[lf].add = v[rf].add = false; 
		v[h].toggle = v[h].flag = 0;
		return ;
	}

	if (v[h].add) {
		ll x = v[h].add;
		//assert(v[h].flag == 0);
		//assert(v[h].toggle == 0);
		v[lf].fr += x, v[lf].ls += x;
		v[rf].fr += x, v[rf].ls += x;
		v[lf].sum += (mf - l + 1) * x, v[rf].sum += (r - mf) * x;

		if (v[lf].flag) v[lf].toggle += v[h].add;
			else v[lf].add += v[h].add;
		
		if (v[rf].flag) v[rf].toggle += v[h].add;
			else v[rf].add += v[h].add;

		v[h].add = 0;
		return ;
	}
}

void build(tree) {
	if (l == r) {
		v[h].pr = v[h].sf = v[h].len = v[h].ans = 1;
		v[h].fr = v[h].ls = v[h].sum = b[l];
		return ;
	}
	build(left), build(right);
	v[h] = mrg(v[lf], v[rf]);
}

void up_range(tree) {
	if (R < l || r < L) return ;
	if (L <= l && r <= R) {
		v[h].fr += C, v[h].ls += C;
		v[h].sum += (r - l + 1) * C;
		if (v[h].flag)  v[h].toggle += C;
			else v[h].add += C;
		return;
	}
	shift(h, l, r);
	up_range(left);
	up_range(right);
	v[h] = mrg(v[lf], v[rf]);
}

void up_dot(tree) {
	if (l == r) {
		v[h].pr = v[h].sf = v[h].len = v[h].ans = 1;
		v[h].fr = v[h].ls = v[h].sum = b[l];
		return;
	}
	shift(h, l, r);
	if (id <= mf) {
		up_dot(left);
	}
		else {
		up_dot(right);
	}
	v[h] = mrg(v[lf], v[rf]);
}

void up_to_range(tree) {
	if (r < L || R < l) return ;
	if (L <= l && r <= R) {
		v[h].ans = v[h].pr = v[h].sf = r - l + 1;
		v[h].toggle = v[h].fr = v[h].ls = C;
		v[h].sum = (r - l + 1) * C;
		v[h].flag = true;
		v[h].add = 0;
		return;
	}
	shift(h, l, r);
	up_to_range(left);
	up_to_range(right);
	v[h] = mrg(v[lf], v[rf]);
}

ll get_avl(tree, int id) {
	if (r < 1 || id < l) return 0;
	if (1 <= l && r <= id) return v[h].sum;
	shift(h, l, r);
	return get_avl(left, id) + get_avl(right, id);
}

ll get_vl(tree) {
	if (l == r) return v[h].fr;
	shift(h, l, r);
	if (id <= mf) {
		return get_vl(left);
	}
	return get_vl(right);
}

node get(tree) {
	if (r < L || R < l) return bs;
	if (L <= l && r <= R) return v[h];
	shift(h, l, r);
	return mrg(get(left), get(right));
}

ll Avl(int x) {
	return a[1] + get_avl(1, 1, m, x - 1);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> q;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		if (1 < i) {
			b[i - 1] = a[i] - a[i - 1];
		} 
	}

	m = n + 1;
	build(1, 1, m);
	for (int i = 1; i <= q; ++i) {
		int tp;
		cin >> tp >> L >> R;
		if (tp == 1) {
			cin >> S >> C;
			if (L == 1) a[1] += S;
			--R, up_range(1, 1, m), ++R;
			if (1 < L) {
				id = L - 1;
				vl = get_vl(1, 1, m);
				b[id] = vl + S;
				up_dot(1, 1, m);
			}

			if (R < n) {
				id = R;
				vl = get_vl(1 , 1, m);
				b[id] = vl - (S + (R - L) * C); 
				up_dot(1, 1, m);
			}
		}
			else
		if (tp == 2) {
			cin >> S >> C;
			if (R < n) {
				id = R;
				b[id] = Avl(id + 1) - (S + (R - L) * C); 
				up_dot(1, 1, m);
			}

			--R, up_to_range(1, 1, m), ++R;

			if (1 < L) {
				id = L - 1;
				b[id] = S - Avl(id); 
				up_dot(1, 1, m);
			}

			if (L == 1) a[1] = S;	
		}
			else
		if (tp == 3) {
			--R; cout << get(1 , 1, m).ans + 1 << "\n";
		}
	}
}

/*
 S + (i − L) × C.

 S + i * C - L * C

 (S - L * C) + i * C

b[i] = a[i + 1] - a[i]
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 235 ms 71356 KB Output is correct
2 Correct 130 ms 66360 KB Output is correct
3 Correct 125 ms 66276 KB Output is correct
4 Correct 126 ms 66332 KB Output is correct
5 Correct 121 ms 66452 KB Output is correct
6 Correct 123 ms 66432 KB Output is correct
7 Correct 139 ms 66300 KB Output is correct
8 Correct 31 ms 65996 KB Output is correct
9 Correct 28 ms 65996 KB Output is correct
10 Correct 27 ms 66076 KB Output is correct
11 Correct 230 ms 71376 KB Output is correct
12 Correct 231 ms 71324 KB Output is correct
13 Correct 228 ms 71588 KB Output is correct
14 Correct 295 ms 71608 KB Output is correct
15 Correct 231 ms 71620 KB Output is correct
16 Correct 228 ms 71284 KB Output is correct
17 Correct 232 ms 71232 KB Output is correct
18 Correct 232 ms 71268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 65992 KB Output is correct
2 Correct 28 ms 66036 KB Output is correct
3 Correct 29 ms 65980 KB Output is correct
4 Correct 27 ms 66004 KB Output is correct
5 Correct 28 ms 65996 KB Output is correct
6 Correct 27 ms 66004 KB Output is correct
7 Correct 28 ms 66092 KB Output is correct
8 Correct 28 ms 66004 KB Output is correct
9 Correct 28 ms 66040 KB Output is correct
10 Correct 28 ms 66036 KB Output is correct
11 Correct 29 ms 66052 KB Output is correct
12 Correct 27 ms 66108 KB Output is correct
13 Correct 28 ms 66012 KB Output is correct
14 Correct 29 ms 66064 KB Output is correct
15 Correct 30 ms 66148 KB Output is correct
16 Correct 36 ms 66004 KB Output is correct
17 Correct 28 ms 65996 KB Output is correct
18 Correct 29 ms 65988 KB Output is correct
19 Correct 29 ms 66048 KB Output is correct
20 Correct 28 ms 65976 KB Output is correct
21 Correct 28 ms 66004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 279 ms 71688 KB Output is correct
2 Correct 119 ms 66672 KB Output is correct
3 Correct 114 ms 66616 KB Output is correct
4 Correct 105 ms 66596 KB Output is correct
5 Correct 125 ms 66640 KB Output is correct
6 Correct 116 ms 66692 KB Output is correct
7 Correct 129 ms 66764 KB Output is correct
8 Correct 29 ms 66048 KB Output is correct
9 Correct 28 ms 66024 KB Output is correct
10 Correct 28 ms 66072 KB Output is correct
11 Correct 290 ms 71448 KB Output is correct
12 Correct 271 ms 71800 KB Output is correct
13 Correct 309 ms 71504 KB Output is correct
14 Correct 310 ms 71552 KB Output is correct
15 Correct 277 ms 71712 KB Output is correct
16 Correct 309 ms 72172 KB Output is correct
17 Correct 297 ms 72140 KB Output is correct
18 Correct 301 ms 72300 KB Output is correct
19 Correct 283 ms 71408 KB Output is correct
20 Correct 281 ms 71392 KB Output is correct
21 Correct 269 ms 71432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 573 ms 71020 KB Output is correct
2 Correct 160 ms 66240 KB Output is correct
3 Correct 175 ms 69372 KB Output is correct
4 Correct 162 ms 69400 KB Output is correct
5 Correct 166 ms 69432 KB Output is correct
6 Correct 172 ms 69428 KB Output is correct
7 Correct 172 ms 69448 KB Output is correct
8 Correct 28 ms 65980 KB Output is correct
9 Correct 31 ms 65980 KB Output is correct
10 Correct 31 ms 66024 KB Output is correct
11 Correct 621 ms 77392 KB Output is correct
12 Correct 581 ms 80660 KB Output is correct
13 Correct 594 ms 77400 KB Output is correct
14 Correct 586 ms 77356 KB Output is correct
15 Correct 566 ms 80592 KB Output is correct
16 Correct 603 ms 80732 KB Output is correct
17 Correct 611 ms 80608 KB Output is correct
18 Correct 595 ms 80768 KB Output is correct
19 Correct 619 ms 80580 KB Output is correct
20 Correct 589 ms 80600 KB Output is correct
21 Correct 579 ms 80528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 279 ms 71688 KB Output is correct
2 Correct 119 ms 66672 KB Output is correct
3 Correct 114 ms 66616 KB Output is correct
4 Correct 105 ms 66596 KB Output is correct
5 Correct 125 ms 66640 KB Output is correct
6 Correct 116 ms 66692 KB Output is correct
7 Correct 129 ms 66764 KB Output is correct
8 Correct 29 ms 66048 KB Output is correct
9 Correct 28 ms 66024 KB Output is correct
10 Correct 28 ms 66072 KB Output is correct
11 Correct 290 ms 71448 KB Output is correct
12 Correct 271 ms 71800 KB Output is correct
13 Correct 309 ms 71504 KB Output is correct
14 Correct 310 ms 71552 KB Output is correct
15 Correct 277 ms 71712 KB Output is correct
16 Correct 309 ms 72172 KB Output is correct
17 Correct 297 ms 72140 KB Output is correct
18 Correct 301 ms 72300 KB Output is correct
19 Correct 283 ms 71408 KB Output is correct
20 Correct 281 ms 71392 KB Output is correct
21 Correct 269 ms 71432 KB Output is correct
22 Correct 656 ms 71036 KB Output is correct
23 Correct 163 ms 66252 KB Output is correct
24 Correct 171 ms 66348 KB Output is correct
25 Correct 170 ms 66368 KB Output is correct
26 Correct 167 ms 66328 KB Output is correct
27 Correct 183 ms 66340 KB Output is correct
28 Correct 166 ms 66308 KB Output is correct
29 Correct 30 ms 65996 KB Output is correct
30 Correct 29 ms 65972 KB Output is correct
31 Correct 28 ms 66036 KB Output is correct
32 Correct 673 ms 71144 KB Output is correct
33 Correct 706 ms 71144 KB Output is correct
34 Correct 695 ms 71164 KB Output is correct
35 Correct 659 ms 71152 KB Output is correct
36 Correct 558 ms 71504 KB Output is correct
37 Correct 543 ms 71480 KB Output is correct
38 Correct 541 ms 71368 KB Output is correct
39 Correct 704 ms 71048 KB Output is correct
40 Correct 687 ms 71380 KB Output is correct
41 Correct 695 ms 71136 KB Output is correct
42 Correct 681 ms 71252 KB Output is correct
43 Correct 678 ms 71276 KB Output is correct
44 Correct 658 ms 71180 KB Output is correct
45 Correct 679 ms 71104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 235 ms 71356 KB Output is correct
2 Correct 130 ms 66360 KB Output is correct
3 Correct 125 ms 66276 KB Output is correct
4 Correct 126 ms 66332 KB Output is correct
5 Correct 121 ms 66452 KB Output is correct
6 Correct 123 ms 66432 KB Output is correct
7 Correct 139 ms 66300 KB Output is correct
8 Correct 31 ms 65996 KB Output is correct
9 Correct 28 ms 65996 KB Output is correct
10 Correct 27 ms 66076 KB Output is correct
11 Correct 230 ms 71376 KB Output is correct
12 Correct 231 ms 71324 KB Output is correct
13 Correct 228 ms 71588 KB Output is correct
14 Correct 295 ms 71608 KB Output is correct
15 Correct 231 ms 71620 KB Output is correct
16 Correct 228 ms 71284 KB Output is correct
17 Correct 232 ms 71232 KB Output is correct
18 Correct 232 ms 71268 KB Output is correct
19 Correct 29 ms 65992 KB Output is correct
20 Correct 28 ms 66036 KB Output is correct
21 Correct 29 ms 65980 KB Output is correct
22 Correct 27 ms 66004 KB Output is correct
23 Correct 28 ms 65996 KB Output is correct
24 Correct 27 ms 66004 KB Output is correct
25 Correct 28 ms 66092 KB Output is correct
26 Correct 28 ms 66004 KB Output is correct
27 Correct 28 ms 66040 KB Output is correct
28 Correct 28 ms 66036 KB Output is correct
29 Correct 29 ms 66052 KB Output is correct
30 Correct 27 ms 66108 KB Output is correct
31 Correct 28 ms 66012 KB Output is correct
32 Correct 29 ms 66064 KB Output is correct
33 Correct 30 ms 66148 KB Output is correct
34 Correct 36 ms 66004 KB Output is correct
35 Correct 28 ms 65996 KB Output is correct
36 Correct 29 ms 65988 KB Output is correct
37 Correct 29 ms 66048 KB Output is correct
38 Correct 28 ms 65976 KB Output is correct
39 Correct 28 ms 66004 KB Output is correct
40 Correct 279 ms 71688 KB Output is correct
41 Correct 119 ms 66672 KB Output is correct
42 Correct 114 ms 66616 KB Output is correct
43 Correct 105 ms 66596 KB Output is correct
44 Correct 125 ms 66640 KB Output is correct
45 Correct 116 ms 66692 KB Output is correct
46 Correct 129 ms 66764 KB Output is correct
47 Correct 29 ms 66048 KB Output is correct
48 Correct 28 ms 66024 KB Output is correct
49 Correct 28 ms 66072 KB Output is correct
50 Correct 290 ms 71448 KB Output is correct
51 Correct 271 ms 71800 KB Output is correct
52 Correct 309 ms 71504 KB Output is correct
53 Correct 310 ms 71552 KB Output is correct
54 Correct 277 ms 71712 KB Output is correct
55 Correct 309 ms 72172 KB Output is correct
56 Correct 297 ms 72140 KB Output is correct
57 Correct 301 ms 72300 KB Output is correct
58 Correct 283 ms 71408 KB Output is correct
59 Correct 281 ms 71392 KB Output is correct
60 Correct 269 ms 71432 KB Output is correct
61 Correct 573 ms 71020 KB Output is correct
62 Correct 160 ms 66240 KB Output is correct
63 Correct 175 ms 69372 KB Output is correct
64 Correct 162 ms 69400 KB Output is correct
65 Correct 166 ms 69432 KB Output is correct
66 Correct 172 ms 69428 KB Output is correct
67 Correct 172 ms 69448 KB Output is correct
68 Correct 28 ms 65980 KB Output is correct
69 Correct 31 ms 65980 KB Output is correct
70 Correct 31 ms 66024 KB Output is correct
71 Correct 621 ms 77392 KB Output is correct
72 Correct 581 ms 80660 KB Output is correct
73 Correct 594 ms 77400 KB Output is correct
74 Correct 586 ms 77356 KB Output is correct
75 Correct 566 ms 80592 KB Output is correct
76 Correct 603 ms 80732 KB Output is correct
77 Correct 611 ms 80608 KB Output is correct
78 Correct 595 ms 80768 KB Output is correct
79 Correct 619 ms 80580 KB Output is correct
80 Correct 589 ms 80600 KB Output is correct
81 Correct 579 ms 80528 KB Output is correct
82 Correct 656 ms 71036 KB Output is correct
83 Correct 163 ms 66252 KB Output is correct
84 Correct 171 ms 66348 KB Output is correct
85 Correct 170 ms 66368 KB Output is correct
86 Correct 167 ms 66328 KB Output is correct
87 Correct 183 ms 66340 KB Output is correct
88 Correct 166 ms 66308 KB Output is correct
89 Correct 30 ms 65996 KB Output is correct
90 Correct 29 ms 65972 KB Output is correct
91 Correct 28 ms 66036 KB Output is correct
92 Correct 673 ms 71144 KB Output is correct
93 Correct 706 ms 71144 KB Output is correct
94 Correct 695 ms 71164 KB Output is correct
95 Correct 659 ms 71152 KB Output is correct
96 Correct 558 ms 71504 KB Output is correct
97 Correct 543 ms 71480 KB Output is correct
98 Correct 541 ms 71368 KB Output is correct
99 Correct 704 ms 71048 KB Output is correct
100 Correct 687 ms 71380 KB Output is correct
101 Correct 695 ms 71136 KB Output is correct
102 Correct 681 ms 71252 KB Output is correct
103 Correct 678 ms 71276 KB Output is correct
104 Correct 658 ms 71180 KB Output is correct
105 Correct 679 ms 71104 KB Output is correct
106 Correct 826 ms 81152 KB Output is correct
107 Correct 203 ms 69516 KB Output is correct
108 Correct 209 ms 69496 KB Output is correct
109 Correct 196 ms 69452 KB Output is correct
110 Correct 29 ms 65996 KB Output is correct
111 Correct 30 ms 66124 KB Output is correct
112 Correct 30 ms 65996 KB Output is correct
113 Correct 712 ms 80132 KB Output is correct
114 Correct 687 ms 80224 KB Output is correct
115 Correct 728 ms 80084 KB Output is correct
116 Correct 721 ms 79972 KB Output is correct
117 Correct 954 ms 81020 KB Output is correct
118 Correct 752 ms 79964 KB Output is correct
119 Correct 756 ms 79948 KB Output is correct
120 Correct 357 ms 78696 KB Output is correct
121 Correct 397 ms 78632 KB Output is correct
122 Correct 420 ms 78512 KB Output is correct
123 Correct 332 ms 77768 KB Output is correct
124 Correct 367 ms 77704 KB Output is correct
125 Correct 297 ms 77732 KB Output is correct
126 Correct 798 ms 77824 KB Output is correct
127 Correct 794 ms 77944 KB Output is correct
128 Correct 867 ms 81120 KB Output is correct
129 Correct 777 ms 77700 KB Output is correct
130 Correct 679 ms 77676 KB Output is correct
131 Correct 638 ms 77720 KB Output is correct
132 Correct 601 ms 77644 KB Output is correct
133 Correct 938 ms 81032 KB Output is correct
134 Correct 832 ms 81012 KB Output is correct
135 Correct 793 ms 81140 KB Output is correct
136 Correct 205 ms 69452 KB Output is correct
137 Correct 195 ms 69516 KB Output is correct
138 Correct 197 ms 69452 KB Output is correct