栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 3573 Under Attack

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 3573 Under Attack

#include<stdio.h>#include<string.h>#include<math.h>#include<iostream>#include<algorithm>#include<map>#include<set>#include<bitset>#include<vector>using namespace std;typedef int lld;#define pb push_back#define mp make_pair#define X first#define Y second#define inf 0xfffffff#define MAXN 1100#define L(x) (x<<1)#define R(x) ((x<<1)|1)const double EPS = 1e-6;lld num[15002*4],col[15002*4];void pushdown(int t,lld col[],lld num[]){ if(col[t]) { num[L(t)]+=col[t]; num[R(t)]+=col[t]; col[L(t)]+=col[t]; col[R(t)]+=col[t]; col[t]=0; }}void update(int ll,int rr,int t,int l,int r,lld num[],lld col[],lld x){ if(l!=r) pushdown(t,col,num); if(ll<=l&&r<=rr) {  col[t]+=x;  num[t]+=x;  return; } int m=(l+r)/2; if(ll<=m) update(ll,rr,L(t),l,m,num,col,x); if(rr>m) update(ll,rr,R(t),m+1,r,num,col,x);}int ansl,ansr,sl,sr;void query(int t,int l,int r,lld col[],lld num []){ if(l!=r) pushdown(t,col,num); if(l==r) { if(num[t]>ansl) {  ansl=num[t];  sl=l; } else if(num[t]==ansl&&l<sl) sl=l; if(num[t]>ansr) {  ansr=num[t];  sr=l; } else if(num[t]==ansr&&l>sr) sr=l; return; } int m=(l+r)/2; query(L(t),l,m,col,num); query(R(t),m+1,r,col,num);}int main(){ int l; while(scanf("%d",&l)!=EOF) { int ll,rr,c; memset(num,0,sizeof(num)); memset(col,0,sizeof(col)); while(scanf("%d%d%d",&ll,&rr,&c)) {  if(ll==-1) break;  update(ll,rr,1,0,l,num,col,c); } ansl=0;sl=l; ansr=0;sr=0; query(1,0,l,col,num); printf("%d %dn",sl,sr); }}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/371969.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号