# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
284281 |
2020-08-27T07:03:28 Z |
송준혁(#5749) |
Progression (NOI20_progression) |
C++17 |
|
1369 ms |
54264 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){
if (e < ts || te < s) return;
busy(id, s, e);
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;
}
busy(id, s, e);
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:73:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
73 | int m=s+e>>1;
| ~^~
Progression.cpp: In function 'LL sumq(int, int, int, int, int)':
Progression.cpp:83:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
83 | int m=s+e>>1;
| ~^~
Progression.cpp: In function 'Node nodq(int, int, int, int, int)':
Progression.cpp:91:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
91 | int m=s+e>>1;
| ~^~
Progression.cpp: In function 'int main()':
Progression.cpp:96:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
96 | scanf("%d %d", &N, &Q);
| ~~~~~^~~~~~~~~~~~~~~~~
Progression.cpp:97:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
97 | for (int i=1; i<=N; i++) scanf("%d", &A[i]);
| ~~~~~^~~~~~~~~~~~~
Progression.cpp:102:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
102 | scanf("%d", &l);
| ~~~~~^~~~~~~~~~
Progression.cpp:104:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
104 | scanf("%d %d %lld %lld", &l, &r, &s, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Progression.cpp:111:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
111 | scanf("%d %d %lld %lld", &l, &r, &s, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Progression.cpp:120:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
120 | scanf("%d %d", &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
733 ms |
54264 KB |
Output is correct |
2 |
Correct |
294 ms |
2084 KB |
Output is correct |
3 |
Correct |
264 ms |
2168 KB |
Output is correct |
4 |
Correct |
258 ms |
2040 KB |
Output is correct |
5 |
Correct |
265 ms |
2168 KB |
Output is correct |
6 |
Correct |
258 ms |
2168 KB |
Output is correct |
7 |
Correct |
260 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 |
747 ms |
53752 KB |
Output is correct |
12 |
Correct |
712 ms |
53624 KB |
Output is correct |
13 |
Correct |
705 ms |
53784 KB |
Output is correct |
14 |
Correct |
711 ms |
53880 KB |
Output is correct |
15 |
Correct |
730 ms |
53788 KB |
Output is correct |
16 |
Correct |
796 ms |
53624 KB |
Output is correct |
17 |
Correct |
744 ms |
53396 KB |
Output is correct |
18 |
Correct |
729 ms |
53496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
580 ms |
53144 KB |
Output is correct |
2 |
Correct |
174 ms |
2296 KB |
Output is correct |
3 |
Correct |
171 ms |
2424 KB |
Output is correct |
4 |
Correct |
162 ms |
2424 KB |
Output is correct |
5 |
Correct |
173 ms |
2424 KB |
Output is correct |
6 |
Correct |
189 ms |
2424 KB |
Output is correct |
7 |
Correct |
171 ms |
2424 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 |
685 ms |
53088 KB |
Output is correct |
12 |
Correct |
578 ms |
53272 KB |
Output is correct |
13 |
Correct |
665 ms |
52988 KB |
Output is correct |
14 |
Correct |
672 ms |
52984 KB |
Output is correct |
15 |
Correct |
582 ms |
53240 KB |
Output is correct |
16 |
Correct |
665 ms |
53496 KB |
Output is correct |
17 |
Correct |
676 ms |
53624 KB |
Output is correct |
18 |
Correct |
681 ms |
53608 KB |
Output is correct |
19 |
Correct |
638 ms |
52856 KB |
Output is correct |
20 |
Correct |
626 ms |
52828 KB |
Output is correct |
21 |
Correct |
623 ms |
52984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1227 ms |
53240 KB |
Output is correct |
2 |
Correct |
307 ms |
1824 KB |
Output is correct |
3 |
Correct |
316 ms |
1792 KB |
Output is correct |
4 |
Correct |
308 ms |
1788 KB |
Output is correct |
5 |
Correct |
315 ms |
1784 KB |
Output is correct |
6 |
Correct |
314 ms |
1656 KB |
Output is correct |
7 |
Correct |
313 ms |
1784 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1218 ms |
53368 KB |
Output is correct |
12 |
Correct |
1258 ms |
54044 KB |
Output is correct |
13 |
Correct |
1248 ms |
53624 KB |
Output is correct |
14 |
Correct |
1229 ms |
53240 KB |
Output is correct |
15 |
Correct |
1168 ms |
53736 KB |
Output is correct |
16 |
Correct |
1275 ms |
54008 KB |
Output is correct |
17 |
Correct |
1245 ms |
53880 KB |
Output is correct |
18 |
Correct |
1258 ms |
54124 KB |
Output is correct |
19 |
Correct |
1235 ms |
53880 KB |
Output is correct |
20 |
Correct |
1204 ms |
54136 KB |
Output is correct |
21 |
Correct |
1220 ms |
53880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
580 ms |
53144 KB |
Output is correct |
2 |
Correct |
174 ms |
2296 KB |
Output is correct |
3 |
Correct |
171 ms |
2424 KB |
Output is correct |
4 |
Correct |
162 ms |
2424 KB |
Output is correct |
5 |
Correct |
173 ms |
2424 KB |
Output is correct |
6 |
Correct |
189 ms |
2424 KB |
Output is correct |
7 |
Correct |
171 ms |
2424 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 |
685 ms |
53088 KB |
Output is correct |
12 |
Correct |
578 ms |
53272 KB |
Output is correct |
13 |
Correct |
665 ms |
52988 KB |
Output is correct |
14 |
Correct |
672 ms |
52984 KB |
Output is correct |
15 |
Correct |
582 ms |
53240 KB |
Output is correct |
16 |
Correct |
665 ms |
53496 KB |
Output is correct |
17 |
Correct |
676 ms |
53624 KB |
Output is correct |
18 |
Correct |
681 ms |
53608 KB |
Output is correct |
19 |
Correct |
638 ms |
52856 KB |
Output is correct |
20 |
Correct |
626 ms |
52828 KB |
Output is correct |
21 |
Correct |
623 ms |
52984 KB |
Output is correct |
22 |
Incorrect |
1369 ms |
53376 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
733 ms |
54264 KB |
Output is correct |
2 |
Correct |
294 ms |
2084 KB |
Output is correct |
3 |
Correct |
264 ms |
2168 KB |
Output is correct |
4 |
Correct |
258 ms |
2040 KB |
Output is correct |
5 |
Correct |
265 ms |
2168 KB |
Output is correct |
6 |
Correct |
258 ms |
2168 KB |
Output is correct |
7 |
Correct |
260 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 |
747 ms |
53752 KB |
Output is correct |
12 |
Correct |
712 ms |
53624 KB |
Output is correct |
13 |
Correct |
705 ms |
53784 KB |
Output is correct |
14 |
Correct |
711 ms |
53880 KB |
Output is correct |
15 |
Correct |
730 ms |
53788 KB |
Output is correct |
16 |
Correct |
796 ms |
53624 KB |
Output is correct |
17 |
Correct |
744 ms |
53396 KB |
Output is correct |
18 |
Correct |
729 ms |
53496 KB |
Output is correct |
19 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |