답안 #938908

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938908 2024-03-05T19:33:30 Z amirhoseinfar1385 Fire (JOI20_ho_t5) C++17
1 / 100
1000 ms 40020 KB
#include<bits/stdc++.h>
using namespace std;
const long long maxn=200000+10;
long long n,q;
long long all[maxn],res[maxn],par[maxn],val[maxn],sz[maxn];
vector<pair<long long,long long>>allq[maxn];
vector<long long>adj[maxn];
pair<long long,long long>tof[maxn];

void vorod(){
	cin>>n>>q;
	for(long long i=1;i<=n;i++){
		cin>>all[i];
	}
	for(long long i=1;i<=q;i++){
		long long t,l,r;
		cin>>t>>l>>r;
		tof[i]=make_pair(l,r);
		allq[l-1].push_back(make_pair(-i,t));
		allq[r].push_back(make_pair(i,t));
	}
}

void pre(){
	vector<long long>v;
	for(long long i=1;i<=n;i++){
		while((long long)v.size()>0&&all[v.back()]<all[i]){
			v.pop_back();
		}
		if((long long)v.size()>0){
			par[i]=v.back();
			val[i]=all[v.back()]-all[i];
			adj[v.back()].push_back(i);
			sz[i]=i-par[i]-1;
		}
		v.push_back(i);
	}
}

void solve(){
	for(long long i=1;i<=n;i++){
		long long u=i;
		while(u!=0){
			sz[u]++;
			u=par[u];
		}
		for(auto x:allq[i]){
			long long mainres=0;
			for(long long j=1;j<=n;j++){
				mainres+=max(min(x.second,sz[j])-(j-par[j]-1),0ll)*val[j];
		//		if(x.first==2){
		//			cout<<"wtf: "<<j<<" "<<sz[j]<<" "<<x.second<<" "<<val[j]<<" "<<mainres<<endl;
		//		}
			}
		//	cout<<i<<" "<<mainres<<" "<<x.first<<" "<<x.second<<endl;
			if(x.first<0){
				x.first*=-1;
				mainres*=-1;
			}
			res[x.first]+=mainres;
		}
	}
}

void khor(){
	for(long long i=1;i<=q;i++){
		for(long long j=tof[i].first;j<=tof[i].second;j++){
			res[i]+=all[j];
		}
		cout<<res[i]<<"\n";
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("inp.txt","r",stdin);
	vorod();
	pre();
	solve();
	khor();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14680 KB Output is correct
2 Correct 3 ms 16828 KB Output is correct
3 Correct 3 ms 16732 KB Output is correct
4 Correct 3 ms 16732 KB Output is correct
5 Correct 3 ms 16732 KB Output is correct
6 Correct 4 ms 16732 KB Output is correct
7 Correct 3 ms 16732 KB Output is correct
8 Correct 3 ms 16732 KB Output is correct
9 Correct 3 ms 16732 KB Output is correct
10 Correct 3 ms 16732 KB Output is correct
11 Correct 4 ms 16732 KB Output is correct
12 Correct 3 ms 16732 KB Output is correct
13 Correct 3 ms 16732 KB Output is correct
14 Correct 5 ms 16832 KB Output is correct
15 Correct 3 ms 16732 KB Output is correct
16 Correct 3 ms 16912 KB Output is correct
17 Correct 3 ms 16872 KB Output is correct
18 Correct 3 ms 16732 KB Output is correct
19 Correct 3 ms 16728 KB Output is correct
20 Correct 3 ms 16732 KB Output is correct
21 Correct 4 ms 16828 KB Output is correct
22 Correct 3 ms 16732 KB Output is correct
23 Correct 4 ms 16824 KB Output is correct
24 Correct 3 ms 16732 KB Output is correct
25 Correct 3 ms 16732 KB Output is correct
26 Correct 4 ms 16880 KB Output is correct
27 Correct 3 ms 16732 KB Output is correct
28 Correct 4 ms 16732 KB Output is correct
29 Correct 4 ms 16872 KB Output is correct
30 Correct 3 ms 16876 KB Output is correct
31 Correct 5 ms 16732 KB Output is correct
32 Correct 3 ms 16732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14680 KB Output is correct
2 Execution timed out 1065 ms 39656 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14680 KB Output is correct
2 Execution timed out 1051 ms 40020 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1044 ms 39368 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14680 KB Output is correct
2 Correct 3 ms 16828 KB Output is correct
3 Correct 3 ms 16732 KB Output is correct
4 Correct 3 ms 16732 KB Output is correct
5 Correct 3 ms 16732 KB Output is correct
6 Correct 4 ms 16732 KB Output is correct
7 Correct 3 ms 16732 KB Output is correct
8 Correct 3 ms 16732 KB Output is correct
9 Correct 3 ms 16732 KB Output is correct
10 Correct 3 ms 16732 KB Output is correct
11 Correct 4 ms 16732 KB Output is correct
12 Correct 3 ms 16732 KB Output is correct
13 Correct 3 ms 16732 KB Output is correct
14 Correct 5 ms 16832 KB Output is correct
15 Correct 3 ms 16732 KB Output is correct
16 Correct 3 ms 16912 KB Output is correct
17 Correct 3 ms 16872 KB Output is correct
18 Correct 3 ms 16732 KB Output is correct
19 Correct 3 ms 16728 KB Output is correct
20 Correct 3 ms 16732 KB Output is correct
21 Correct 4 ms 16828 KB Output is correct
22 Correct 3 ms 16732 KB Output is correct
23 Correct 4 ms 16824 KB Output is correct
24 Correct 3 ms 16732 KB Output is correct
25 Correct 3 ms 16732 KB Output is correct
26 Correct 4 ms 16880 KB Output is correct
27 Correct 3 ms 16732 KB Output is correct
28 Correct 4 ms 16732 KB Output is correct
29 Correct 4 ms 16872 KB Output is correct
30 Correct 3 ms 16876 KB Output is correct
31 Correct 5 ms 16732 KB Output is correct
32 Correct 3 ms 16732 KB Output is correct
33 Execution timed out 1065 ms 39656 KB Time limit exceeded
34 Halted 0 ms 0 KB -