답안 #754941

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
754941 2023-06-09T03:04:17 Z pcc Fire (JOI20_ho_t5) C++14
14 / 100
637 ms 106652 KB
#include <bits/stdc++.h>
using namespace std;

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

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;
}

int 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 69188 KB Output is correct
2 Correct 38 ms 69276 KB Output is correct
3 Correct 35 ms 69200 KB Output is correct
4 Correct 36 ms 69168 KB Output is correct
5 Correct 37 ms 69204 KB Output is correct
6 Correct 35 ms 69200 KB Output is correct
7 Correct 35 ms 69196 KB Output is correct
8 Correct 35 ms 69196 KB Output is correct
9 Correct 38 ms 69200 KB Output is correct
10 Correct 37 ms 69196 KB Output is correct
11 Correct 36 ms 69132 KB Output is correct
12 Correct 35 ms 69236 KB Output is correct
13 Correct 36 ms 69196 KB Output is correct
14 Correct 37 ms 69204 KB Output is correct
15 Correct 35 ms 69212 KB Output is correct
16 Correct 35 ms 69156 KB Output is correct
17 Correct 39 ms 69208 KB Output is correct
18 Correct 35 ms 69252 KB Output is correct
19 Correct 36 ms 69208 KB Output is correct
20 Correct 35 ms 69140 KB Output is correct
21 Correct 35 ms 69204 KB Output is correct
22 Correct 35 ms 69220 KB Output is correct
23 Correct 38 ms 69268 KB Output is correct
24 Correct 36 ms 69204 KB Output is correct
25 Correct 36 ms 69260 KB Output is correct
26 Correct 37 ms 69200 KB Output is correct
27 Correct 37 ms 69192 KB Output is correct
28 Correct 35 ms 69236 KB Output is correct
29 Correct 35 ms 69196 KB Output is correct
30 Correct 36 ms 69196 KB Output is correct
31 Correct 36 ms 69220 KB Output is correct
32 Correct 38 ms 69240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 69188 KB Output is correct
2 Correct 580 ms 102388 KB Output is correct
3 Correct 544 ms 102444 KB Output is correct
4 Correct 561 ms 104140 KB Output is correct
5 Correct 586 ms 105716 KB Output is correct
6 Correct 548 ms 103896 KB Output is correct
7 Correct 526 ms 102956 KB Output is correct
8 Correct 542 ms 106652 KB Output is correct
9 Correct 549 ms 104696 KB Output is correct
10 Correct 528 ms 104008 KB Output is correct
11 Correct 554 ms 104772 KB Output is correct
12 Correct 521 ms 103928 KB Output is correct
13 Correct 528 ms 104896 KB Output is correct
14 Correct 525 ms 101660 KB Output is correct
15 Correct 553 ms 106232 KB Output is correct
16 Correct 534 ms 104364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 69188 KB Output is correct
2 Correct 530 ms 98460 KB Output is correct
3 Correct 513 ms 99800 KB Output is correct
4 Correct 536 ms 101704 KB Output is correct
5 Correct 514 ms 99904 KB Output is correct
6 Correct 524 ms 100188 KB Output is correct
7 Correct 526 ms 100256 KB Output is correct
8 Correct 543 ms 100252 KB Output is correct
9 Correct 529 ms 99996 KB Output is correct
10 Correct 521 ms 99628 KB Output is correct
11 Correct 580 ms 101596 KB Output is correct
12 Correct 551 ms 101176 KB Output is correct
13 Correct 586 ms 101488 KB Output is correct
14 Correct 515 ms 99976 KB Output is correct
15 Correct 529 ms 101544 KB Output is correct
16 Correct 513 ms 100968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 637 ms 97152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 69188 KB Output is correct
2 Correct 38 ms 69276 KB Output is correct
3 Correct 35 ms 69200 KB Output is correct
4 Correct 36 ms 69168 KB Output is correct
5 Correct 37 ms 69204 KB Output is correct
6 Correct 35 ms 69200 KB Output is correct
7 Correct 35 ms 69196 KB Output is correct
8 Correct 35 ms 69196 KB Output is correct
9 Correct 38 ms 69200 KB Output is correct
10 Correct 37 ms 69196 KB Output is correct
11 Correct 36 ms 69132 KB Output is correct
12 Correct 35 ms 69236 KB Output is correct
13 Correct 36 ms 69196 KB Output is correct
14 Correct 37 ms 69204 KB Output is correct
15 Correct 35 ms 69212 KB Output is correct
16 Correct 35 ms 69156 KB Output is correct
17 Correct 39 ms 69208 KB Output is correct
18 Correct 35 ms 69252 KB Output is correct
19 Correct 36 ms 69208 KB Output is correct
20 Correct 35 ms 69140 KB Output is correct
21 Correct 35 ms 69204 KB Output is correct
22 Correct 35 ms 69220 KB Output is correct
23 Correct 38 ms 69268 KB Output is correct
24 Correct 36 ms 69204 KB Output is correct
25 Correct 36 ms 69260 KB Output is correct
26 Correct 37 ms 69200 KB Output is correct
27 Correct 37 ms 69192 KB Output is correct
28 Correct 35 ms 69236 KB Output is correct
29 Correct 35 ms 69196 KB Output is correct
30 Correct 36 ms 69196 KB Output is correct
31 Correct 36 ms 69220 KB Output is correct
32 Correct 38 ms 69240 KB Output is correct
33 Correct 580 ms 102388 KB Output is correct
34 Correct 544 ms 102444 KB Output is correct
35 Correct 561 ms 104140 KB Output is correct
36 Correct 586 ms 105716 KB Output is correct
37 Correct 548 ms 103896 KB Output is correct
38 Correct 526 ms 102956 KB Output is correct
39 Correct 542 ms 106652 KB Output is correct
40 Correct 549 ms 104696 KB Output is correct
41 Correct 528 ms 104008 KB Output is correct
42 Correct 554 ms 104772 KB Output is correct
43 Correct 521 ms 103928 KB Output is correct
44 Correct 528 ms 104896 KB Output is correct
45 Correct 525 ms 101660 KB Output is correct
46 Correct 553 ms 106232 KB Output is correct
47 Correct 534 ms 104364 KB Output is correct
48 Correct 530 ms 98460 KB Output is correct
49 Correct 513 ms 99800 KB Output is correct
50 Correct 536 ms 101704 KB Output is correct
51 Correct 514 ms 99904 KB Output is correct
52 Correct 524 ms 100188 KB Output is correct
53 Correct 526 ms 100256 KB Output is correct
54 Correct 543 ms 100252 KB Output is correct
55 Correct 529 ms 99996 KB Output is correct
56 Correct 521 ms 99628 KB Output is correct
57 Correct 580 ms 101596 KB Output is correct
58 Correct 551 ms 101176 KB Output is correct
59 Correct 586 ms 101488 KB Output is correct
60 Correct 515 ms 99976 KB Output is correct
61 Correct 529 ms 101544 KB Output is correct
62 Correct 513 ms 100968 KB Output is correct
63 Incorrect 637 ms 97152 KB Output isn't correct
64 Halted 0 ms 0 KB -