Submission #317764

# Submission time Handle Problem Language Result Execution time Memory
317764 2020-10-30T10:41:57 Z parsabahrami Progression (NOI20_progression) C++17
100 / 100
1993 ms 95400 KB
//! The Leader Of Retards Bemola
#include <bits/stdc++.h>
 
using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;
 
#define sz(x)                       (ll) x.size()
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define lc 							id << 1
#define rc 							lc | 1

ll Pow(ll a, ll b, ll md, ll ans = 1) {
    for (; b; b >>= 1, a = a * a % md)
        if (b & 1)
            ans = ans * a % md;
    return ans % md;
}
const ll MAXN = 3e5 + 10;
const ll INF  = 8e18;
const ll MOD  = 1e9 + 7;
ll lazy[2][MAXN << 2], A[MAXN], n, q;

struct Node {
	ll sum, L, R, cntL, cntR, mx, l, r;

	friend Node operator+(const Node x, const Node y) {
		if (y.l == -1) return x;
		if (x.l == -1) return y;
		Node ans; ans.sum = x.sum + y.sum; ans.l = x.l, ans.r = y.r;
		ans.L = x.L, ans.cntL = x.cntL;
		ans.R = y.R, ans.cntR = y.cntR;
		ans.mx = max(x.mx, y.mx);
		if (x.cntL == x.r - x.l && x.L == y.L) ans.cntL = x.cntL + y.cntL;
		if (y.cntR == y.r - y.l && x.R == y.R) ans.cntR = x.cntR + y.cntR;
		if (x.R == y.L) ans.mx = max(ans.mx, x.cntR + y.cntL);
		return ans;
	}
};

Node seg[MAXN << 2], emp;

void build(ll id = 1, ll l = 1, ll r = n + 1) {
	if (r - l == 1) {
		seg[id].l = l, seg[id].r = r;
		seg[id].mx = seg[id].cntL = seg[id].cntR = 1;
		seg[id].sum = seg[id].L = seg[id].R = A[l];
		return;
	}
	ll mid = (l + r) >> 1;
	build(lc, l, mid);
	build(rc, mid, r);
	seg[id] = seg[lc] + seg[rc];
}

void shift(ll id, ll l, ll r) {
	if (lazy[0][id] == 0) return;
	if (lazy[0][id] == 1) {
		seg[id].sum += lazy[1][id] * (r - l);
		seg[id].L += lazy[1][id];
		seg[id].R += lazy[1][id];
		if (r - l > 1) {
			if (lazy[0][lc] == 0) lazy[0][lc] = lazy[0][id];
			lazy[1][lc] += lazy[1][id];
			if (lazy[0][rc] == 0) lazy[0][rc] = lazy[0][id];
			lazy[1][rc] += lazy[1][id];
		}
	} else {
		seg[id].sum = lazy[1][id] * (r - l);
		seg[id].mx = seg[id].cntL = seg[id].cntR = r - l;
		seg[id].L = seg[id].R = lazy[1][id];
		if (r - l > 1) {
			lazy[0][lc] = lazy[0][rc] = lazy[0][id];
			lazy[1][lc] = lazy[1][rc] = lazy[1][id];
		}
	}
	lazy[0][id] = lazy[1][id] = 0;
}

void update(ll ql, ll qr, ll t, ll x, ll id = 1, ll l = 1, ll r = n + 1) {
	shift(id, l, r);
	if (qr <= l || r <= ql) return;
	if (ql <= l && r <= qr) {
		lazy[0][id] = t, lazy[1][id] = x;
		return shift(id, l, r);
	}
	ll mid = (l + r) >> 1;
	shift(lc, l, mid), shift(rc, mid, r);
	update(ql, qr, t, x, lc, l, mid);
	update(ql, qr, t, x, rc, mid, r);
	seg[id] = seg[lc] + seg[rc];
}

Node get(ll ql, ll qr, ll id = 1, ll l = 1, ll r = n + 1) {
	shift(id, l, r);
	if (qr <= l || r <= ql) return emp;
	if (ql <= l && r <= qr) return seg[id];
	ll mid = (l + r) >> 1;
	shift(lc, l, mid), shift(rc, mid, r);
	return get(ql, qr, lc, l, mid) + get(ql, qr, rc, mid, r);
}

int main() {
	emp.l = -1;
	scanf("%lld%lld", &n, &q);
	for (ll i = 1; i <= n; i++) {
		scanf("%lld", &A[i]);
	}
	for (ll i = n; i >= 1; i--) {
		A[i] = A[i] - A[i - 1];
	}
	build();
	while (q--) {
		ll t, l, r, s, c;
		scanf("%lld", &t);
		if (t == 1) {
			scanf("%lld%lld%lld%lld", &l, &r, &s, &c);
			ll x = get(1, r + 2).sum;
			update(l + 1, r + 1, 1, c);
			update(l, l + 1, 1, s);
			update(r + 1, r + 2, 2, x - get(1, r + 1).sum);
		} else if (t == 2) {
			scanf("%lld%lld%lld%lld", &l, &r, &s, &c);
			ll x = get(1, r + 2).sum;
			update(l + 1, r + 1, 2, c);
			update(l, l + 1, 2, -get(1, l).sum + s);
			update(r + 1, r + 2, 2, x - get(1, r + 1).sum);
		} else {
			scanf("%lld%lld", &l, &r);
			if (r == l) printf("%lld\n", 1LL);
			else printf("%lld\n", get(l + 1, r + 1).mx + 1);
		}
	}
    return 0;
}

Compilation message

Progression.cpp: In function 'int main()':
Progression.cpp:108:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  108 |  scanf("%lld%lld", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~
Progression.cpp:110:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  110 |   scanf("%lld", &A[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
Progression.cpp:118:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  118 |   scanf("%lld", &t);
      |   ~~~~~^~~~~~~~~~~~
Progression.cpp:120:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  120 |    scanf("%lld%lld%lld%lld", &l, &r, &s, &c);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Progression.cpp:126:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  126 |    scanf("%lld%lld%lld%lld", &l, &r, &s, &c);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Progression.cpp:132:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  132 |    scanf("%lld%lld", &l, &r);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 508 ms 77176 KB Output is correct
2 Correct 198 ms 3576 KB Output is correct
3 Correct 200 ms 3540 KB Output is correct
4 Correct 198 ms 3704 KB Output is correct
5 Correct 199 ms 3704 KB Output is correct
6 Correct 204 ms 3704 KB Output is correct
7 Correct 199 ms 3704 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 508 ms 77096 KB Output is correct
12 Correct 499 ms 77120 KB Output is correct
13 Correct 498 ms 77432 KB Output is correct
14 Correct 499 ms 77508 KB Output is correct
15 Correct 511 ms 77308 KB Output is correct
16 Correct 518 ms 77204 KB Output is correct
17 Correct 512 ms 77048 KB Output is correct
18 Correct 531 ms 77048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 512 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 512 KB Output is correct
13 Correct 3 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 544 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 540 ms 75512 KB Output is correct
2 Correct 178 ms 2992 KB Output is correct
3 Correct 161 ms 3064 KB Output is correct
4 Correct 173 ms 3064 KB Output is correct
5 Correct 160 ms 3192 KB Output is correct
6 Correct 162 ms 3192 KB Output is correct
7 Correct 164 ms 3320 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 551 ms 74104 KB Output is correct
12 Correct 513 ms 75512 KB Output is correct
13 Correct 559 ms 74100 KB Output is correct
14 Correct 552 ms 74040 KB Output is correct
15 Correct 537 ms 75360 KB Output is correct
16 Correct 574 ms 76084 KB Output is correct
17 Correct 858 ms 76024 KB Output is correct
18 Correct 575 ms 76212 KB Output is correct
19 Correct 487 ms 75448 KB Output is correct
20 Correct 488 ms 75520 KB Output is correct
21 Correct 485 ms 75508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1313 ms 90704 KB Output is correct
2 Correct 293 ms 3736 KB Output is correct
3 Correct 287 ms 3704 KB Output is correct
4 Correct 290 ms 3780 KB Output is correct
5 Correct 293 ms 3956 KB Output is correct
6 Correct 297 ms 3704 KB Output is correct
7 Correct 287 ms 3696 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1307 ms 87388 KB Output is correct
12 Correct 1340 ms 90536 KB Output is correct
13 Correct 1312 ms 87404 KB Output is correct
14 Correct 1313 ms 87308 KB Output is correct
15 Correct 1273 ms 90488 KB Output is correct
16 Correct 1337 ms 90832 KB Output is correct
17 Correct 1314 ms 90744 KB Output is correct
18 Correct 1325 ms 90896 KB Output is correct
19 Correct 1295 ms 90676 KB Output is correct
20 Correct 1306 ms 90592 KB Output is correct
21 Correct 1295 ms 90580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 540 ms 75512 KB Output is correct
2 Correct 178 ms 2992 KB Output is correct
3 Correct 161 ms 3064 KB Output is correct
4 Correct 173 ms 3064 KB Output is correct
5 Correct 160 ms 3192 KB Output is correct
6 Correct 162 ms 3192 KB Output is correct
7 Correct 164 ms 3320 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 551 ms 74104 KB Output is correct
12 Correct 513 ms 75512 KB Output is correct
13 Correct 559 ms 74100 KB Output is correct
14 Correct 552 ms 74040 KB Output is correct
15 Correct 537 ms 75360 KB Output is correct
16 Correct 574 ms 76084 KB Output is correct
17 Correct 858 ms 76024 KB Output is correct
18 Correct 575 ms 76212 KB Output is correct
19 Correct 487 ms 75448 KB Output is correct
20 Correct 488 ms 75520 KB Output is correct
21 Correct 485 ms 75508 KB Output is correct
22 Correct 1663 ms 94048 KB Output is correct
23 Correct 269 ms 3576 KB Output is correct
24 Correct 264 ms 3576 KB Output is correct
25 Correct 264 ms 3576 KB Output is correct
26 Correct 384 ms 3704 KB Output is correct
27 Correct 280 ms 3704 KB Output is correct
28 Correct 263 ms 3576 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 1702 ms 91256 KB Output is correct
33 Correct 1605 ms 94072 KB Output is correct
34 Correct 1635 ms 91256 KB Output is correct
35 Correct 1614 ms 91340 KB Output is correct
36 Correct 1256 ms 91192 KB Output is correct
37 Correct 1270 ms 91136 KB Output is correct
38 Correct 1256 ms 91292 KB Output is correct
39 Correct 1587 ms 94292 KB Output is correct
40 Correct 1658 ms 94448 KB Output is correct
41 Correct 1702 ms 94200 KB Output is correct
42 Correct 1686 ms 94084 KB Output is correct
43 Correct 1592 ms 94000 KB Output is correct
44 Correct 1628 ms 94172 KB Output is correct
45 Correct 1600 ms 94200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 508 ms 77176 KB Output is correct
2 Correct 198 ms 3576 KB Output is correct
3 Correct 200 ms 3540 KB Output is correct
4 Correct 198 ms 3704 KB Output is correct
5 Correct 199 ms 3704 KB Output is correct
6 Correct 204 ms 3704 KB Output is correct
7 Correct 199 ms 3704 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 508 ms 77096 KB Output is correct
12 Correct 499 ms 77120 KB Output is correct
13 Correct 498 ms 77432 KB Output is correct
14 Correct 499 ms 77508 KB Output is correct
15 Correct 511 ms 77308 KB Output is correct
16 Correct 518 ms 77204 KB Output is correct
17 Correct 512 ms 77048 KB Output is correct
18 Correct 531 ms 77048 KB Output is correct
19 Correct 4 ms 512 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 512 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 512 KB Output is correct
31 Correct 3 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 544 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 2 ms 384 KB Output is correct
40 Correct 540 ms 75512 KB Output is correct
41 Correct 178 ms 2992 KB Output is correct
42 Correct 161 ms 3064 KB Output is correct
43 Correct 173 ms 3064 KB Output is correct
44 Correct 160 ms 3192 KB Output is correct
45 Correct 162 ms 3192 KB Output is correct
46 Correct 164 ms 3320 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 551 ms 74104 KB Output is correct
51 Correct 513 ms 75512 KB Output is correct
52 Correct 559 ms 74100 KB Output is correct
53 Correct 552 ms 74040 KB Output is correct
54 Correct 537 ms 75360 KB Output is correct
55 Correct 574 ms 76084 KB Output is correct
56 Correct 858 ms 76024 KB Output is correct
57 Correct 575 ms 76212 KB Output is correct
58 Correct 487 ms 75448 KB Output is correct
59 Correct 488 ms 75520 KB Output is correct
60 Correct 485 ms 75508 KB Output is correct
61 Correct 1313 ms 90704 KB Output is correct
62 Correct 293 ms 3736 KB Output is correct
63 Correct 287 ms 3704 KB Output is correct
64 Correct 290 ms 3780 KB Output is correct
65 Correct 293 ms 3956 KB Output is correct
66 Correct 297 ms 3704 KB Output is correct
67 Correct 287 ms 3696 KB Output is correct
68 Correct 1 ms 384 KB Output is correct
69 Correct 2 ms 384 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 1307 ms 87388 KB Output is correct
72 Correct 1340 ms 90536 KB Output is correct
73 Correct 1312 ms 87404 KB Output is correct
74 Correct 1313 ms 87308 KB Output is correct
75 Correct 1273 ms 90488 KB Output is correct
76 Correct 1337 ms 90832 KB Output is correct
77 Correct 1314 ms 90744 KB Output is correct
78 Correct 1325 ms 90896 KB Output is correct
79 Correct 1295 ms 90676 KB Output is correct
80 Correct 1306 ms 90592 KB Output is correct
81 Correct 1295 ms 90580 KB Output is correct
82 Correct 1663 ms 94048 KB Output is correct
83 Correct 269 ms 3576 KB Output is correct
84 Correct 264 ms 3576 KB Output is correct
85 Correct 264 ms 3576 KB Output is correct
86 Correct 384 ms 3704 KB Output is correct
87 Correct 280 ms 3704 KB Output is correct
88 Correct 263 ms 3576 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 1702 ms 91256 KB Output is correct
93 Correct 1605 ms 94072 KB Output is correct
94 Correct 1635 ms 91256 KB Output is correct
95 Correct 1614 ms 91340 KB Output is correct
96 Correct 1256 ms 91192 KB Output is correct
97 Correct 1270 ms 91136 KB Output is correct
98 Correct 1256 ms 91292 KB Output is correct
99 Correct 1587 ms 94292 KB Output is correct
100 Correct 1658 ms 94448 KB Output is correct
101 Correct 1702 ms 94200 KB Output is correct
102 Correct 1686 ms 94084 KB Output is correct
103 Correct 1592 ms 94000 KB Output is correct
104 Correct 1628 ms 94172 KB Output is correct
105 Correct 1600 ms 94200 KB Output is correct
106 Correct 1993 ms 95264 KB Output is correct
107 Correct 318 ms 3840 KB Output is correct
108 Correct 320 ms 3832 KB Output is correct
109 Correct 336 ms 3832 KB Output is correct
110 Correct 1 ms 384 KB Output is correct
111 Correct 2 ms 416 KB Output is correct
112 Correct 2 ms 416 KB Output is correct
113 Correct 1641 ms 94252 KB Output is correct
114 Correct 1640 ms 94428 KB Output is correct
115 Correct 1671 ms 94044 KB Output is correct
116 Correct 1606 ms 94188 KB Output is correct
117 Correct 1832 ms 95140 KB Output is correct
118 Correct 1574 ms 94220 KB Output is correct
119 Correct 1565 ms 94200 KB Output is correct
120 Correct 549 ms 76408 KB Output is correct
121 Correct 552 ms 76408 KB Output is correct
122 Correct 565 ms 76280 KB Output is correct
123 Correct 473 ms 75640 KB Output is correct
124 Correct 472 ms 75516 KB Output is correct
125 Correct 472 ms 75384 KB Output is correct
126 Correct 1765 ms 91796 KB Output is correct
127 Correct 1763 ms 91984 KB Output is correct
128 Correct 1790 ms 95064 KB Output is correct
129 Correct 1746 ms 91896 KB Output is correct
130 Correct 1218 ms 91768 KB Output is correct
131 Correct 1227 ms 91932 KB Output is correct
132 Correct 1209 ms 91888 KB Output is correct
133 Correct 1758 ms 95352 KB Output is correct
134 Correct 1784 ms 95136 KB Output is correct
135 Correct 1825 ms 95400 KB Output is correct
136 Correct 343 ms 3832 KB Output is correct
137 Correct 323 ms 3832 KB Output is correct
138 Correct 323 ms 3960 KB Output is correct