Submission #284291

# Submission time Handle Problem Language Result Execution time Memory
284291 2020-08-27T07:31:25 Z 송준혁(#5749) Progression (NOI20_progression) C++17
100 / 100
1691 ms 53240 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

int N, Q;
int A[303030];
bool ISS;

struct Node{
	LL l, r, sum, lz;
	int ld, rd, ans;
	bool iss, fl;
} T[1202020], I;

Node add(Node a, Node b){
	if (a.ld == 0) return b;
	if (b.ld == 0) return a;
	Node ret;
	ret.lz = 0, ret.iss = false;
	ret.sum = a.sum + b.sum;
	ret.l = a.l, ret.r = b.r;
	ret.ans = max(a.ans, b.ans);
	if (a.r == b.l) ret.ans = max(ret.ans, a.rd+b.ld);
	ret.ld = a.ld + ((a.fl && a.l == b.l)?b.ld:0);
	ret.rd = b.rd + ((b.fl && a.r == b.r)?a.rd:0);
	ret.fl = a.fl && b.fl && a.l == b.l;
	return ret;
}

void busy(int id, int s, int e){
	if (T[id].iss){
		T[id].fl = true;
		T[id].l = T[id].r = T[id].lz;
		T[id].sum = T[id].lz*(e-s+1);
		T[id].ld = T[id].rd = T[id].ans = e-s+1;
		if (s != e){
			T[id*2].lz = T[id*2+1].lz = T[id].lz;
			T[id*2].iss = T[id*2+1].iss = true;
		}
	}
	else{
		T[id].l += T[id].lz, T[id].r += T[id].lz;
		T[id].sum += T[id].lz*(e-s+1);
		if (s != e) T[id*2].lz += T[id].lz, T[id*2+1].lz += T[id].lz;
	}
	T[id].lz = 0, T[id].iss = false;
}

void init(int id, int s, int e){
	if (s == e){
		T[id].l = T[id].r = T[id].sum = A[s]-A[s-1];
		T[id].ld = T[id].rd = T[id].ans = 1;
		T[id].fl = true, T[id].iss = false;
		T[id].lz = 0;
		return;
	}
	int m=s+e>>1;
	init(id*2, s, m), init(id*2+1, m+1, e);
	T[id] = add(T[id*2], T[id*2+1]);
}

void upd(int id, int s, int e, int ts, int te, LL v){
	busy(id, s, e);
	if (e < ts || te < s) return;
	if (ts <= s && e <= te){
		if (ISS) T[id].lz = v, T[id].iss = true;
		else T[id].lz += v;
		busy(id, s, e);
		return;
	}
	int m=s+e>>1;
	upd(id*2, s, m, ts, te, v);
	upd(id*2+1, m+1, e, ts, te, v);
	T[id] = add(T[id*2], T[id*2+1]);
}

LL sumq(int id, int s, int e, int ts, int te){
	if (e < ts || te < s) return 0;
	busy(id, s, e);
	if (ts <= s && e <= te) return T[id].sum;
	int m=s+e>>1;
	return sumq(id*2, s, m, ts, te)+sumq(id*2+1, m+1, e, ts, te);
}

Node nodq(int id, int s, int e, int ts, int te){
	if (e < ts || te < s) return I;
	busy(id, s, e);
	if (ts <= s && e <= te) return T[id];
	int m=s+e>>1;
	return add(nodq(id*2, s, m, ts, te), nodq(id*2+1, m+1, e, ts, te));
}

int main(){
	scanf("%d %d", &N, &Q);
	for (int i=1; i<=N; i++) scanf("%d", &A[i]);
	init(1, 1, N);
	while (Q--){
		int l, r;
		LL s, c;
		scanf("%d", &l);
		if (l == 1){
			scanf("%d %d %lld %lld", &l, &r, &s, &c);
			ISS = false;
			upd(1, 1, N, l, l, s);
			upd(1, 1, N, l+1, r, c);
			upd(1, 1, N, r+1, r+1, -(s+c*(r-l)));
		}
		else if (l == 2){
			scanf("%d %d %lld %lld", &l, &r, &s, &c);
			ISS = true;
			LL x = sumq(1, 1, N, 1, r+1);
			upd(1, 1, N, r+1, r+1, x-(s+c*(r-l)));
			x = sumq(1, 1, N, 1, l-1);
			upd(1, 1, N, l, l, s-x);
			upd(1, 1, N, l+1, r, c);
		}
		else{
			scanf("%d %d", &l, &r);
			printf("%d\n", nodq(1, 1, N, l+1, r).ans+1);
		}
	}
	return 0;
}

Compilation message

Progression.cpp: In function 'void init(int, int, int)':
Progression.cpp:58:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   58 |  int m=s+e>>1;
      |        ~^~
Progression.cpp: In function 'void upd(int, int, int, int, int, LL)':
Progression.cpp:72:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   72 |  int m=s+e>>1;
      |        ~^~
Progression.cpp: In function 'LL sumq(int, int, int, int, int)':
Progression.cpp:82:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   82 |  int m=s+e>>1;
      |        ~^~
Progression.cpp: In function 'Node nodq(int, int, int, int, int)':
Progression.cpp:90:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   90 |  int m=s+e>>1;
      |        ~^~
Progression.cpp: In function 'int main()':
Progression.cpp:95:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   95 |  scanf("%d %d", &N, &Q);
      |  ~~~~~^~~~~~~~~~~~~~~~~
Progression.cpp:96:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   96 |  for (int i=1; i<=N; i++) scanf("%d", &A[i]);
      |                           ~~~~~^~~~~~~~~~~~~
Progression.cpp:101:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  101 |   scanf("%d", &l);
      |   ~~~~~^~~~~~~~~~
Progression.cpp:103:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  103 |    scanf("%d %d %lld %lld", &l, &r, &s, &c);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Progression.cpp:110:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  110 |    scanf("%d %d %lld %lld", &l, &r, &s, &c);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Progression.cpp:119:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  119 |    scanf("%d %d", &l, &r);
      |    ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 711 ms 52856 KB Output is correct
2 Correct 275 ms 1272 KB Output is correct
3 Correct 267 ms 1400 KB Output is correct
4 Correct 282 ms 1400 KB Output is correct
5 Correct 262 ms 1400 KB Output is correct
6 Correct 263 ms 1408 KB Output is correct
7 Correct 271 ms 1244 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 700 ms 53012 KB Output is correct
12 Correct 705 ms 52712 KB Output is correct
13 Correct 697 ms 53112 KB Output is correct
14 Correct 756 ms 53116 KB Output is correct
15 Correct 687 ms 53112 KB Output is correct
16 Correct 698 ms 52728 KB Output is correct
17 Correct 701 ms 52784 KB Output is correct
18 Correct 746 ms 52872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 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 2 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 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 582 ms 52916 KB Output is correct
2 Correct 178 ms 1656 KB Output is correct
3 Correct 175 ms 1656 KB Output is correct
4 Correct 170 ms 1916 KB Output is correct
5 Correct 179 ms 1656 KB Output is correct
6 Correct 183 ms 1784 KB Output is correct
7 Correct 183 ms 1784 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 681 ms 52600 KB Output is correct
12 Correct 586 ms 53112 KB Output is correct
13 Correct 744 ms 52468 KB Output is correct
14 Correct 700 ms 52440 KB Output is correct
15 Correct 607 ms 52856 KB Output is correct
16 Correct 727 ms 52984 KB Output is correct
17 Correct 679 ms 52984 KB Output is correct
18 Correct 685 ms 53240 KB Output is correct
19 Correct 614 ms 52344 KB Output is correct
20 Correct 610 ms 52436 KB Output is correct
21 Correct 637 ms 52504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1245 ms 52600 KB Output is correct
2 Correct 311 ms 1400 KB Output is correct
3 Correct 314 ms 1144 KB Output is correct
4 Correct 324 ms 1400 KB Output is correct
5 Correct 341 ms 1400 KB Output is correct
6 Correct 325 ms 1144 KB Output is correct
7 Correct 328 ms 1120 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 1235 ms 51960 KB Output is correct
12 Correct 1241 ms 52044 KB Output is correct
13 Correct 1208 ms 52068 KB Output is correct
14 Correct 1238 ms 52344 KB Output is correct
15 Correct 1158 ms 52092 KB Output is correct
16 Correct 1309 ms 51912 KB Output is correct
17 Correct 1308 ms 51960 KB Output is correct
18 Correct 1235 ms 52088 KB Output is correct
19 Correct 1196 ms 51800 KB Output is correct
20 Correct 1203 ms 52116 KB Output is correct
21 Correct 1244 ms 52104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 582 ms 52916 KB Output is correct
2 Correct 178 ms 1656 KB Output is correct
3 Correct 175 ms 1656 KB Output is correct
4 Correct 170 ms 1916 KB Output is correct
5 Correct 179 ms 1656 KB Output is correct
6 Correct 183 ms 1784 KB Output is correct
7 Correct 183 ms 1784 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 681 ms 52600 KB Output is correct
12 Correct 586 ms 53112 KB Output is correct
13 Correct 744 ms 52468 KB Output is correct
14 Correct 700 ms 52440 KB Output is correct
15 Correct 607 ms 52856 KB Output is correct
16 Correct 727 ms 52984 KB Output is correct
17 Correct 679 ms 52984 KB Output is correct
18 Correct 685 ms 53240 KB Output is correct
19 Correct 614 ms 52344 KB Output is correct
20 Correct 610 ms 52436 KB Output is correct
21 Correct 637 ms 52504 KB Output is correct
22 Correct 1280 ms 52708 KB Output is correct
23 Correct 287 ms 1528 KB Output is correct
24 Correct 299 ms 1604 KB Output is correct
25 Correct 286 ms 1680 KB Output is correct
26 Correct 295 ms 1528 KB Output is correct
27 Correct 282 ms 1540 KB Output is correct
28 Correct 277 ms 1672 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 1300 ms 52216 KB Output is correct
33 Correct 1224 ms 52196 KB Output is correct
34 Correct 1271 ms 52364 KB Output is correct
35 Correct 1287 ms 52080 KB Output is correct
36 Correct 1057 ms 52472 KB Output is correct
37 Correct 1087 ms 52356 KB Output is correct
38 Correct 1095 ms 52400 KB Output is correct
39 Correct 1255 ms 52088 KB Output is correct
40 Correct 1294 ms 52356 KB Output is correct
41 Correct 1308 ms 52048 KB Output is correct
42 Correct 1365 ms 52240 KB Output is correct
43 Correct 1274 ms 52088 KB Output is correct
44 Correct 1238 ms 52344 KB Output is correct
45 Correct 1235 ms 52244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 711 ms 52856 KB Output is correct
2 Correct 275 ms 1272 KB Output is correct
3 Correct 267 ms 1400 KB Output is correct
4 Correct 282 ms 1400 KB Output is correct
5 Correct 262 ms 1400 KB Output is correct
6 Correct 263 ms 1408 KB Output is correct
7 Correct 271 ms 1244 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 700 ms 53012 KB Output is correct
12 Correct 705 ms 52712 KB Output is correct
13 Correct 697 ms 53112 KB Output is correct
14 Correct 756 ms 53116 KB Output is correct
15 Correct 687 ms 53112 KB Output is correct
16 Correct 698 ms 52728 KB Output is correct
17 Correct 701 ms 52784 KB Output is correct
18 Correct 746 ms 52872 KB Output is correct
19 Correct 3 ms 384 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 2 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 3 ms 512 KB Output is correct
34 Correct 3 ms 384 KB Output is correct
35 Correct 3 ms 384 KB Output is correct
36 Correct 3 ms 384 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 582 ms 52916 KB Output is correct
41 Correct 178 ms 1656 KB Output is correct
42 Correct 175 ms 1656 KB Output is correct
43 Correct 170 ms 1916 KB Output is correct
44 Correct 179 ms 1656 KB Output is correct
45 Correct 183 ms 1784 KB Output is correct
46 Correct 183 ms 1784 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 681 ms 52600 KB Output is correct
51 Correct 586 ms 53112 KB Output is correct
52 Correct 744 ms 52468 KB Output is correct
53 Correct 700 ms 52440 KB Output is correct
54 Correct 607 ms 52856 KB Output is correct
55 Correct 727 ms 52984 KB Output is correct
56 Correct 679 ms 52984 KB Output is correct
57 Correct 685 ms 53240 KB Output is correct
58 Correct 614 ms 52344 KB Output is correct
59 Correct 610 ms 52436 KB Output is correct
60 Correct 637 ms 52504 KB Output is correct
61 Correct 1245 ms 52600 KB Output is correct
62 Correct 311 ms 1400 KB Output is correct
63 Correct 314 ms 1144 KB Output is correct
64 Correct 324 ms 1400 KB Output is correct
65 Correct 341 ms 1400 KB Output is correct
66 Correct 325 ms 1144 KB Output is correct
67 Correct 328 ms 1120 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 1235 ms 51960 KB Output is correct
72 Correct 1241 ms 52044 KB Output is correct
73 Correct 1208 ms 52068 KB Output is correct
74 Correct 1238 ms 52344 KB Output is correct
75 Correct 1158 ms 52092 KB Output is correct
76 Correct 1309 ms 51912 KB Output is correct
77 Correct 1308 ms 51960 KB Output is correct
78 Correct 1235 ms 52088 KB Output is correct
79 Correct 1196 ms 51800 KB Output is correct
80 Correct 1203 ms 52116 KB Output is correct
81 Correct 1244 ms 52104 KB Output is correct
82 Correct 1280 ms 52708 KB Output is correct
83 Correct 287 ms 1528 KB Output is correct
84 Correct 299 ms 1604 KB Output is correct
85 Correct 286 ms 1680 KB Output is correct
86 Correct 295 ms 1528 KB Output is correct
87 Correct 282 ms 1540 KB Output is correct
88 Correct 277 ms 1672 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 384 KB Output is correct
92 Correct 1300 ms 52216 KB Output is correct
93 Correct 1224 ms 52196 KB Output is correct
94 Correct 1271 ms 52364 KB Output is correct
95 Correct 1287 ms 52080 KB Output is correct
96 Correct 1057 ms 52472 KB Output is correct
97 Correct 1087 ms 52356 KB Output is correct
98 Correct 1095 ms 52400 KB Output is correct
99 Correct 1255 ms 52088 KB Output is correct
100 Correct 1294 ms 52356 KB Output is correct
101 Correct 1308 ms 52048 KB Output is correct
102 Correct 1365 ms 52240 KB Output is correct
103 Correct 1274 ms 52088 KB Output is correct
104 Correct 1238 ms 52344 KB Output is correct
105 Correct 1235 ms 52244 KB Output is correct
106 Correct 1632 ms 52116 KB Output is correct
107 Correct 337 ms 1144 KB Output is correct
108 Correct 336 ms 1312 KB Output is correct
109 Correct 336 ms 1144 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 1299 ms 51864 KB Output is correct
114 Correct 1345 ms 51960 KB Output is correct
115 Correct 1327 ms 51920 KB Output is correct
116 Correct 1230 ms 51832 KB Output is correct
117 Correct 1642 ms 52068 KB Output is correct
118 Correct 1251 ms 51776 KB Output is correct
119 Correct 1254 ms 51832 KB Output is correct
120 Correct 694 ms 52828 KB Output is correct
121 Correct 678 ms 52892 KB Output is correct
122 Correct 706 ms 52984 KB Output is correct
123 Correct 610 ms 51960 KB Output is correct
124 Correct 599 ms 51960 KB Output is correct
125 Correct 604 ms 51960 KB Output is correct
126 Correct 1597 ms 51836 KB Output is correct
127 Correct 1605 ms 51744 KB Output is correct
128 Correct 1666 ms 52216 KB Output is correct
129 Correct 1609 ms 51808 KB Output is correct
130 Correct 1143 ms 52396 KB Output is correct
131 Correct 1188 ms 52600 KB Output is correct
132 Correct 1171 ms 52560 KB Output is correct
133 Correct 1654 ms 52484 KB Output is correct
134 Correct 1691 ms 52476 KB Output is correct
135 Correct 1643 ms 52344 KB Output is correct
136 Correct 340 ms 1148 KB Output is correct
137 Correct 349 ms 888 KB Output is correct
138 Correct 344 ms 1016 KB Output is correct