답안 #261264

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
261264 2020-08-11T15:37:12 Z Berted Progression (NOI20_progression) C++14
100 / 100
1885 ms 127056 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<ll, ll>
#define fst first
#define snd second
using namespace std;

const ll INF = 1e18;

const int SZ = (1 << 20) + 69;

inline pii getLine(pii p1, pii p2)
{
	assert(p1.fst + 1 == p2.fst);
	return {p2.snd - p1.snd, p1.snd * (1 + p1.fst) - p2.snd * p1.fst};
}

inline pii addLine(pii l1, pii l2) {return {l1.fst + l2.fst, l1.snd + l2.snd};}

inline pii getP(pii l, ll x) {return {x, l.fst * x + l.snd};}

struct node
{
	pii lp = {INF, INF}, rp = {INF, INF}, lq = {INF, INF}, rq = {INF, INF};
	int pl = 0, sl = 0, mxl = 0;

	node() {}
};

node seg[SZ];
pii lz[SZ][2];

inline void merge(node &p, node l, node r)
{
	if (l.lp.fst == INF) {p = r;}
	else if (r.lp.fst == INF) {p = l;}
	else
	{
		p.lp = l.lp; p.rp = r.rp;

		pii cl = getLine(l.rp, r.lp);
		int nwsz = 1 + (cl == l.rq) * l.sl + (cl == r.lq) * r.pl; 

		if (l.lq.fst == INF) {p.lq = cl;}
		else {p.lq = l.lq;}

		if (r.rq.fst == INF) {p.rq = cl;}
		else {p.rq = r.rq;}

		if (l.lq.fst == INF) {p.pl = nwsz;}
		else if (l.pl == l.rp.fst - l.lp.fst && l.rq == cl) {p.pl = nwsz;}
		else {p.pl = l.pl;}

		if (r.rq.fst == INF) {p.sl = nwsz;}
		else if (r.sl == r.rp.fst - r.lp.fst && r.lq == cl) {p.sl = nwsz;}
		else {p.sl = r.sl;}

		p.mxl = max({l.mxl, r.mxl, nwsz});
	}
}

inline void lazyDrop(pii a, pii b, int idx)
{
	if (a != make_pair(INF, INF))
	{
		lz[idx][0] = a;
		lz[idx][1] = make_pair(0, 0);
	}
	else if (b != make_pair(0LL, 0LL))
	{
		if (lz[idx][0] != make_pair(INF, INF)) {lz[idx][0] = addLine(lz[idx][0], b);}
		else {lz[idx][1] = addLine(lz[idx][1], b);}
	}
}

inline void prop(int idx, int L, int R)
{
	if (L <= R)
	{
		if (lz[idx][0] != make_pair(INF, INF))
		{
			seg[idx].lp = getP(lz[idx][0], seg[idx].lp.fst);
			seg[idx].rp = getP(lz[idx][0], seg[idx].rp.fst);
			if (R > L)
			{
				seg[idx].lq = lz[idx][0];
				seg[idx].rq = lz[idx][0];
			}
			seg[idx].pl = R - L;
			seg[idx].sl = R - L;
			seg[idx].mxl = R - L;
		} 
		else if (lz[idx][1] != make_pair(0LL, 0LL))
		{
			seg[idx].lp.snd += getP(lz[idx][1], seg[idx].lp.fst).snd;
			seg[idx].rp.snd += getP(lz[idx][1], seg[idx].rp.fst).snd;
			if (R > L)
			{
				seg[idx].lq = addLine(lz[idx][1], seg[idx].lq);
				seg[idx].rq = addLine(lz[idx][1], seg[idx].rq);
			}
		}
		if (L < R)
		{
			lazyDrop(lz[idx][0], lz[idx][1], 2 * idx);
			lazyDrop(lz[idx][0], lz[idx][1], 2 * idx + 1);
		}
		lz[idx][0] = make_pair(INF, INF);
		lz[idx][1] = make_pair(0, 0);
	}
}

int n, q, ar[300001];

void bld(int idx, int L, int R)
{
	if (L < R)
	{
		lz[idx][0] = make_pair(INF, INF);
		lz[idx][1] = make_pair(0LL, 0LL);
		int M = L + R >> 1;
		bld(2 * idx, L, M);
		bld(2 * idx + 1, M + 1, R);
		merge(seg[idx], seg[2 * idx], seg[2 * idx + 1]);
	}
	else if (L == R)
	{
		lz[idx][0] = make_pair(INF, INF);
		lz[idx][1] = make_pair(0LL, 0LL);
		seg[idx].lp = {L, ar[L]};
		seg[idx].rp = seg[idx].lp;
	}
	/*cout << "--- " << L << "  " << R << " --\n";
	cout << seg[idx].lp.fst << ", " << seg[idx].lp.snd << "\n";
	cout << seg[idx].rp.fst << ", " << seg[idx].rp.snd << "\n";
	cout << seg[idx].lq.fst << ", " << seg[idx].lq.snd << "\n";
	cout << seg[idx].rq.fst << ", " << seg[idx].rq.snd << "\n";
	cout << seg[idx].pl << "  " << seg[idx].sl << "  " << seg[idx].mxl << "\n";*/
}

void upd(int idx, int L, int R, int l, int r, int t, pii val)
{
	prop(idx, L, R);
	if (l <= r)
	{
		if (L == l && R == r) 
		{
			if (t == 0) {lazyDrop(val, {0, 0}, idx); prop(idx, L, R);}
			else {lazyDrop({INF, INF}, val, idx); prop(idx, L, R);}
		}
		else
		{
			int M = L + R >> 1;
			upd(2 * idx, L, M, l, min(M, r), t, val);
			upd(2 * idx + 1, M + 1, R, max(M + 1, l), r, t, val);
			merge(seg[idx], seg[2 * idx], seg[2 * idx + 1]);
		}
	}
}

node qry(int idx, int L, int R, int l, int r)
{
	if (l <= r)
	{
		prop(idx, L, R);
		if (L == l && R == r) return seg[idx];
		else
		{
			node ret; int M = L + R >> 1;
			merge(ret, qry(2 * idx, L, M, l, min(M, r)), qry(2 * idx + 1, M + 1, R, max(M + 1, l), r));
			return ret;
		}
	}
	return node();
}

int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> q;
	for (int i = 1; i <= n; i++) cin >> ar[i];
	bld(1, 1, n);
	for (int i = 0; i < q; i++)
	{
		int t; cin >> t;
		if (t < 3)
		{
			ll l, r, s, c; cin >> l >> r >> s >> c;
			t = !(t - 1);
			upd(1, 1, n, l, r, t, make_pair(c, s - c * l));
		}
		else 
		{
			int l, r; cin >> l >> r;
			cout << qry(1, 1, n, l, r).mxl + 1 << "\n";
		}
	}
	return 0;
}

Compilation message

Progression.cpp: In function 'void bld(int, int, int)':
Progression.cpp:121:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int M = L + R >> 1;
           ~~^~~
Progression.cpp: In function 'void upd(int, int, int, int, int, int, std::pair<long long int, long long int>)':
Progression.cpp:153:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    int M = L + R >> 1;
            ~~^~~
Progression.cpp: In function 'node qry(int, int, int, int, int)':
Progression.cpp:169:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    node ret; int M = L + R >> 1;
                      ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 309 ms 125056 KB Output is correct
2 Correct 184 ms 85672 KB Output is correct
3 Correct 186 ms 85752 KB Output is correct
4 Correct 186 ms 85724 KB Output is correct
5 Correct 178 ms 85880 KB Output is correct
6 Correct 178 ms 85732 KB Output is correct
7 Correct 178 ms 85676 KB Output is correct
8 Correct 53 ms 82424 KB Output is correct
9 Correct 51 ms 82428 KB Output is correct
10 Correct 56 ms 82424 KB Output is correct
11 Correct 311 ms 125096 KB Output is correct
12 Correct 288 ms 125048 KB Output is correct
13 Correct 284 ms 125304 KB Output is correct
14 Correct 288 ms 125468 KB Output is correct
15 Correct 336 ms 125184 KB Output is correct
16 Correct 309 ms 125048 KB Output is correct
17 Correct 282 ms 125048 KB Output is correct
18 Correct 305 ms 124980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 82528 KB Output is correct
2 Correct 57 ms 82412 KB Output is correct
3 Correct 66 ms 82424 KB Output is correct
4 Correct 53 ms 82468 KB Output is correct
5 Correct 50 ms 82456 KB Output is correct
6 Correct 54 ms 82412 KB Output is correct
7 Correct 53 ms 82396 KB Output is correct
8 Correct 54 ms 82512 KB Output is correct
9 Correct 58 ms 82508 KB Output is correct
10 Correct 52 ms 82516 KB Output is correct
11 Correct 57 ms 82552 KB Output is correct
12 Correct 58 ms 82500 KB Output is correct
13 Correct 59 ms 82492 KB Output is correct
14 Correct 49 ms 82480 KB Output is correct
15 Correct 60 ms 82480 KB Output is correct
16 Correct 59 ms 82552 KB Output is correct
17 Correct 60 ms 82552 KB Output is correct
18 Correct 54 ms 82572 KB Output is correct
19 Correct 54 ms 82396 KB Output is correct
20 Correct 52 ms 82448 KB Output is correct
21 Correct 61 ms 82552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 674 ms 123580 KB Output is correct
2 Correct 222 ms 85112 KB Output is correct
3 Correct 199 ms 85124 KB Output is correct
4 Correct 196 ms 85112 KB Output is correct
5 Correct 219 ms 85240 KB Output is correct
6 Correct 201 ms 85240 KB Output is correct
7 Correct 198 ms 85240 KB Output is correct
8 Correct 52 ms 82488 KB Output is correct
9 Correct 59 ms 82424 KB Output is correct
10 Correct 57 ms 82372 KB Output is correct
11 Correct 749 ms 122248 KB Output is correct
12 Correct 669 ms 123692 KB Output is correct
13 Correct 778 ms 122256 KB Output is correct
14 Correct 788 ms 122400 KB Output is correct
15 Correct 618 ms 123480 KB Output is correct
16 Correct 889 ms 124072 KB Output is correct
17 Correct 859 ms 124024 KB Output is correct
18 Correct 808 ms 124208 KB Output is correct
19 Correct 724 ms 123652 KB Output is correct
20 Correct 718 ms 123512 KB Output is correct
21 Correct 690 ms 123512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1159 ms 126376 KB Output is correct
2 Correct 220 ms 85752 KB Output is correct
3 Correct 227 ms 85800 KB Output is correct
4 Correct 227 ms 85752 KB Output is correct
5 Correct 228 ms 85752 KB Output is correct
6 Correct 245 ms 85880 KB Output is correct
7 Correct 239 ms 85984 KB Output is correct
8 Correct 55 ms 82424 KB Output is correct
9 Correct 53 ms 82424 KB Output is correct
10 Correct 54 ms 82424 KB Output is correct
11 Correct 1124 ms 123108 KB Output is correct
12 Correct 1067 ms 126488 KB Output is correct
13 Correct 1037 ms 123056 KB Output is correct
14 Correct 1051 ms 123196 KB Output is correct
15 Correct 1090 ms 126268 KB Output is correct
16 Correct 1153 ms 126548 KB Output is correct
17 Correct 1042 ms 126436 KB Output is correct
18 Correct 1113 ms 126620 KB Output is correct
19 Correct 1075 ms 126688 KB Output is correct
20 Correct 989 ms 126404 KB Output is correct
21 Correct 1100 ms 126376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 674 ms 123580 KB Output is correct
2 Correct 222 ms 85112 KB Output is correct
3 Correct 199 ms 85124 KB Output is correct
4 Correct 196 ms 85112 KB Output is correct
5 Correct 219 ms 85240 KB Output is correct
6 Correct 201 ms 85240 KB Output is correct
7 Correct 198 ms 85240 KB Output is correct
8 Correct 52 ms 82488 KB Output is correct
9 Correct 59 ms 82424 KB Output is correct
10 Correct 57 ms 82372 KB Output is correct
11 Correct 749 ms 122248 KB Output is correct
12 Correct 669 ms 123692 KB Output is correct
13 Correct 778 ms 122256 KB Output is correct
14 Correct 788 ms 122400 KB Output is correct
15 Correct 618 ms 123480 KB Output is correct
16 Correct 889 ms 124072 KB Output is correct
17 Correct 859 ms 124024 KB Output is correct
18 Correct 808 ms 124208 KB Output is correct
19 Correct 724 ms 123652 KB Output is correct
20 Correct 718 ms 123512 KB Output is correct
21 Correct 690 ms 123512 KB Output is correct
22 Correct 1517 ms 126088 KB Output is correct
23 Correct 240 ms 85752 KB Output is correct
24 Correct 251 ms 85752 KB Output is correct
25 Correct 241 ms 85624 KB Output is correct
26 Correct 242 ms 85752 KB Output is correct
27 Correct 246 ms 85756 KB Output is correct
28 Correct 243 ms 85752 KB Output is correct
29 Correct 59 ms 82552 KB Output is correct
30 Correct 58 ms 82612 KB Output is correct
31 Correct 52 ms 82424 KB Output is correct
32 Correct 1489 ms 123384 KB Output is correct
33 Correct 1370 ms 125828 KB Output is correct
34 Correct 1564 ms 123256 KB Output is correct
35 Correct 1355 ms 123192 KB Output is correct
36 Correct 1348 ms 122896 KB Output is correct
37 Correct 1265 ms 122868 KB Output is correct
38 Correct 1480 ms 122988 KB Output is correct
39 Correct 1512 ms 125944 KB Output is correct
40 Correct 1455 ms 125944 KB Output is correct
41 Correct 1419 ms 125944 KB Output is correct
42 Correct 1441 ms 126020 KB Output is correct
43 Correct 1562 ms 126036 KB Output is correct
44 Correct 1384 ms 125884 KB Output is correct
45 Correct 1426 ms 126016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 309 ms 125056 KB Output is correct
2 Correct 184 ms 85672 KB Output is correct
3 Correct 186 ms 85752 KB Output is correct
4 Correct 186 ms 85724 KB Output is correct
5 Correct 178 ms 85880 KB Output is correct
6 Correct 178 ms 85732 KB Output is correct
7 Correct 178 ms 85676 KB Output is correct
8 Correct 53 ms 82424 KB Output is correct
9 Correct 51 ms 82428 KB Output is correct
10 Correct 56 ms 82424 KB Output is correct
11 Correct 311 ms 125096 KB Output is correct
12 Correct 288 ms 125048 KB Output is correct
13 Correct 284 ms 125304 KB Output is correct
14 Correct 288 ms 125468 KB Output is correct
15 Correct 336 ms 125184 KB Output is correct
16 Correct 309 ms 125048 KB Output is correct
17 Correct 282 ms 125048 KB Output is correct
18 Correct 305 ms 124980 KB Output is correct
19 Correct 53 ms 82528 KB Output is correct
20 Correct 57 ms 82412 KB Output is correct
21 Correct 66 ms 82424 KB Output is correct
22 Correct 53 ms 82468 KB Output is correct
23 Correct 50 ms 82456 KB Output is correct
24 Correct 54 ms 82412 KB Output is correct
25 Correct 53 ms 82396 KB Output is correct
26 Correct 54 ms 82512 KB Output is correct
27 Correct 58 ms 82508 KB Output is correct
28 Correct 52 ms 82516 KB Output is correct
29 Correct 57 ms 82552 KB Output is correct
30 Correct 58 ms 82500 KB Output is correct
31 Correct 59 ms 82492 KB Output is correct
32 Correct 49 ms 82480 KB Output is correct
33 Correct 60 ms 82480 KB Output is correct
34 Correct 59 ms 82552 KB Output is correct
35 Correct 60 ms 82552 KB Output is correct
36 Correct 54 ms 82572 KB Output is correct
37 Correct 54 ms 82396 KB Output is correct
38 Correct 52 ms 82448 KB Output is correct
39 Correct 61 ms 82552 KB Output is correct
40 Correct 674 ms 123580 KB Output is correct
41 Correct 222 ms 85112 KB Output is correct
42 Correct 199 ms 85124 KB Output is correct
43 Correct 196 ms 85112 KB Output is correct
44 Correct 219 ms 85240 KB Output is correct
45 Correct 201 ms 85240 KB Output is correct
46 Correct 198 ms 85240 KB Output is correct
47 Correct 52 ms 82488 KB Output is correct
48 Correct 59 ms 82424 KB Output is correct
49 Correct 57 ms 82372 KB Output is correct
50 Correct 749 ms 122248 KB Output is correct
51 Correct 669 ms 123692 KB Output is correct
52 Correct 778 ms 122256 KB Output is correct
53 Correct 788 ms 122400 KB Output is correct
54 Correct 618 ms 123480 KB Output is correct
55 Correct 889 ms 124072 KB Output is correct
56 Correct 859 ms 124024 KB Output is correct
57 Correct 808 ms 124208 KB Output is correct
58 Correct 724 ms 123652 KB Output is correct
59 Correct 718 ms 123512 KB Output is correct
60 Correct 690 ms 123512 KB Output is correct
61 Correct 1159 ms 126376 KB Output is correct
62 Correct 220 ms 85752 KB Output is correct
63 Correct 227 ms 85800 KB Output is correct
64 Correct 227 ms 85752 KB Output is correct
65 Correct 228 ms 85752 KB Output is correct
66 Correct 245 ms 85880 KB Output is correct
67 Correct 239 ms 85984 KB Output is correct
68 Correct 55 ms 82424 KB Output is correct
69 Correct 53 ms 82424 KB Output is correct
70 Correct 54 ms 82424 KB Output is correct
71 Correct 1124 ms 123108 KB Output is correct
72 Correct 1067 ms 126488 KB Output is correct
73 Correct 1037 ms 123056 KB Output is correct
74 Correct 1051 ms 123196 KB Output is correct
75 Correct 1090 ms 126268 KB Output is correct
76 Correct 1153 ms 126548 KB Output is correct
77 Correct 1042 ms 126436 KB Output is correct
78 Correct 1113 ms 126620 KB Output is correct
79 Correct 1075 ms 126688 KB Output is correct
80 Correct 989 ms 126404 KB Output is correct
81 Correct 1100 ms 126376 KB Output is correct
82 Correct 1517 ms 126088 KB Output is correct
83 Correct 240 ms 85752 KB Output is correct
84 Correct 251 ms 85752 KB Output is correct
85 Correct 241 ms 85624 KB Output is correct
86 Correct 242 ms 85752 KB Output is correct
87 Correct 246 ms 85756 KB Output is correct
88 Correct 243 ms 85752 KB Output is correct
89 Correct 59 ms 82552 KB Output is correct
90 Correct 58 ms 82612 KB Output is correct
91 Correct 52 ms 82424 KB Output is correct
92 Correct 1489 ms 123384 KB Output is correct
93 Correct 1370 ms 125828 KB Output is correct
94 Correct 1564 ms 123256 KB Output is correct
95 Correct 1355 ms 123192 KB Output is correct
96 Correct 1348 ms 122896 KB Output is correct
97 Correct 1265 ms 122868 KB Output is correct
98 Correct 1480 ms 122988 KB Output is correct
99 Correct 1512 ms 125944 KB Output is correct
100 Correct 1455 ms 125944 KB Output is correct
101 Correct 1419 ms 125944 KB Output is correct
102 Correct 1441 ms 126020 KB Output is correct
103 Correct 1562 ms 126036 KB Output is correct
104 Correct 1384 ms 125884 KB Output is correct
105 Correct 1426 ms 126016 KB Output is correct
106 Correct 1515 ms 127056 KB Output is correct
107 Correct 244 ms 85880 KB Output is correct
108 Correct 244 ms 85880 KB Output is correct
109 Correct 251 ms 86056 KB Output is correct
110 Correct 46 ms 82428 KB Output is correct
111 Correct 59 ms 82424 KB Output is correct
112 Correct 47 ms 82424 KB Output is correct
113 Correct 1514 ms 125820 KB Output is correct
114 Correct 1611 ms 125944 KB Output is correct
115 Correct 1533 ms 125816 KB Output is correct
116 Correct 1529 ms 125688 KB Output is correct
117 Correct 1658 ms 126688 KB Output is correct
118 Correct 1529 ms 125688 KB Output is correct
119 Correct 1335 ms 125944 KB Output is correct
120 Correct 795 ms 124408 KB Output is correct
121 Correct 803 ms 124536 KB Output is correct
122 Correct 873 ms 124408 KB Output is correct
123 Correct 712 ms 123500 KB Output is correct
124 Correct 705 ms 123640 KB Output is correct
125 Correct 708 ms 123640 KB Output is correct
126 Correct 1579 ms 123756 KB Output is correct
127 Correct 1594 ms 123572 KB Output is correct
128 Correct 1642 ms 126796 KB Output is correct
129 Correct 1544 ms 123556 KB Output is correct
130 Correct 1554 ms 123528 KB Output is correct
131 Correct 1365 ms 123636 KB Output is correct
132 Correct 1499 ms 123632 KB Output is correct
133 Correct 1682 ms 126888 KB Output is correct
134 Correct 1661 ms 126728 KB Output is correct
135 Correct 1885 ms 126792 KB Output is correct
136 Correct 252 ms 85880 KB Output is correct
137 Correct 265 ms 85952 KB Output is correct
138 Correct 252 ms 85880 KB Output is correct