답안 #284287

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
284287 2020-08-27T07:21:34 Z 임성재(#5754) Progression (NOI20_progression) C++17
57 / 100
1646 ms 77944 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;

			q1(1, 1, n, L, L, s - a(L-1));
			if(L+1 <= R) q1(1, 1, n, L+1, R, c);
			if(R + 1 <= n) q1(1, 1, n, R+1, R+1, a(R+1) - 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";
			}
			
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 695 ms 75896 KB Output is correct
2 Correct 171 ms 1916 KB Output is correct
3 Correct 163 ms 1916 KB Output is correct
4 Correct 162 ms 2000 KB Output is correct
5 Correct 169 ms 2040 KB Output is correct
6 Correct 168 ms 2168 KB Output is correct
7 Correct 170 ms 1944 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 703 ms 75900 KB Output is correct
12 Correct 700 ms 76044 KB Output is correct
13 Correct 702 ms 76408 KB Output is correct
14 Correct 760 ms 76280 KB Output is correct
15 Correct 723 ms 76152 KB Output is correct
16 Correct 709 ms 75896 KB Output is correct
17 Correct 705 ms 76128 KB Output is correct
18 Correct 700 ms 76156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 596 ms 76184 KB Output is correct
2 Correct 109 ms 1912 KB Output is correct
3 Correct 112 ms 1984 KB Output is correct
4 Correct 96 ms 2040 KB Output is correct
5 Correct 112 ms 2172 KB Output is correct
6 Correct 111 ms 2040 KB Output is correct
7 Correct 115 ms 2040 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 725 ms 75940 KB Output is correct
12 Correct 618 ms 76280 KB Output is correct
13 Correct 762 ms 76024 KB Output is correct
14 Correct 745 ms 75896 KB Output is correct
15 Correct 603 ms 76152 KB Output is correct
16 Correct 697 ms 76536 KB Output is correct
17 Correct 718 ms 76660 KB Output is correct
18 Correct 730 ms 76572 KB Output is correct
19 Correct 621 ms 75928 KB Output is correct
20 Correct 623 ms 75896 KB Output is correct
21 Correct 597 ms 75384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1039 ms 76024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 596 ms 76184 KB Output is correct
2 Correct 109 ms 1912 KB Output is correct
3 Correct 112 ms 1984 KB Output is correct
4 Correct 96 ms 2040 KB Output is correct
5 Correct 112 ms 2172 KB Output is correct
6 Correct 111 ms 2040 KB Output is correct
7 Correct 115 ms 2040 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 725 ms 75940 KB Output is correct
12 Correct 618 ms 76280 KB Output is correct
13 Correct 762 ms 76024 KB Output is correct
14 Correct 745 ms 75896 KB Output is correct
15 Correct 603 ms 76152 KB Output is correct
16 Correct 697 ms 76536 KB Output is correct
17 Correct 718 ms 76660 KB Output is correct
18 Correct 730 ms 76572 KB Output is correct
19 Correct 621 ms 75928 KB Output is correct
20 Correct 623 ms 75896 KB Output is correct
21 Correct 597 ms 75384 KB Output is correct
22 Correct 1469 ms 77944 KB Output is correct
23 Correct 173 ms 1528 KB Output is correct
24 Correct 174 ms 1404 KB Output is correct
25 Correct 167 ms 1400 KB Output is correct
26 Correct 181 ms 1400 KB Output is correct
27 Correct 188 ms 1400 KB Output is correct
28 Correct 177 ms 1400 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 384 KB Output is correct
32 Correct 1646 ms 76664 KB Output is correct
33 Correct 1424 ms 76636 KB Output is correct
34 Correct 1551 ms 76920 KB Output is correct
35 Correct 1549 ms 76612 KB Output is correct
36 Correct 1250 ms 77056 KB Output is correct
37 Correct 1304 ms 77176 KB Output is correct
38 Correct 1325 ms 77208 KB Output is correct
39 Correct 1470 ms 76920 KB Output is correct
40 Correct 1613 ms 76920 KB Output is correct
41 Correct 1589 ms 76636 KB Output is correct
42 Correct 1546 ms 76748 KB Output is correct
43 Correct 1440 ms 76664 KB Output is correct
44 Correct 1458 ms 76728 KB Output is correct
45 Correct 1483 ms 76664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 695 ms 75896 KB Output is correct
2 Correct 171 ms 1916 KB Output is correct
3 Correct 163 ms 1916 KB Output is correct
4 Correct 162 ms 2000 KB Output is correct
5 Correct 169 ms 2040 KB Output is correct
6 Correct 168 ms 2168 KB Output is correct
7 Correct 170 ms 1944 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 703 ms 75900 KB Output is correct
12 Correct 700 ms 76044 KB Output is correct
13 Correct 702 ms 76408 KB Output is correct
14 Correct 760 ms 76280 KB Output is correct
15 Correct 723 ms 76152 KB Output is correct
16 Correct 709 ms 75896 KB Output is correct
17 Correct 705 ms 76128 KB Output is correct
18 Correct 700 ms 76156 KB Output is correct
19 Incorrect 3 ms 512 KB Output isn't correct
20 Halted 0 ms 0 KB -