HDU 1698 Just a Hook (선분 트 리, 세그먼트 업데이트)
2060 단어 HDU
http://acm.hdu.edu.cn/showproblem.php?pid=1698
분석 과 총 결:
내 첫 번 째 라인 트 리 업데이트 문제... 유 여가 대 백서 + 바보 새끼 코드 보고 배 웠 어 요.
코드:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define mid ((left+right)>>1)
#define lson rt<<1,left,mid
#define rson rt<<1|1,mid+1,right
#define int64 long long
using namespace std;
const int MAXN = 100005;
int n,m;
int sum[MAXN<<2],col[MAXN<<2];
inline void push_up(int rt){
sum[rt] = sum[rt<<1] + sum[rt<<1|1];
}
inline void push_down(int rt,int m){
if(col[rt]){
col[rt<<1] = col[rt<<1|1] = col[rt];
sum[rt<<1] = (m-(m>>1)) * col[rt];
sum[rt<<1|1] = (m>>1) * col[rt];
col[rt] = 0;
}
}
void build(int rt,int left,int right){
col[rt] = 0;
sum[rt] = 1;
if(left==right)return;
build(lson);
build(rson);
push_up(rt);
}
void update(int rt,int left,int right,int l,int r,int data){
if(l<=left && right<=r) {
col[rt] = data;
sum[rt] = data*(right-left+1);
return;
}
push_down(rt, right-left+1);
int m = mid;
if(l <= m) update(lson,l,r,data);
if(r > m) update(rson,l,r,data);
push_up(rt);
}
int main(){
int T,x,y,z,cas=1;
scanf("%d", &T);
while(T--){
scanf("%d%d",&n,&m);
build(1,1,n);
for(int i=0; i<m; ++i){
scanf("%d%d%d",&x,&y,&z);
update(1,1,n,x,y,z);
}
printf("Case %d: The total value of the hook is %d.
",cas++,sum[1]);
}
return 0;
}
- 생명의 의 미 는 의 미 를 부여 하 는 데 있다.
오리지널 http://blog.csdn.net/shuangde800, By DDouble (전재 표시)
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
hdu4671(다교리그 7--수 시뮬레이션)클릭하여 링크 열기 제목: n과 서버, m개의 데이터베이스가 있고 모든 데이터베이스는 서버를 연결해야 하지만 모든 데이터베이스는 서버를 연결하는 우선순위가 있습니다.모든 데이터베이스의 서버 우선순위를 구하다.또한 한...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.