这个输入有点奇怪,你还得判断你输入的那一行有两个数还是三个
by ChenZQ @ 2024-03-19 18:54:03
这什么比题数据结构操作居然是字符串
by FerventTempo @ 2024-03-19 20:31:14
你的玄学输入恁好了吗???
by EricEnkAliTheFox @ 2024-03-20 18:34:20
@[ChenZQ](/user/745358) 求链接
by xzz_cat6 @ 2024-03-20 18:40:56
@[xiaozizhuo](/user/773813) 这是我们机构的一个网站,你看不到的,是我题目有些地方没截到你需要的吗
by ChenZQ @ 2024-03-20 19:05:40
我自己手打了一份代码,如果有TLE,请反馈我
```
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5;
typedef long long ll;
struct node{
ll l,r;
ll sum;
ll lazy;
}SegTree[maxn<<2];
void BuildTree(int rt,int l,int r){
SegTree[rt].l=l,SegTree[rt].r=r;
SegTree[rt].lazy=0;
if(l==r){
cin>>SegTree[rt].sum;
return;
}
BuildTree(rt<<1,l,(l+r)>>1);
BuildTree(rt<<1|1,((l+r)>>1)+1,r);
SegTree[rt].sum=min(SegTree[rt<<1].sum,SegTree[rt<<1|1].sum);
}
void PushDown(int rt){
if(SegTree[rt].lazy){
SegTree[rt<<1].lazy+=SegTree[rt].lazy;
SegTree[rt<<1|1].lazy+=SegTree[rt].lazy;
SegTree[rt<<1].sum+=(SegTree[rt<<1].r-SegTree[rt<<1].l+1)*SegTree[rt].lazy;
SegTree[rt<<1|1].sum+=(SegTree[rt<<1|1].r-SegTree[rt<<1|1].l+1)*SegTree[rt].lazy;
SegTree[rt].lazy=0;
}
}
void UpDate(int rt,int c,int l,int r){
if(SegTree[rt].l==l&&SegTree[rt].r==r){
SegTree[rt].lazy+=c;
SegTree[rt].sum+=(SegTree[rt].r-SegTree[rt].l+1)*c;
return;
}
if(SegTree[rt].l==SegTree[rt].r){
return;
}
PushDown(rt);
int mid=(SegTree[rt].l+SegTree[rt].r)/2;
if(r<=mid){
UpDate(rt<<1,c,l,r);
}
else if(l>mid){
UpDate(rt<<1|1,c,l,r);
}
else{
UpDate(rt<<1,c,l,mid);
UpDate(rt<<1|1,c,mid+1,r);
}
SegTree[rt].sum=min(SegTree[rt<<1].sum,SegTree[rt<<1|1].sum);
}
ll QueryTree(int rt,int l,int r){
if(SegTree[rt].l==l&&SegTree[rt].r==r){
return SegTree[rt].sum;
}
PushDown(rt);
int mid=(SegTree[rt].r+SegTree[rt].l)>>1;
ll ans;
if(r<=mid){
ans=QueryTree(rt<<1,l,r);
}
else if(l>mid){
ans=QueryTree(rt<<1|1,l,r);
}
else{
ans=min(QueryTree(rt<<1,l,mid),QueryTree(rt<<1|1,mid+1,r));
}
return ans;
}
int main(){
int n,m;
cin>>n;
BuildTree(1,1,n);
cin>>m;
getchar();
while(m--){
string s;
getline(cin,s);
int a=0,b=0,c=0,j=0,t=s.size();
while(j<t && isdigit(s[j])) a=a*10+s[j]-'0',j++;
j++;
while(j<t && isdigit(s[j])) b=b*10+s[j]-'0',j++;
if(j+2>t){
//cout<<a<<' '<<b<<endl;
cout<<QueryTree(1,a,b)<<endl;
}
else{
j++;
int flag=0;
while((s[j]=='-' || isdigit(s[j])) && j<t)
{
if(s[j]=='-') flag=-1;
else c=c*10+s[j]-'0';
j++;
}
cin>>c;
UpDate(1,c,a,b);
}
}
return 0;
}
```
@[ChenZQ](/user/745358)
by xzz_cat6 @ 2024-03-20 20:23:18
@[ChenZQ](/user/745358) 输入我实在不理解
by Acerakoi @ 2024-03-20 20:32:17
@[Acerakoi](/user/514850) 输入就是每次输入一行字符串,你需要判断字符串中有两个数还是三个数
by ChenZQ @ 2024-03-20 20:39:47
@[Acerakoi](/user/514850) 说实话这么离谱的输入我也是第一次间
by ChenZQ @ 2024-03-20 20:40:05
@[xiaozizhuo](/user/773813) ![](https://cdn.luogu.com.cn/upload/image_hosting/8bkhx1x0.png)
by ChenZQ @ 2024-03-20 20:41:22