# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
284268 |
2020-08-27T06:24:13 Z |
문홍윤(#5761) |
Progression (NOI20_progression) |
C++17 |
|
1162 ms |
65276 KB |
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(x.begin(), x.end())
#define press(x) x.erase(unique(x.begin(), x.end()), x.end())
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
const LL llinf=2e18;
const int inf=1e9;
struct SEGMENT_TREE{
struct NODE{
bool setz;
LL lzy, l, r, sum;
int nl, nr, ans;
}tree[1200000];
struct QUERY_NODE{
LL l, r;
int nl, nr, ans, len;
//QUERY_NODE(){l=r=0, nl=nr=ans=len=0;}
};
void prop(int point, int s, int e){
if(tree[point].setz){
if(s!=e){
tree[point*2].setz=true;
tree[point*2+1].setz=true;
tree[point*2].lzy=tree[point].lzy;
tree[point*2+1].lzy=tree[point].lzy;
}
else{
tree[point].l=tree[point].lzy;
tree[point].r=tree[point].lzy;
tree[point].sum=tree[point].l;
}
tree[point].lzy=0;
tree[point].setz=false;
}
else{
if(s!=e){
tree[point*2].lzy+=tree[point].lzy;
tree[point*2+1].lzy+=tree[point].lzy;
}
else{
tree[point].l+=tree[point].lzy;
tree[point].r+=tree[point].lzy;
tree[point].sum=tree[point].l;
}
tree[point].lzy=0;
}
}
void eat(int point, int s, int e){
if(s==e)return;
LL ll, lr, rl, rr, sl, sr;
int nll, nlr, nrl, nrr, al, ar;
int mid=(s+e)/2;
if(tree[point*2].setz){
ll=lr=tree[point*2].lzy;
sl=tree[point*2].lzy*(mid-s+1);
nll=nlr=al=mid-s+1;
}
else{
ll=tree[point*2].l+tree[point*2].lzy;
lr=tree[point*2].r+tree[point*2].lzy;
sl=tree[point*2].sum+tree[point*2].lzy*(mid-s+1);
nll=tree[point*2].nl;
nlr=tree[point*2].nr;
al=tree[point*2].ans;
}
if(tree[point*2+1].setz){
rl=rr=tree[point*2+1].lzy;
sr=tree[point*2+1].lzy*(e-mid);
nrl=nrr=ar=e-mid;
}
else{
rl=tree[point*2+1].l+tree[point*2+1].lzy;
rr=tree[point*2+1].r+tree[point*2+1].lzy;
sr=tree[point*2+1].sum+tree[point*2+1].lzy*(e-mid);
nrl=tree[point*2+1].nl;
nrr=tree[point*2+1].nr;
ar=tree[point*2+1].ans;
}
tree[point].ans=max(al, ar);
tree[point].nl=nll;
tree[point].nr=nrr;
tree[point].sum=sl+sr;
tree[point].l=ll;
tree[point].r=rr;
if(lr==rl){
tree[point].ans=max(tree[point].ans, nlr+nrl);
if(nll==mid-s+1)tree[point].nl=nll+nrl;
if(nrr==e-mid)tree[point].nr=nrr+nlr;
}
}
void init(int point, int s, int e){
tree[point].ans=tree[point].nl=tree[point].nr=e-s+1;
if(s==e)return;
init(point*2, s, (s+e)/2);
init(point*2+1, (s+e)/2+1, e);
}
void upd(int point, int s, int e, int a, int b, LL val, bool str){
if(e<a||s>b)return;
prop(point, s, e);
if(a<=s&&e<=b){
if(str)tree[point].setz=true;
tree[point].lzy=val;
return;
}
upd(point*2, s, (s+e)/2, a, b, val, str);
upd(point*2+1, (s+e)/2+1, e, a, b, val, str);
eat(point, s, e);
}
QUERY_NODE calc(QUERY_NODE a, QUERY_NODE b){
QUERY_NODE ret;
ret.len=a.len+b.len;
ret.ans=max(a.ans, b.ans);
ret.l=a.l, ret.r=b.r;
ret.nl=a.nl, ret.nr=b.nr;
if(a.r==b.l){
if(a.nl==a.len)ret.nl=a.nl+b.nl;
if(b.nr==b.len)ret.nr=b.nr+a.nr;
ret.ans=max(ret.ans, a.nr+b.nl);
}
return ret;
}
QUERY_NODE query2(int point, int s, int e, int a, int b){
if(e<a||s>b)return {llinf, llinf, -1, -1, -1, 0};
prop(point, s, e);
if(a<=s&&e<=b){
eat(point, s, e);
if(tree[point].setz)return {tree[point].lzy, tree[point].lzy, e-s+1, e-s+1, e-s+1, e-s+1};
return {tree[point].lzy+tree[point].l, tree[point].lzy+tree[point].r, tree[point].nl, tree[point].nr, tree[point].ans, e-s+1};
}
QUERY_NODE qa=query2(point*2, s, (s+e)/2, a, b);
QUERY_NODE qb=query2(point*2+1, (s+e)/2+1, e, a, b);
if(qa.l==llinf)return qb;
if(qb.l==llinf)return qa;
return calc(qa, qb);
}
int query(int point, int s, int e, int a, int b){
if(a>b)return 1;
return query2(point, s, e, a, b).ans+1;
}
LL get_sum(int point, int s, int e, int a, int b){
if(e<a||s>b)return 0;
prop(point, s, e);
if(a<=s&&e<=b){
eat(point, s, e);
return tree[point].sum;
}
LL ret=0;
ret+=get_sum(point*2, s, (s+e)/2, a, b);
ret+=get_sum(point*2+1, (s+e)/2+1, e, a, b);
eat(point, s, e);
return ret;
}
}seg;
int n, q;
LL arr[300010];
int main(){
scanf("%d %d", &n, &q);
for(int i=1; i<=n; i++)scanf("%lld", &arr[i]);
seg.init(1, 1, n);
for(int i=1; i<=n; i++)
seg.upd(1, 1, n, i, i, arr[i]-arr[i-1], true);
for(int i=1; i<=q; i++){
int qt, a, b;
scanf("%d", &qt);
if(qt==1){
LL c, d;
scanf("%d %d %lld %lld", &a, &b, &c, &d);
if(a+1<=b)seg.upd(1, 1, n, a+1, b, d, false);
seg.upd(1, 1, n, a, a, c, false);
if(b<n)seg.upd(1, 1, n, b+1, b+1, -c-d*(b-a), false);
}
if(qt==2){
LL c, d, fr, re;
scanf("%d %d %lld %lld", &a, &b, &c, &d);
re=seg.get_sum(1, 1, n, 1, b+1);
fr=seg.get_sum(1, 1, n, 1, a-1);
if(a+1<=b)seg.upd(1, 1, n, a+1, b, d, true);
seg.upd(1, 1, n, a, a, c-fr, true);
if(b<n)seg.upd(1, 1, n, b+1, b+1, re-c-d*(b-a), true);
}
if(qt==3){
scanf("%d %d", &a, &b);
printf("%d\n", seg.query(1, 1, n, a+1, b));
}
}
}
Compilation message
Progression.cpp: In function 'int main()':
Progression.cpp:169:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
169 | scanf("%d %d", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~~
Progression.cpp:170:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
170 | for(int i=1; i<=n; i++)scanf("%lld", &arr[i]);
| ~~~~~^~~~~~~~~~~~~~~~~
Progression.cpp:176:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
176 | scanf("%d", &qt);
| ~~~~~^~~~~~~~~~~
Progression.cpp:179:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
179 | scanf("%d %d %lld %lld", &a, &b, &c, &d);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Progression.cpp:186:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
186 | scanf("%d %d %lld %lld", &a, &b, &c, &d);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Progression.cpp:194:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
194 | scanf("%d %d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
672 ms |
63864 KB |
Output is correct |
2 |
Correct |
206 ms |
2296 KB |
Output is correct |
3 |
Correct |
208 ms |
2296 KB |
Output is correct |
4 |
Correct |
210 ms |
2424 KB |
Output is correct |
5 |
Correct |
212 ms |
2040 KB |
Output is correct |
6 |
Correct |
211 ms |
2040 KB |
Output is correct |
7 |
Correct |
217 ms |
1912 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 |
288 KB |
Output is correct |
11 |
Correct |
676 ms |
62968 KB |
Output is correct |
12 |
Correct |
673 ms |
62824 KB |
Output is correct |
13 |
Correct |
688 ms |
63096 KB |
Output is correct |
14 |
Correct |
690 ms |
63096 KB |
Output is correct |
15 |
Correct |
735 ms |
62968 KB |
Output is correct |
16 |
Correct |
685 ms |
62712 KB |
Output is correct |
17 |
Correct |
675 ms |
62712 KB |
Output is correct |
18 |
Correct |
670 ms |
62712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
669 ms |
63352 KB |
Output is correct |
2 |
Correct |
162 ms |
2040 KB |
Output is correct |
3 |
Correct |
149 ms |
1912 KB |
Output is correct |
4 |
Correct |
133 ms |
1928 KB |
Output is correct |
5 |
Correct |
161 ms |
2040 KB |
Output is correct |
6 |
Correct |
156 ms |
2040 KB |
Output is correct |
7 |
Correct |
162 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 |
758 ms |
63096 KB |
Output is correct |
12 |
Correct |
662 ms |
63352 KB |
Output is correct |
13 |
Correct |
757 ms |
63224 KB |
Output is correct |
14 |
Correct |
740 ms |
62996 KB |
Output is correct |
15 |
Correct |
647 ms |
63224 KB |
Output is correct |
16 |
Correct |
769 ms |
63608 KB |
Output is correct |
17 |
Correct |
745 ms |
63736 KB |
Output is correct |
18 |
Correct |
776 ms |
63736 KB |
Output is correct |
19 |
Correct |
697 ms |
63224 KB |
Output is correct |
20 |
Correct |
685 ms |
62884 KB |
Output is correct |
21 |
Correct |
751 ms |
62972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1068 ms |
62432 KB |
Output is correct |
2 |
Correct |
243 ms |
3704 KB |
Output is correct |
3 |
Correct |
246 ms |
3704 KB |
Output is correct |
4 |
Correct |
232 ms |
3648 KB |
Output is correct |
5 |
Correct |
251 ms |
3704 KB |
Output is correct |
6 |
Correct |
245 ms |
3832 KB |
Output is correct |
7 |
Correct |
236 ms |
3832 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 |
1099 ms |
65276 KB |
Output is correct |
12 |
Correct |
1087 ms |
65276 KB |
Output is correct |
13 |
Correct |
1128 ms |
65144 KB |
Output is correct |
14 |
Correct |
1114 ms |
65272 KB |
Output is correct |
15 |
Correct |
1022 ms |
65276 KB |
Output is correct |
16 |
Correct |
1125 ms |
65144 KB |
Output is correct |
17 |
Correct |
1113 ms |
65016 KB |
Output is correct |
18 |
Correct |
1108 ms |
64888 KB |
Output is correct |
19 |
Correct |
1067 ms |
64896 KB |
Output is correct |
20 |
Correct |
1098 ms |
64800 KB |
Output is correct |
21 |
Correct |
1162 ms |
64796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
669 ms |
63352 KB |
Output is correct |
2 |
Correct |
162 ms |
2040 KB |
Output is correct |
3 |
Correct |
149 ms |
1912 KB |
Output is correct |
4 |
Correct |
133 ms |
1928 KB |
Output is correct |
5 |
Correct |
161 ms |
2040 KB |
Output is correct |
6 |
Correct |
156 ms |
2040 KB |
Output is correct |
7 |
Correct |
162 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 |
758 ms |
63096 KB |
Output is correct |
12 |
Correct |
662 ms |
63352 KB |
Output is correct |
13 |
Correct |
757 ms |
63224 KB |
Output is correct |
14 |
Correct |
740 ms |
62996 KB |
Output is correct |
15 |
Correct |
647 ms |
63224 KB |
Output is correct |
16 |
Correct |
769 ms |
63608 KB |
Output is correct |
17 |
Correct |
745 ms |
63736 KB |
Output is correct |
18 |
Correct |
776 ms |
63736 KB |
Output is correct |
19 |
Correct |
697 ms |
63224 KB |
Output is correct |
20 |
Correct |
685 ms |
62884 KB |
Output is correct |
21 |
Correct |
751 ms |
62972 KB |
Output is correct |
22 |
Incorrect |
1149 ms |
62476 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
672 ms |
63864 KB |
Output is correct |
2 |
Correct |
206 ms |
2296 KB |
Output is correct |
3 |
Correct |
208 ms |
2296 KB |
Output is correct |
4 |
Correct |
210 ms |
2424 KB |
Output is correct |
5 |
Correct |
212 ms |
2040 KB |
Output is correct |
6 |
Correct |
211 ms |
2040 KB |
Output is correct |
7 |
Correct |
217 ms |
1912 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 |
288 KB |
Output is correct |
11 |
Correct |
676 ms |
62968 KB |
Output is correct |
12 |
Correct |
673 ms |
62824 KB |
Output is correct |
13 |
Correct |
688 ms |
63096 KB |
Output is correct |
14 |
Correct |
690 ms |
63096 KB |
Output is correct |
15 |
Correct |
735 ms |
62968 KB |
Output is correct |
16 |
Correct |
685 ms |
62712 KB |
Output is correct |
17 |
Correct |
675 ms |
62712 KB |
Output is correct |
18 |
Correct |
670 ms |
62712 KB |
Output is correct |
19 |
Incorrect |
4 ms |
640 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |