Submission #754942

# Submission time Handle Problem Language Result Execution time Memory
754942 2023-06-09T03:05:33 Z pcc Fire (JOI20_ho_t5) C++14
14 / 100
735 ms 103348 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define fs first
#define sc second
#define int ll

const ll mxn = 4e5+10;

struct Seg{
	pll segtree[mxn*4];
	Seg(){
		for(auto &i:segtree)i = {0,0};
	}
	void modify(int now,int l,int r,int s,int e,ll v){
		if(l>=s&&e>=r){
			segtree[now].sc += v;
			return;
		}
		int mid = (l+r)>>1;
		if(mid>=s)modify(now*2+1,l,mid,s,e,v);
		if(mid<e)modify(now*2+2,mid+1,r,s,e,v);
		segtree[now].fs = 
			segtree[now*2+1].fs+segtree[now*2+1].sc*(mid-l+1)+segtree[now*2+2].fs+segtree[now*2+2].sc*(r-mid);
	}
	ll getval(int now,int l,int r,int s,int e){
		if(l>=s&&e>=r){
			return segtree[now].fs+segtree[now].sc*(r-l+1);
		}
		int mid = (l+r)>>1;
		if(mid>=e)return getval(now*2+1,l,mid,s,e)+segtree[now].sc*(min(e,r)-max(s,l)+1);
		else if(mid<s)return getval(now*2+2,mid+1,r,s,e)+segtree[now].sc*(min(e,r)-max(s,l)+1);
		else return getval(now*2+1,l,mid,s,e)+getval(now*2+2,mid+1,r,s,e)+segtree[now].sc*(min(e,r)-max(s,l)+1);
	}
};
Seg seg1,seg2;
vector<pll> op[mxn];
ll arr[mxn];
ll n,q;
vector<tuple<ll,ll,ll>> req[mxn];
pll range[mxn];
ll ans[mxn];
ll sh = mxn>>1;

void addtri(int r,int c,ll val){
	op[c].push_back({r,val});
}

void add(int now,int h,int w){
	//cout<<now<<":"<<h<<' '<<w<<endl;
	addtri(now,0,arr[now]);
	addtri(now,h,-arr[now]);
	addtri(now+w,w,-arr[now]);
	addtri(now+w,h+w,arr[now]);
	return;
}

int32_t main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>q;
	for(int i = 1;i<=n;i++){
		cin>>arr[i];
	}
	for(int i = 1;i<=q;i++){
		ll t,l,r;
		cin>>t>>l>>r;
		req[t].push_back(make_tuple(1LL*i,l,r));
	}
	arr[0] = arr[n+1] = 1e18;
	deque<int> dq;
	dq.push_back(0);
	for(int i = 1;i<=n;i++){
		while(arr[dq.back()]<arr[i])dq.pop_back();
		range[i].fs = dq.back();
		dq.push_back(i);
	}
	dq.clear();
	dq.push_back(n+1);
	for(int i = n;i>=1;i--){
		while(arr[dq.back()]<arr[i])dq.pop_back();
		range[i].sc = dq.back();
		dq.push_back(i);
		//cout<<i<<":"<<range[i].fs<<' '<<range[i].sc<<'\n';
	}
	for(int i = 1;i<=n;i++){
		if(range[i].fs == 0)range[i].fs = n+1;
		else range[i].fs = i-range[i].fs;
		range[i].sc = range[i].sc-i;
		add(i,range[i].fs,range[i].sc);
	}
	for(int i = 0;i<=n;i++){
		for(auto &j:op[i]){
			seg1.modify(0,1,mxn,j.fs,mxn,j.sc);
			seg2.modify(0,1,mxn,sh+j.fs+1,mxn,-j.sc);
		}
		for(auto &j:req[i]){
			ans[get<0>(j)] = 
				seg1.getval(0,1,mxn,get<1>(j),get<2>(j))+seg2.getval(0,1,mxn,sh+get<1>(j),sh+get<2>(j));
		}
		/*
		for(int i = 1;i<=n;i++)cout<<seg1.getval(0,1,mxn,i,i)<<' ';cout<<endl;
		for(int i  = 1;i<=n;i++)cout<<seg2.getval(0,1,mxn,sh+i,sh+i)<<' ';cout<<endl;

	   */
		sh--;
	}
	for(int i = 1;i<=q;i++)cout<<ans[i]<<'\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 34 ms 69204 KB Output is correct
2 Correct 42 ms 69352 KB Output is correct
3 Correct 34 ms 69168 KB Output is correct
4 Correct 35 ms 69204 KB Output is correct
5 Correct 35 ms 69204 KB Output is correct
6 Correct 35 ms 69132 KB Output is correct
7 Correct 35 ms 69204 KB Output is correct
8 Correct 35 ms 69136 KB Output is correct
9 Correct 36 ms 69136 KB Output is correct
10 Correct 42 ms 69244 KB Output is correct
11 Correct 37 ms 69252 KB Output is correct
12 Correct 36 ms 69212 KB Output is correct
13 Correct 39 ms 69236 KB Output is correct
14 Correct 35 ms 69204 KB Output is correct
15 Correct 34 ms 69200 KB Output is correct
16 Correct 35 ms 69180 KB Output is correct
17 Correct 36 ms 69224 KB Output is correct
18 Correct 35 ms 69180 KB Output is correct
19 Correct 35 ms 69224 KB Output is correct
20 Correct 35 ms 69208 KB Output is correct
21 Correct 34 ms 69252 KB Output is correct
22 Correct 35 ms 69192 KB Output is correct
23 Correct 35 ms 69244 KB Output is correct
24 Correct 37 ms 69168 KB Output is correct
25 Correct 39 ms 69256 KB Output is correct
26 Correct 40 ms 69196 KB Output is correct
27 Correct 38 ms 69144 KB Output is correct
28 Correct 34 ms 69196 KB Output is correct
29 Correct 34 ms 69252 KB Output is correct
30 Correct 35 ms 69184 KB Output is correct
31 Correct 35 ms 69220 KB Output is correct
32 Correct 36 ms 69248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 69204 KB Output is correct
2 Correct 597 ms 100948 KB Output is correct
3 Correct 537 ms 99224 KB Output is correct
4 Correct 537 ms 100980 KB Output is correct
5 Correct 565 ms 102696 KB Output is correct
6 Correct 537 ms 100652 KB Output is correct
7 Correct 551 ms 99808 KB Output is correct
8 Correct 543 ms 103348 KB Output is correct
9 Correct 565 ms 101524 KB Output is correct
10 Correct 560 ms 100824 KB Output is correct
11 Correct 566 ms 101428 KB Output is correct
12 Correct 575 ms 100652 KB Output is correct
13 Correct 656 ms 101612 KB Output is correct
14 Correct 735 ms 98348 KB Output is correct
15 Correct 591 ms 102876 KB Output is correct
16 Correct 601 ms 101064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 69204 KB Output is correct
2 Correct 581 ms 97020 KB Output is correct
3 Correct 556 ms 96524 KB Output is correct
4 Correct 564 ms 98312 KB Output is correct
5 Correct 519 ms 96756 KB Output is correct
6 Correct 550 ms 96960 KB Output is correct
7 Correct 546 ms 96884 KB Output is correct
8 Correct 589 ms 96940 KB Output is correct
9 Correct 554 ms 96644 KB Output is correct
10 Correct 556 ms 96432 KB Output is correct
11 Correct 635 ms 98464 KB Output is correct
12 Correct 542 ms 97924 KB Output is correct
13 Correct 556 ms 98240 KB Output is correct
14 Correct 545 ms 96704 KB Output is correct
15 Correct 545 ms 98268 KB Output is correct
16 Correct 611 ms 97944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 656 ms 96708 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 69204 KB Output is correct
2 Correct 42 ms 69352 KB Output is correct
3 Correct 34 ms 69168 KB Output is correct
4 Correct 35 ms 69204 KB Output is correct
5 Correct 35 ms 69204 KB Output is correct
6 Correct 35 ms 69132 KB Output is correct
7 Correct 35 ms 69204 KB Output is correct
8 Correct 35 ms 69136 KB Output is correct
9 Correct 36 ms 69136 KB Output is correct
10 Correct 42 ms 69244 KB Output is correct
11 Correct 37 ms 69252 KB Output is correct
12 Correct 36 ms 69212 KB Output is correct
13 Correct 39 ms 69236 KB Output is correct
14 Correct 35 ms 69204 KB Output is correct
15 Correct 34 ms 69200 KB Output is correct
16 Correct 35 ms 69180 KB Output is correct
17 Correct 36 ms 69224 KB Output is correct
18 Correct 35 ms 69180 KB Output is correct
19 Correct 35 ms 69224 KB Output is correct
20 Correct 35 ms 69208 KB Output is correct
21 Correct 34 ms 69252 KB Output is correct
22 Correct 35 ms 69192 KB Output is correct
23 Correct 35 ms 69244 KB Output is correct
24 Correct 37 ms 69168 KB Output is correct
25 Correct 39 ms 69256 KB Output is correct
26 Correct 40 ms 69196 KB Output is correct
27 Correct 38 ms 69144 KB Output is correct
28 Correct 34 ms 69196 KB Output is correct
29 Correct 34 ms 69252 KB Output is correct
30 Correct 35 ms 69184 KB Output is correct
31 Correct 35 ms 69220 KB Output is correct
32 Correct 36 ms 69248 KB Output is correct
33 Correct 597 ms 100948 KB Output is correct
34 Correct 537 ms 99224 KB Output is correct
35 Correct 537 ms 100980 KB Output is correct
36 Correct 565 ms 102696 KB Output is correct
37 Correct 537 ms 100652 KB Output is correct
38 Correct 551 ms 99808 KB Output is correct
39 Correct 543 ms 103348 KB Output is correct
40 Correct 565 ms 101524 KB Output is correct
41 Correct 560 ms 100824 KB Output is correct
42 Correct 566 ms 101428 KB Output is correct
43 Correct 575 ms 100652 KB Output is correct
44 Correct 656 ms 101612 KB Output is correct
45 Correct 735 ms 98348 KB Output is correct
46 Correct 591 ms 102876 KB Output is correct
47 Correct 601 ms 101064 KB Output is correct
48 Correct 581 ms 97020 KB Output is correct
49 Correct 556 ms 96524 KB Output is correct
50 Correct 564 ms 98312 KB Output is correct
51 Correct 519 ms 96756 KB Output is correct
52 Correct 550 ms 96960 KB Output is correct
53 Correct 546 ms 96884 KB Output is correct
54 Correct 589 ms 96940 KB Output is correct
55 Correct 554 ms 96644 KB Output is correct
56 Correct 556 ms 96432 KB Output is correct
57 Correct 635 ms 98464 KB Output is correct
58 Correct 542 ms 97924 KB Output is correct
59 Correct 556 ms 98240 KB Output is correct
60 Correct 545 ms 96704 KB Output is correct
61 Correct 545 ms 98268 KB Output is correct
62 Correct 611 ms 97944 KB Output is correct
63 Incorrect 656 ms 96708 KB Output isn't correct
64 Halted 0 ms 0 KB -