C++代码

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
int n,a[10000],t,d[10000];
int main(){
    cin>>n>>t;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(i==1) d[i]=a[i];
		else d[i]=a[i]-a[i-1];
	}
	while(t--){
		int x,y,v;
		cin>>x>>y>>v;
		d[x]+=v;
		d[y+1]-=v;
	}
	for(int i=1;i<=n;i++){
		a[i]=a[i-1]+d[i];
	}
	for(int i=1;i<=n;i++){
		cout<<a[i]<<" ";
	}
	return 0;
}
cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
int n,a[10000],t,d[10000],ma=-1;
int main(){
    cin>>n>>t;
	while(t--){
		int v,f,to;
		cin>>v>>f>>to;
		d[f]+=v;
		d[to-1]-=v;
		ma=max(ma,to);
	}
	bool b=true;
	for(int i=1;i<=n;i++){
		a[i]=a[i-1]+d[i];
		if(a[i]>n) b=false;break;
	}
	if(b==true) cout<<"true";
	else cout<<"false";
	return 0;
}
cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
int n,a[10000],t,d[10000],ma=-1;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		int x,y;
		cin>>x>>y;
		d[x]++;
		d[y-1]--;
	}
	for(int i=1;i<=n;i++){
		a[i]=a[i-1]+d[i];
		ma=max(ma,a[i]);
	}
	cout<<ma;
	return 0;
}
相关推荐
wuyk5551 小时前
【Socket 进阶之路】第 9 章 Linux 网络服务量产稳定性优化|心跳保活、TIME_WAIT、SO_LINGER、内存池、断线重连、完整异常防护框架
linux·服务器·开发语言·网络·物联网
木子算法1 小时前
不是重心也不是中点:费马—韦伯点、它的最优性条件与迭代求解
人工智能·算法·目标跟踪
邪修king1 小时前
Re:Linux 系统篇(三十四):进程间通信开篇Chapter1 —— 匿名管道 pipe 深度拆解与代码实战
android·linux·运维·开发语言
程序员AlbertTu2 小时前
# Mantissa 使用教程 — Python 版与 C++ 版
c++·python·数值运算
孙启超2 小时前
【AI开发之Rust】第 13 课:async/await 与 tokio 异步运行时
开发语言·后端·rust
Am-Chestnuts2 小时前
DeepSeek内容转Word有哪几种方法?用DS随心转对比6条主流路径
开发语言·人工智能
大黄说说2 小时前
App 启动速度优化:冷启动从 3s 降到 800ms 完整实操
开发语言
Lazionr2 小时前
多态:从多种形态到运行时绑定
开发语言·c++