- 差分(模板)
SGOJ644/680
- 2022-10-2 11:14:17 @
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <string>
#include <stdlib.h>
#include <ctype.h>
#include <algorithm>
using namespace std;
int a[5000005],n,q,x,y,z,minn=99999999;
int main(){
scanf("%d%d",&n,&q);
for(int i=1;i<=n;++i)scanf("%d",&a[i]);
for(int i=0;i<q;++i){
scanf("%d%d%d",&x,&y,&z);
for(;x<=y;++x)a[x]+=z;
}
for(int i=1;i<=n;++i)if(minn>a[i])minn=a[i];
printf("%d",minn);
return 0;
}
1 条评论
-
chjshen 教练 LV 5 SU @ 2023-7-12 9:06:50
#include<iostream> #include<cstdio> using namespace std; const int N = 1E5 + 5; int n, m, a[N], d[N]; int x, y; void handle() { int L, R , t; cin >> L >> R >> t; int k = (t == 1 ? x : -y); d[L] += k; d[R + 1] -= k; } void show() { for(int i = 1; i <= n; i++) { a[i] = a[i - 1] + d[i]; cout << a[i] << " "; } cout << endl; } void initInput() { ios::sync_with_stdio(0); cin >> n >> m >> x >> y; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++) d[i] = a[i] - a[i - 1]; while(m--) handle(); show(); } int main(void) { initInput(); return 0; }
- 1
信息
- ID
- 644
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 6
- 标签
- 递交数
- 373
- 已通过
- 103
- 上传者