跳到正文

题解

P1531

ZZZZZhanggggg约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年7月4日
收录
2025年12月12日
更新
2026年10月27日
篇幅
约 1 分钟
题目
P1531

版本

  1. v1当前

前言:

翻遍了题解,貌似没有这个做法


上代码

C++
#include<bits/stdc++.h>
using namespace std;
#define lld long long
const int N=1e5+10;
map<pair<int,int>,int> mp;
int n,m,sc[2*N],x,y,ans;
char op;
int dfs(int s){
	if(s==y){
		return sc[s];
	}else{
		return max(sc[s],dfs(s+1));
	}
}
int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>sc[i];
	while(m--){
		cin>>op>>x>>y;
		if(op=='Q'){
			int flag=mp[{x,y}];
			if(!flag){
				ans=dfs(x);
				mp[{x,y}]=ans;
			}else{
				ans=mp[{x,y}];
			}
			cout<<ans<<endl;
		}else{
			sc[x]=max(y,sc[x]);
			mp.clear();
		}
	}
	return 0;
}

AC记录

原文