답안 #585389

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
585389 2022-06-28T19:29:55 Z keta_tsimakuridze Progression (NOI20_progression) C++14
100 / 100
926 ms 108440 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define f first
#define s second
#define endl "\n"
const int N = 3e5 + 5, mod = 1e9 + 7; //!
int t, d[N], a[N];
struct node {
	int L, R, len;
	pii suf, pref;
	int ans;
} tree[4 * N];
struct z {
	int k, b, t;
} lazy[4 * N];
bool eq(pii a, pii b) {
	return (min(a.s, b.s) == 1 ? 1 : a.f == b.f);
}
node merge(node a, node b) {
	node c;
	c.len = a.len + b.len;
	c.L = a.L; c.R = b.R;
	c.ans = max(a.ans, b.ans);
	c.pref = a.pref; c.suf = b.suf;
	int d = b.L - a.R;
	if(eq(a.suf, {d, 2})) {
		c.ans = max(c.ans, a.suf.s + (!eq({d, 2}, b.pref) ? 1 : b.pref.s));
	}
	if(eq(b.pref, {d, 2})) {
		c.ans = max(c.ans, b.pref.s + (!eq({d, 2}, a.suf) ? 1 : a.suf.s));
	}
	if(c.suf.s == 1) c.suf.f = d;
	if(c.pref.s == 1) c.pref.f = d;
	if(a.pref.s == a.len && eq(a.pref, {d, 2})) {
		c.pref.s += (eq({d, 2}, b.pref) ? b.pref.s : 1);
	}
	if(b.suf.s == b.len && eq(b.suf, {d, 2})) {
		c.suf.s += (eq({d, 2}, a.suf) ? a.suf.s : 1);
	}
	return c;
		
}
void build(int u,int l,int r) {
	if(l == r) {
		tree[u].L = tree[u].R = a[l];
		tree[u].ans = 1;
		tree[u].pref = {0, 1};
		tree[u].suf = {0, 1};
		tree[u].len = 1;
		return;
	}
	int mid = (l + r) / 2;
	build(2 * u, l, mid); build(2 * u + 1, mid + 1, r);
	tree[u] = merge(tree[2 * u], tree[2 * u + 1]);
//	cout << l << " " << r << " " << tree[u].ans << " " << tree[u].R << " " << tree[u].suf.f << " " << tree[u].suf.s <<endl;
 
}
void push(int u,int l,int r) {
	if(lazy[u].t) {
		tree[u].ans = r - l + 1;
		tree[u].L = lazy[u].k * l + lazy[u].b;
		tree[u].R = lazy[u].k * r + lazy[u].b;
		
		tree[u].pref.s = tree[u].suf.s = r - l + 1;
		tree[u].pref.f = tree[u].suf.f = (r == l ? 0 : lazy[u].k);
		tree[u].ans = r - l + 1;
		if(l != r) {
			lazy[2 * u].t = lazy[2 * u + 1].t = 1;
			lazy[2 * u].k = lazy[2 * u + 1].k = lazy[u].k;
			lazy[2 * u].b = lazy[2 * u + 1].b = lazy[u].b;
		}
	} else {
		tree[u].L += lazy[u].k * l + lazy[u].b;
		tree[u].R += lazy[u].k * r + lazy[u].b;
		if(tree[u].len > 1) {
			tree[u].pref.f += lazy[u].k;
			tree[u].suf.f += lazy[u].k;
		}
		if(l != r) {
			lazy[2 * u].k += lazy[u].k;
			lazy[2 * u + 1].k += lazy[u].k;
			lazy[2 * u].b += lazy[u].b;
			lazy[2 * u + 1].b += lazy[u].b;
		}		
	}
	lazy[u].k = lazy[u].b = lazy[u].t = 0;
}
void upd(int u,int st,int en,int l,int r,int k,int b,int t) {
	push(u, l, r);
	if(l > en || r < st) return;
	if(st <= l && r <= en) {			
		lazy[u].k = k;
		lazy[u].b = b;
		lazy[u].t = (t == 2);
		push(u, l, r);
		return;
	}
	int mid = (l + r) / 2;
	upd(2 * u, st, en, l, mid, k, b, t);
	upd(2 * u + 1, st, en, mid + 1, r, k, b, t);
	tree[u] = merge(tree[2 * u], tree[2 * u + 1]);
}
node get(int u,int st,int en, int l,int r) {
	push(u, l, r);
	if(st <= l && r <= en) return tree[u];
	int mid = (l + r) / 2;
	if(mid + 1 > en) return get(2 * u, st, en, l, mid);
	if(mid < st) return get(2 * u + 1, st, en, mid + 1, r);
	return merge(get(2 * u, st, en, l, mid), get(2 * u + 1, st, en, mid + 1, r));
}
 
main() {
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int n, q;
	cin >> n >> q;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	build(1, 1, n);
	for(int i = 1; i <= q; i++) {
		int t;
		cin >> t;
		if(t < 3) { 
			int l, r, s, c;
			cin >> l >> r >> s >> c; 
 
				upd(1, l, r, 1, n, c, s - l * c, t);
			
 
			continue; 
		}
		int l, r;
		cin >> l >> r;
	//	for(int j = 1; j <= n; j++) a[j] = get(1, j, 1, n);
		cout << get(1, l, r, 1, n).ans << endl;
	}
}

Compilation message

Progression.cpp:114:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  114 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 173 ms 85324 KB Output is correct
2 Correct 102 ms 77212 KB Output is correct
3 Correct 101 ms 77256 KB Output is correct
4 Correct 105 ms 77292 KB Output is correct
5 Correct 107 ms 77296 KB Output is correct
6 Correct 103 ms 77380 KB Output is correct
7 Correct 103 ms 77260 KB Output is correct
8 Correct 28 ms 75376 KB Output is correct
9 Correct 28 ms 75476 KB Output is correct
10 Correct 30 ms 75468 KB Output is correct
11 Correct 193 ms 81672 KB Output is correct
12 Correct 160 ms 81624 KB Output is correct
13 Correct 164 ms 81912 KB Output is correct
14 Correct 169 ms 82016 KB Output is correct
15 Correct 216 ms 81760 KB Output is correct
16 Correct 156 ms 81528 KB Output is correct
17 Correct 169 ms 81512 KB Output is correct
18 Correct 219 ms 81636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 75568 KB Output is correct
2 Correct 28 ms 75476 KB Output is correct
3 Correct 29 ms 75500 KB Output is correct
4 Correct 28 ms 75460 KB Output is correct
5 Correct 31 ms 75468 KB Output is correct
6 Correct 28 ms 75468 KB Output is correct
7 Correct 29 ms 75480 KB Output is correct
8 Correct 33 ms 75496 KB Output is correct
9 Correct 30 ms 75476 KB Output is correct
10 Correct 29 ms 75468 KB Output is correct
11 Correct 32 ms 75468 KB Output is correct
12 Correct 38 ms 75456 KB Output is correct
13 Correct 37 ms 75476 KB Output is correct
14 Correct 38 ms 75492 KB Output is correct
15 Correct 32 ms 75444 KB Output is correct
16 Correct 29 ms 75468 KB Output is correct
17 Correct 29 ms 75468 KB Output is correct
18 Correct 32 ms 75548 KB Output is correct
19 Correct 30 ms 75468 KB Output is correct
20 Correct 28 ms 75484 KB Output is correct
21 Correct 29 ms 75476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 477 ms 108440 KB Output is correct
2 Correct 124 ms 78124 KB Output is correct
3 Correct 121 ms 78116 KB Output is correct
4 Correct 132 ms 78144 KB Output is correct
5 Correct 136 ms 78268 KB Output is correct
6 Correct 135 ms 78264 KB Output is correct
7 Correct 125 ms 78276 KB Output is correct
8 Correct 31 ms 75392 KB Output is correct
9 Correct 32 ms 75384 KB Output is correct
10 Correct 31 ms 75432 KB Output is correct
11 Correct 578 ms 107460 KB Output is correct
12 Correct 483 ms 107768 KB Output is correct
13 Correct 487 ms 107324 KB Output is correct
14 Correct 524 ms 107268 KB Output is correct
15 Correct 376 ms 107720 KB Output is correct
16 Correct 477 ms 108076 KB Output is correct
17 Correct 513 ms 108132 KB Output is correct
18 Correct 516 ms 108044 KB Output is correct
19 Correct 440 ms 107456 KB Output is correct
20 Correct 480 ms 107444 KB Output is correct
21 Correct 382 ms 107492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 674 ms 107296 KB Output is correct
2 Correct 156 ms 78412 KB Output is correct
3 Correct 184 ms 77256 KB Output is correct
4 Correct 156 ms 77332 KB Output is correct
5 Correct 173 ms 77304 KB Output is correct
6 Correct 160 ms 77284 KB Output is correct
7 Correct 164 ms 77276 KB Output is correct
8 Correct 30 ms 75560 KB Output is correct
9 Correct 31 ms 75420 KB Output is correct
10 Correct 29 ms 75484 KB Output is correct
11 Correct 665 ms 104360 KB Output is correct
12 Correct 623 ms 104376 KB Output is correct
13 Correct 622 ms 104468 KB Output is correct
14 Correct 635 ms 104500 KB Output is correct
15 Correct 541 ms 104296 KB Output is correct
16 Correct 676 ms 104400 KB Output is correct
17 Correct 620 ms 104376 KB Output is correct
18 Correct 742 ms 104424 KB Output is correct
19 Correct 630 ms 104376 KB Output is correct
20 Correct 613 ms 104304 KB Output is correct
21 Correct 600 ms 104340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 477 ms 108440 KB Output is correct
2 Correct 124 ms 78124 KB Output is correct
3 Correct 121 ms 78116 KB Output is correct
4 Correct 132 ms 78144 KB Output is correct
5 Correct 136 ms 78268 KB Output is correct
6 Correct 135 ms 78264 KB Output is correct
7 Correct 125 ms 78276 KB Output is correct
8 Correct 31 ms 75392 KB Output is correct
9 Correct 32 ms 75384 KB Output is correct
10 Correct 31 ms 75432 KB Output is correct
11 Correct 578 ms 107460 KB Output is correct
12 Correct 483 ms 107768 KB Output is correct
13 Correct 487 ms 107324 KB Output is correct
14 Correct 524 ms 107268 KB Output is correct
15 Correct 376 ms 107720 KB Output is correct
16 Correct 477 ms 108076 KB Output is correct
17 Correct 513 ms 108132 KB Output is correct
18 Correct 516 ms 108044 KB Output is correct
19 Correct 440 ms 107456 KB Output is correct
20 Correct 480 ms 107444 KB Output is correct
21 Correct 382 ms 107492 KB Output is correct
22 Correct 837 ms 107704 KB Output is correct
23 Correct 162 ms 78316 KB Output is correct
24 Correct 164 ms 78320 KB Output is correct
25 Correct 157 ms 78344 KB Output is correct
26 Correct 158 ms 78328 KB Output is correct
27 Correct 158 ms 78320 KB Output is correct
28 Correct 164 ms 78400 KB Output is correct
29 Correct 29 ms 75428 KB Output is correct
30 Correct 35 ms 75440 KB Output is correct
31 Correct 30 ms 75396 KB Output is correct
32 Correct 862 ms 106368 KB Output is correct
33 Correct 756 ms 107632 KB Output is correct
34 Correct 874 ms 106272 KB Output is correct
35 Correct 901 ms 106508 KB Output is correct
36 Correct 790 ms 106216 KB Output is correct
37 Correct 710 ms 106256 KB Output is correct
38 Correct 693 ms 106328 KB Output is correct
39 Correct 779 ms 107920 KB Output is correct
40 Correct 821 ms 107960 KB Output is correct
41 Correct 812 ms 108088 KB Output is correct
42 Correct 868 ms 108088 KB Output is correct
43 Correct 781 ms 107924 KB Output is correct
44 Correct 773 ms 107956 KB Output is correct
45 Correct 819 ms 107732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 173 ms 85324 KB Output is correct
2 Correct 102 ms 77212 KB Output is correct
3 Correct 101 ms 77256 KB Output is correct
4 Correct 105 ms 77292 KB Output is correct
5 Correct 107 ms 77296 KB Output is correct
6 Correct 103 ms 77380 KB Output is correct
7 Correct 103 ms 77260 KB Output is correct
8 Correct 28 ms 75376 KB Output is correct
9 Correct 28 ms 75476 KB Output is correct
10 Correct 30 ms 75468 KB Output is correct
11 Correct 193 ms 81672 KB Output is correct
12 Correct 160 ms 81624 KB Output is correct
13 Correct 164 ms 81912 KB Output is correct
14 Correct 169 ms 82016 KB Output is correct
15 Correct 216 ms 81760 KB Output is correct
16 Correct 156 ms 81528 KB Output is correct
17 Correct 169 ms 81512 KB Output is correct
18 Correct 219 ms 81636 KB Output is correct
19 Correct 31 ms 75568 KB Output is correct
20 Correct 28 ms 75476 KB Output is correct
21 Correct 29 ms 75500 KB Output is correct
22 Correct 28 ms 75460 KB Output is correct
23 Correct 31 ms 75468 KB Output is correct
24 Correct 28 ms 75468 KB Output is correct
25 Correct 29 ms 75480 KB Output is correct
26 Correct 33 ms 75496 KB Output is correct
27 Correct 30 ms 75476 KB Output is correct
28 Correct 29 ms 75468 KB Output is correct
29 Correct 32 ms 75468 KB Output is correct
30 Correct 38 ms 75456 KB Output is correct
31 Correct 37 ms 75476 KB Output is correct
32 Correct 38 ms 75492 KB Output is correct
33 Correct 32 ms 75444 KB Output is correct
34 Correct 29 ms 75468 KB Output is correct
35 Correct 29 ms 75468 KB Output is correct
36 Correct 32 ms 75548 KB Output is correct
37 Correct 30 ms 75468 KB Output is correct
38 Correct 28 ms 75484 KB Output is correct
39 Correct 29 ms 75476 KB Output is correct
40 Correct 477 ms 108440 KB Output is correct
41 Correct 124 ms 78124 KB Output is correct
42 Correct 121 ms 78116 KB Output is correct
43 Correct 132 ms 78144 KB Output is correct
44 Correct 136 ms 78268 KB Output is correct
45 Correct 135 ms 78264 KB Output is correct
46 Correct 125 ms 78276 KB Output is correct
47 Correct 31 ms 75392 KB Output is correct
48 Correct 32 ms 75384 KB Output is correct
49 Correct 31 ms 75432 KB Output is correct
50 Correct 578 ms 107460 KB Output is correct
51 Correct 483 ms 107768 KB Output is correct
52 Correct 487 ms 107324 KB Output is correct
53 Correct 524 ms 107268 KB Output is correct
54 Correct 376 ms 107720 KB Output is correct
55 Correct 477 ms 108076 KB Output is correct
56 Correct 513 ms 108132 KB Output is correct
57 Correct 516 ms 108044 KB Output is correct
58 Correct 440 ms 107456 KB Output is correct
59 Correct 480 ms 107444 KB Output is correct
60 Correct 382 ms 107492 KB Output is correct
61 Correct 674 ms 107296 KB Output is correct
62 Correct 156 ms 78412 KB Output is correct
63 Correct 184 ms 77256 KB Output is correct
64 Correct 156 ms 77332 KB Output is correct
65 Correct 173 ms 77304 KB Output is correct
66 Correct 160 ms 77284 KB Output is correct
67 Correct 164 ms 77276 KB Output is correct
68 Correct 30 ms 75560 KB Output is correct
69 Correct 31 ms 75420 KB Output is correct
70 Correct 29 ms 75484 KB Output is correct
71 Correct 665 ms 104360 KB Output is correct
72 Correct 623 ms 104376 KB Output is correct
73 Correct 622 ms 104468 KB Output is correct
74 Correct 635 ms 104500 KB Output is correct
75 Correct 541 ms 104296 KB Output is correct
76 Correct 676 ms 104400 KB Output is correct
77 Correct 620 ms 104376 KB Output is correct
78 Correct 742 ms 104424 KB Output is correct
79 Correct 630 ms 104376 KB Output is correct
80 Correct 613 ms 104304 KB Output is correct
81 Correct 600 ms 104340 KB Output is correct
82 Correct 837 ms 107704 KB Output is correct
83 Correct 162 ms 78316 KB Output is correct
84 Correct 164 ms 78320 KB Output is correct
85 Correct 157 ms 78344 KB Output is correct
86 Correct 158 ms 78328 KB Output is correct
87 Correct 158 ms 78320 KB Output is correct
88 Correct 164 ms 78400 KB Output is correct
89 Correct 29 ms 75428 KB Output is correct
90 Correct 35 ms 75440 KB Output is correct
91 Correct 30 ms 75396 KB Output is correct
92 Correct 862 ms 106368 KB Output is correct
93 Correct 756 ms 107632 KB Output is correct
94 Correct 874 ms 106272 KB Output is correct
95 Correct 901 ms 106508 KB Output is correct
96 Correct 790 ms 106216 KB Output is correct
97 Correct 710 ms 106256 KB Output is correct
98 Correct 693 ms 106328 KB Output is correct
99 Correct 779 ms 107920 KB Output is correct
100 Correct 821 ms 107960 KB Output is correct
101 Correct 812 ms 108088 KB Output is correct
102 Correct 868 ms 108088 KB Output is correct
103 Correct 781 ms 107924 KB Output is correct
104 Correct 773 ms 107956 KB Output is correct
105 Correct 819 ms 107732 KB Output is correct
106 Correct 878 ms 106808 KB Output is correct
107 Correct 179 ms 78896 KB Output is correct
108 Correct 194 ms 78840 KB Output is correct
109 Correct 182 ms 78796 KB Output is correct
110 Correct 29 ms 75376 KB Output is correct
111 Correct 29 ms 75464 KB Output is correct
112 Correct 28 ms 75476 KB Output is correct
113 Correct 848 ms 106768 KB Output is correct
114 Correct 787 ms 106704 KB Output is correct
115 Correct 785 ms 106708 KB Output is correct
116 Correct 838 ms 106608 KB Output is correct
117 Correct 883 ms 106892 KB Output is correct
118 Correct 735 ms 106628 KB Output is correct
119 Correct 780 ms 106608 KB Output is correct
120 Correct 460 ms 107852 KB Output is correct
121 Correct 408 ms 107752 KB Output is correct
122 Correct 422 ms 107688 KB Output is correct
123 Correct 421 ms 107064 KB Output is correct
124 Correct 336 ms 106952 KB Output is correct
125 Correct 365 ms 106992 KB Output is correct
126 Correct 876 ms 106920 KB Output is correct
127 Correct 878 ms 106796 KB Output is correct
128 Correct 884 ms 107016 KB Output is correct
129 Correct 842 ms 106860 KB Output is correct
130 Correct 838 ms 107520 KB Output is correct
131 Correct 685 ms 107636 KB Output is correct
132 Correct 751 ms 107520 KB Output is correct
133 Correct 926 ms 106820 KB Output is correct
134 Correct 888 ms 106932 KB Output is correct
135 Correct 900 ms 106860 KB Output is correct
136 Correct 183 ms 78796 KB Output is correct
137 Correct 179 ms 78804 KB Output is correct
138 Correct 190 ms 78936 KB Output is correct