Submission #284288

# Submission time Handle Problem Language Result Execution time Memory
284288 2020-08-27T07:25:45 Z 임성재(#5754) Progression (NOI20_progression) C++17
100 / 100
1939 ms 80020 KB
#include<bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef pair<ll,ll> pll;
const ll inf = 1e9;
const ll INF = 1e18;

ll n, q;
ll d[1200010];
pll tree[1200010];
pll l[1200010];
pll r[1200010];
ll add[1200010];
ll cls[1200010];
ll sum[1200010];
bool chk[1200010];

void propagate(ll node, ll s, ll e) {
	if(!chk[node] && !add[node]) return;

	if(chk[node]) tree[node] = l[node] = r[node] = mp(e - s + 1, cls[node]), sum[node] = cls[node] * (e - s + 1);
	
	tree[node].se += add[node];
	l[node].se += add[node];
	r[node].se += add[node];
	sum[node] += add[node] * (e - s + 1);

	if(s != e) {
		if(chk[node]) {
			chk[node*2] = chk[node*2+1] = true;
			cls[node*2] = cls[node*2+1] = cls[node];
			add[node*2] = add[node*2+1] = 0;
		}

		add[node*2] += add[node];
		add[node*2+1] += add[node];
	}

	chk[node] = false;
	add[node] = 0;
}

void q1(ll node, ll s, ll e, ll L, ll R, ll x) {
	propagate(node, s, e);
	
	if(R < s || e < L) return;
	if(L <= s && e <= R) {
		chk[node] = true;
		cls[node] = x;

		propagate(node, s, e);
		
		return;
	}

	q1(node*2, s, (s+e)/2, L, R, x);
	q1(node*2+1, (s+e)/2+1, e, L, R, x);

	tree[node] = max(tree[node*2], tree[node*2+1]);
	if(l[node*2+1].se == r[node*2].se) tree[node] = max(tree[node], mp(l[node*2+1].fi + r[node*2].fi, l[node*2+1].se));
	
	l[node] = l[node*2];
	r[node] = r[node*2+1];

	if(l[node*2].se == l[node*2+1].se && l[node*2].fi == (s+e)/2 - s + 1) l[node].fi += l[node*2+1].fi;
	if(r[node*2].se == r[node*2+1].se && r[node*2+1].fi == e - (s+e)/2) r[node].fi += r[node*2].fi;

	sum[node] = sum[node*2] + sum[node*2+1];
}

void q2(ll node, ll s, ll e, ll L, ll R, ll x) {
	propagate(node, s, e);
	if(R < s || e < L) return;
	if(L <= s && e <= R) {
		add[node] += x;

		propagate(node, s, e);
		return;
	}

	q2(node*2, s, (s+e)/2, L, R, x);
	q2(node*2+1, (s+e)/2+1, e, L, R, x);

	tree[node] = max(tree[node*2], tree[node*2+1]);
	if(l[node*2+1].se == r[node*2].se) tree[node] = max(tree[node], mp(l[node*2+1].fi + r[node*2].fi, l[node*2+1].se));
	
	l[node] = l[node*2];
	r[node] = r[node*2+1];

	if(l[node*2].se == l[node*2+1].se && l[node*2].fi == (s+e)/2 - s + 1) l[node].fi += l[node*2+1].fi;
	if(r[node*2].se == r[node*2+1].se && r[node*2+1].fi == e - (s+e)/2) r[node].fi += r[node*2].fi;

	sum[node] = sum[node*2] + sum[node*2+1];
}

void cal(ll node, ll s, ll e, ll L, ll R, pll &tot, pll &lsum, pll &rsum) {
	propagate(node, s, e);
	
	if(R < s || e < L) {
		tot = lsum = rsum = mp(0, 0);
		return;
	}
	if(L <= s && e <= R) {
		tot = tree[node];
		lsum = l[node];
		rsum = r[node];

		return;
	}

	ll m = (s + e) / 2;

	if(R <= m) {
		cal(node*2, s, m, L, R, tot, lsum, rsum);
	}
	else if(L >= m+1) {
		cal(node*2+1, m+1, e, L, R, tot, lsum, rsum);
	}
	else {
		pll x, y, z, X, Y, Z;

		cal(node*2, s, m, L, R, x, y, z);
		cal(node*2+1, m+1, e, L, R, X, Y, Z);

		tot = max(x, X);

		if(Y.se == z.se) tot = max(tot, mp(Y.fi + z.fi, Y.se));
		
		lsum = y;
		rsum = Z;

		if(y.se == Y.se && y.fi == m - max(L, s) + 1) lsum.fi += Y.fi;
		if(z.se == Z.se && Z.fi == min(R, e) - m) rsum.fi += z.fi;
	}

	//cout << s << " " << e << " " << tot.fi << " " << tot.se << " " << lsum.fi << " " << lsum.se << " " << rsum.fi << " " << rsum.se << endl;
}

ll A(ll node, ll s, ll e, ll i) {
	propagate(node, s, e);

	if(i < s) return 0;
	if(e <= i) return sum[node];

	ll m = (s + e) / 2;
	return A(node*2, s, m, i) + A(node*2+1, m+1, e, i);
}

ll a(ll x) {
	return A(1, 1, n, x);
}

int main() {
	fast;

	cin >> n >> q;

	for(ll i=1; i<=n; i++) {
		cin >> d[i];

		q1(1, 1, n, i, i, d[i] - d[i-1]);
	}

	while(q--) {
		ll t, L, R;
		cin >> t >> L >> R;

		if(t == 1) {
			ll s, c;
			cin >> s >> c;

			q2(1, 1, n, L, L, s);
			if(L+1 <= R) q2(1, 1, n, L+1, R, c);
			if(R + 1 <= n) q2(1, 1, n, R+1, R+1, - s - (R - L) * c);
		}
		else if(t == 2) {
			ll s, c;
			cin >> s >> c;

			ll x, y;
			x = a(L-1);
			y = a(R+1);

			q1(1, 1, n, L, L, s - x);
			if(L+1 <= R) q1(1, 1, n, L+1, R, c);
			if(R + 1 <= n) q1(1, 1, n, R+1, R+1, y - s - (R - L) * c);
		}
		else {
			if(L == R) {
				cout << 1 << "\n";
			}
			else {
				pll x, y, z;
				cal(1, 1, n, L+1, R, x, y, z);

				cout << x.fi + 1 << "\n";
			}
			
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 695 ms 74616 KB Output is correct
2 Correct 174 ms 1016 KB Output is correct
3 Correct 164 ms 1056 KB Output is correct
4 Correct 164 ms 1016 KB Output is correct
5 Correct 166 ms 1144 KB Output is correct
6 Correct 167 ms 1144 KB Output is correct
7 Correct 167 ms 1016 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 718 ms 74612 KB Output is correct
12 Correct 705 ms 74488 KB Output is correct
13 Correct 724 ms 74872 KB Output is correct
14 Correct 731 ms 74872 KB Output is correct
15 Correct 695 ms 74796 KB Output is correct
16 Correct 691 ms 74524 KB Output is correct
17 Correct 718 ms 74744 KB Output is correct
18 Correct 688 ms 74476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 3 ms 640 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 571 ms 74792 KB Output is correct
2 Correct 106 ms 1400 KB Output is correct
3 Correct 102 ms 1400 KB Output is correct
4 Correct 89 ms 1528 KB Output is correct
5 Correct 112 ms 1528 KB Output is correct
6 Correct 115 ms 1400 KB Output is correct
7 Correct 116 ms 1400 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 758 ms 74540 KB Output is correct
12 Correct 593 ms 75000 KB Output is correct
13 Correct 719 ms 74488 KB Output is correct
14 Correct 733 ms 74488 KB Output is correct
15 Correct 582 ms 74800 KB Output is correct
16 Correct 696 ms 75236 KB Output is correct
17 Correct 704 ms 75256 KB Output is correct
18 Correct 723 ms 75384 KB Output is correct
19 Correct 606 ms 74624 KB Output is correct
20 Correct 603 ms 74528 KB Output is correct
21 Correct 622 ms 74360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1070 ms 74264 KB Output is correct
2 Correct 172 ms 2296 KB Output is correct
3 Correct 177 ms 2424 KB Output is correct
4 Correct 173 ms 2296 KB Output is correct
5 Correct 179 ms 2424 KB Output is correct
6 Correct 181 ms 2376 KB Output is correct
7 Correct 179 ms 2424 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1099 ms 76488 KB Output is correct
12 Correct 1067 ms 76792 KB Output is correct
13 Correct 1103 ms 76408 KB Output is correct
14 Correct 1081 ms 76332 KB Output is correct
15 Correct 990 ms 76664 KB Output is correct
16 Correct 1153 ms 76880 KB Output is correct
17 Correct 1097 ms 76792 KB Output is correct
18 Correct 1125 ms 76696 KB Output is correct
19 Correct 1057 ms 76656 KB Output is correct
20 Correct 1046 ms 76664 KB Output is correct
21 Correct 1010 ms 76512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 571 ms 74792 KB Output is correct
2 Correct 106 ms 1400 KB Output is correct
3 Correct 102 ms 1400 KB Output is correct
4 Correct 89 ms 1528 KB Output is correct
5 Correct 112 ms 1528 KB Output is correct
6 Correct 115 ms 1400 KB Output is correct
7 Correct 116 ms 1400 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 758 ms 74540 KB Output is correct
12 Correct 593 ms 75000 KB Output is correct
13 Correct 719 ms 74488 KB Output is correct
14 Correct 733 ms 74488 KB Output is correct
15 Correct 582 ms 74800 KB Output is correct
16 Correct 696 ms 75236 KB Output is correct
17 Correct 704 ms 75256 KB Output is correct
18 Correct 723 ms 75384 KB Output is correct
19 Correct 606 ms 74624 KB Output is correct
20 Correct 603 ms 74528 KB Output is correct
21 Correct 622 ms 74360 KB Output is correct
22 Correct 1486 ms 76812 KB Output is correct
23 Correct 202 ms 1016 KB Output is correct
24 Correct 175 ms 1144 KB Output is correct
25 Correct 169 ms 1020 KB Output is correct
26 Correct 181 ms 1020 KB Output is correct
27 Correct 186 ms 1016 KB Output is correct
28 Correct 173 ms 1144 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 512 KB Output is correct
32 Correct 1564 ms 76408 KB Output is correct
33 Correct 1444 ms 76408 KB Output is correct
34 Correct 1517 ms 76312 KB Output is correct
35 Correct 1530 ms 76284 KB Output is correct
36 Correct 1270 ms 76536 KB Output is correct
37 Correct 1256 ms 76540 KB Output is correct
38 Correct 1276 ms 76744 KB Output is correct
39 Correct 1515 ms 76396 KB Output is correct
40 Correct 1552 ms 76664 KB Output is correct
41 Correct 1522 ms 76280 KB Output is correct
42 Correct 1535 ms 76540 KB Output is correct
43 Correct 1492 ms 76408 KB Output is correct
44 Correct 1479 ms 76564 KB Output is correct
45 Correct 1520 ms 76360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 695 ms 74616 KB Output is correct
2 Correct 174 ms 1016 KB Output is correct
3 Correct 164 ms 1056 KB Output is correct
4 Correct 164 ms 1016 KB Output is correct
5 Correct 166 ms 1144 KB Output is correct
6 Correct 167 ms 1144 KB Output is correct
7 Correct 167 ms 1016 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 718 ms 74612 KB Output is correct
12 Correct 705 ms 74488 KB Output is correct
13 Correct 724 ms 74872 KB Output is correct
14 Correct 731 ms 74872 KB Output is correct
15 Correct 695 ms 74796 KB Output is correct
16 Correct 691 ms 74524 KB Output is correct
17 Correct 718 ms 74744 KB Output is correct
18 Correct 688 ms 74476 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 3 ms 640 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 3 ms 512 KB Output is correct
34 Correct 3 ms 512 KB Output is correct
35 Correct 3 ms 512 KB Output is correct
36 Correct 3 ms 512 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 2 ms 384 KB Output is correct
40 Correct 571 ms 74792 KB Output is correct
41 Correct 106 ms 1400 KB Output is correct
42 Correct 102 ms 1400 KB Output is correct
43 Correct 89 ms 1528 KB Output is correct
44 Correct 112 ms 1528 KB Output is correct
45 Correct 115 ms 1400 KB Output is correct
46 Correct 116 ms 1400 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 758 ms 74540 KB Output is correct
51 Correct 593 ms 75000 KB Output is correct
52 Correct 719 ms 74488 KB Output is correct
53 Correct 733 ms 74488 KB Output is correct
54 Correct 582 ms 74800 KB Output is correct
55 Correct 696 ms 75236 KB Output is correct
56 Correct 704 ms 75256 KB Output is correct
57 Correct 723 ms 75384 KB Output is correct
58 Correct 606 ms 74624 KB Output is correct
59 Correct 603 ms 74528 KB Output is correct
60 Correct 622 ms 74360 KB Output is correct
61 Correct 1070 ms 74264 KB Output is correct
62 Correct 172 ms 2296 KB Output is correct
63 Correct 177 ms 2424 KB Output is correct
64 Correct 173 ms 2296 KB Output is correct
65 Correct 179 ms 2424 KB Output is correct
66 Correct 181 ms 2376 KB Output is correct
67 Correct 179 ms 2424 KB Output is correct
68 Correct 1 ms 384 KB Output is correct
69 Correct 1 ms 384 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 1099 ms 76488 KB Output is correct
72 Correct 1067 ms 76792 KB Output is correct
73 Correct 1103 ms 76408 KB Output is correct
74 Correct 1081 ms 76332 KB Output is correct
75 Correct 990 ms 76664 KB Output is correct
76 Correct 1153 ms 76880 KB Output is correct
77 Correct 1097 ms 76792 KB Output is correct
78 Correct 1125 ms 76696 KB Output is correct
79 Correct 1057 ms 76656 KB Output is correct
80 Correct 1046 ms 76664 KB Output is correct
81 Correct 1010 ms 76512 KB Output is correct
82 Correct 1486 ms 76812 KB Output is correct
83 Correct 202 ms 1016 KB Output is correct
84 Correct 175 ms 1144 KB Output is correct
85 Correct 169 ms 1020 KB Output is correct
86 Correct 181 ms 1020 KB Output is correct
87 Correct 186 ms 1016 KB Output is correct
88 Correct 173 ms 1144 KB Output is correct
89 Correct 1 ms 384 KB Output is correct
90 Correct 1 ms 384 KB Output is correct
91 Correct 1 ms 512 KB Output is correct
92 Correct 1564 ms 76408 KB Output is correct
93 Correct 1444 ms 76408 KB Output is correct
94 Correct 1517 ms 76312 KB Output is correct
95 Correct 1530 ms 76284 KB Output is correct
96 Correct 1270 ms 76536 KB Output is correct
97 Correct 1256 ms 76540 KB Output is correct
98 Correct 1276 ms 76744 KB Output is correct
99 Correct 1515 ms 76396 KB Output is correct
100 Correct 1552 ms 76664 KB Output is correct
101 Correct 1522 ms 76280 KB Output is correct
102 Correct 1535 ms 76540 KB Output is correct
103 Correct 1492 ms 76408 KB Output is correct
104 Correct 1479 ms 76564 KB Output is correct
105 Correct 1520 ms 76360 KB Output is correct
106 Correct 1852 ms 79452 KB Output is correct
107 Correct 252 ms 1528 KB Output is correct
108 Correct 241 ms 1528 KB Output is correct
109 Correct 237 ms 1528 KB Output is correct
110 Correct 1 ms 384 KB Output is correct
111 Correct 1 ms 384 KB Output is correct
112 Correct 1 ms 384 KB Output is correct
113 Correct 1547 ms 77176 KB Output is correct
114 Correct 1598 ms 76976 KB Output is correct
115 Correct 1574 ms 77048 KB Output is correct
116 Correct 1474 ms 76916 KB Output is correct
117 Correct 1924 ms 79708 KB Output is correct
118 Correct 1487 ms 77064 KB Output is correct
119 Correct 1512 ms 77084 KB Output is correct
120 Correct 731 ms 75896 KB Output is correct
121 Correct 708 ms 75640 KB Output is correct
122 Correct 742 ms 75896 KB Output is correct
123 Correct 600 ms 74872 KB Output is correct
124 Correct 596 ms 75000 KB Output is correct
125 Correct 596 ms 75000 KB Output is correct
126 Correct 1857 ms 79364 KB Output is correct
127 Correct 1913 ms 79404 KB Output is correct
128 Correct 1925 ms 80000 KB Output is correct
129 Correct 1933 ms 79240 KB Output is correct
130 Correct 1425 ms 80020 KB Output is correct
131 Correct 1393 ms 79716 KB Output is correct
132 Correct 1379 ms 79880 KB Output is correct
133 Correct 1879 ms 79736 KB Output is correct
134 Correct 1901 ms 79884 KB Output is correct
135 Correct 1939 ms 79856 KB Output is correct
136 Correct 240 ms 1492 KB Output is correct
137 Correct 241 ms 1400 KB Output is correct
138 Correct 236 ms 1400 KB Output is correct