답안 #585253

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
585253 2022-06-28T13:14:21 Z keta_tsimakuridze Progression (NOI20_progression) C++14
24 / 100
553 ms 85784 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, inf = 2e18; //!
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[N];
bool eq(int a, int b) {
	return (a == -inf || b == -inf ? 1 : a == b);
}
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);
//	cout << eq(a.suf.f, b.suf.f) << endl;
	if(eq(a.suf.f, b.pref.f) && eq(a.suf.f, b.L - a.R) && eq(b.pref.f, b.L - a.R)) {
		c.ans = max(c.ans, a.suf.s + b.pref.s);
	}
	if(eq(a.suf.f, b.L - a.R)) {
		c.ans = max(c.ans, a.suf.s + 1);
	}
	if(eq(b.pref.f, b.L - a.R)) {
		c.ans = max(c.ans, b.pref.s + 1);
	}
	c.suf = b.suf;
	if(b.suf.s == b.len && eq(a.suf.f, b.pref.f) && eq(a.suf.f, b.L - a.R) && eq(b.suf.f, b.L - a.R)) {
		c.suf.s += a.suf.s;
	} else if(b.suf.s == b.len && eq(b.suf.f, b.L - a.R)) {
		c.suf.s++;
	}
	c.pref = a.pref;
	if(a.pref.s == a.len && eq(a.pref.f, b.pref.f)&& eq(a.pref.f, b.L - a.R) && eq(b.pref.f, b.L - a.R)) {
		c.pref.s += b.pref.s;
	} else if(a.pref.s == a.len && eq(a.pref.f, b.L - a.R)) c.pref.s++;
	
	if(b.len == 1) {
		c.suf.f = b.L - a.R;
	}
	if(a.len == 1) {
		c.pref.f = b.L - a.R;
	}
	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 = {-inf, 1};
		tree[u].suf = {-inf, 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 ? -inf : 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:125:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  125 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 78416 KB Output is correct
2 Correct 104 ms 75700 KB Output is correct
3 Correct 102 ms 75772 KB Output is correct
4 Correct 102 ms 75752 KB Output is correct
5 Correct 106 ms 75772 KB Output is correct
6 Correct 99 ms 75760 KB Output is correct
7 Correct 99 ms 75756 KB Output is correct
8 Correct 32 ms 75368 KB Output is correct
9 Correct 28 ms 75452 KB Output is correct
10 Correct 29 ms 75356 KB Output is correct
11 Correct 153 ms 78448 KB Output is correct
12 Correct 154 ms 78324 KB Output is correct
13 Correct 167 ms 78572 KB Output is correct
14 Correct 153 ms 78692 KB Output is correct
15 Correct 148 ms 78640 KB Output is correct
16 Correct 159 ms 78304 KB Output is correct
17 Correct 155 ms 78316 KB Output is correct
18 Correct 154 ms 78336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 75536 KB Output is correct
2 Correct 30 ms 75376 KB Output is correct
3 Correct 31 ms 75340 KB Output is correct
4 Correct 29 ms 75340 KB Output is correct
5 Correct 34 ms 75372 KB Output is correct
6 Correct 27 ms 75380 KB Output is correct
7 Correct 28 ms 75464 KB Output is correct
8 Correct 28 ms 75468 KB Output is correct
9 Correct 28 ms 75468 KB Output is correct
10 Correct 29 ms 75504 KB Output is correct
11 Correct 28 ms 75464 KB Output is correct
12 Correct 34 ms 75488 KB Output is correct
13 Correct 32 ms 75468 KB Output is correct
14 Correct 31 ms 75512 KB Output is correct
15 Correct 29 ms 75476 KB Output is correct
16 Correct 29 ms 75540 KB Output is correct
17 Correct 31 ms 75460 KB Output is correct
18 Correct 29 ms 75476 KB Output is correct
19 Correct 28 ms 75408 KB Output is correct
20 Correct 32 ms 75424 KB Output is correct
21 Correct 28 ms 75468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 381 ms 85784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 553 ms 85080 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 381 ms 85784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 78416 KB Output is correct
2 Correct 104 ms 75700 KB Output is correct
3 Correct 102 ms 75772 KB Output is correct
4 Correct 102 ms 75752 KB Output is correct
5 Correct 106 ms 75772 KB Output is correct
6 Correct 99 ms 75760 KB Output is correct
7 Correct 99 ms 75756 KB Output is correct
8 Correct 32 ms 75368 KB Output is correct
9 Correct 28 ms 75452 KB Output is correct
10 Correct 29 ms 75356 KB Output is correct
11 Correct 153 ms 78448 KB Output is correct
12 Correct 154 ms 78324 KB Output is correct
13 Correct 167 ms 78572 KB Output is correct
14 Correct 153 ms 78692 KB Output is correct
15 Correct 148 ms 78640 KB Output is correct
16 Correct 159 ms 78304 KB Output is correct
17 Correct 155 ms 78316 KB Output is correct
18 Correct 154 ms 78336 KB Output is correct
19 Correct 30 ms 75536 KB Output is correct
20 Correct 30 ms 75376 KB Output is correct
21 Correct 31 ms 75340 KB Output is correct
22 Correct 29 ms 75340 KB Output is correct
23 Correct 34 ms 75372 KB Output is correct
24 Correct 27 ms 75380 KB Output is correct
25 Correct 28 ms 75464 KB Output is correct
26 Correct 28 ms 75468 KB Output is correct
27 Correct 28 ms 75468 KB Output is correct
28 Correct 29 ms 75504 KB Output is correct
29 Correct 28 ms 75464 KB Output is correct
30 Correct 34 ms 75488 KB Output is correct
31 Correct 32 ms 75468 KB Output is correct
32 Correct 31 ms 75512 KB Output is correct
33 Correct 29 ms 75476 KB Output is correct
34 Correct 29 ms 75540 KB Output is correct
35 Correct 31 ms 75460 KB Output is correct
36 Correct 29 ms 75476 KB Output is correct
37 Correct 28 ms 75408 KB Output is correct
38 Correct 32 ms 75424 KB Output is correct
39 Correct 28 ms 75468 KB Output is correct
40 Incorrect 381 ms 85784 KB Output isn't correct
41 Halted 0 ms 0 KB -