1488 Problem J-qwb又偷懒了
来源:互联网 发布:沃尔沃销售数据 编辑:程序博客网 时间:2024/04/27 18:18
思路:
离散化点查点插线段树
#include <iostream>#include <algorithm>#include <stdio.h>#include <cstring>#include <map>using namespace std;const int maxn=300005;int has[1000005];int step[maxn];int id[maxn];struct node{ int left,right; long long sum,num;}tree[maxn*4];struct ct2{ int left, right ;}oper2[maxn*2];struct ct1{ int num,id,fir,kind;}oper1[maxn*2];int n; void push_up(int i){ tree[i].sum=tree[i<<1].sum+tree[i<<1|1].sum; tree[i].num=tree[i<<1].num+tree[i<<1|1].num; return ;}void build(int i,int left,int right){ tree[i].left=left,tree[i].right=right; tree[i].num=0; tree[i].sum=0; if(left==right) { return ; } int mid=(tree[i].left+tree[i].right)>>1; build(i<<1,left,mid); build(i<<1|1,mid+1,right); return ;}void add(int i,int aim){ if(tree[i].left==tree[i].right&&tree[i].left==aim) { tree[i].sum+=has[tree[i].left]; tree[i].num++; return ; } int mid=(tree[i].left+tree[i].right)>>1; if(aim<=mid) add(i<<1,aim); else add(i<<1|1,aim); push_up(i); return ;}long long ans,peo;void query(int i,int left,int right){ if(tree[i].left==left&&tree[i].right==right) { ans+=tree[i].sum; peo+=tree[i].num; return ; } int mid=(tree[i].left+tree[i].right)>>1; if(right<=mid) query(i<<1,left,right); else if(left>mid) query(i<<1|1,left,right); else { query(i<<1,left,mid); query(i<<1|1,mid+1,right); } return ;}bool cmpnum(ct1 x,ct1 y){ return x.num<y.num;}bool cmpfir(ct1 x,ct1 y){ return x.fir<y.fir;}int main(){ int xc=1; while(scanf("%d",&n)!=EOF) { memset(has,0,sizeof(has)); map<int,int>mp; if(xc!=1) printf("\n"); xc++; int n1=0,n2=0; for(int i=1;i<=n;i++) { int op; scanf("%d",&op); if(op==0) { step[i]=1; scanf("%d",&oper1[++n1].num); oper1[n1].fir=i; oper1[n1].kind=1; } else { step[i]=2; scanf("%d",&oper2[++n2].left); scanf("%d",&oper2[n2].right); oper1[++n1].kind=2; oper1[n1].fir=n*2+1; oper1[n1].num=oper2[n2].left; oper1[++n1].kind=2; oper1[n1].fir=n*2+1; oper1[n1].num=oper2[n2].right; } } int all=0,numm2=0; sort(oper1+1,oper1+1+n1,cmpnum); oper1[0].num=-1; for(int i=1;i<=n1;i++) { if(oper1[i].num!=oper1[i-1].num) { oper1[i].id=++all; mp[oper1[i].num]=all; has[all]=oper1[i].num; } else { oper1[i].id=all; } } sort(oper1+1,oper1+1+n1,cmpfir); build(1,1,all); int nm1=0,nm2=0; for(int i=1;i<=n;i++) { if(step[i]==1) { ++nm1; add(1,oper1[nm1].id); } else { ans=0,peo=0; ++nm2; query(1,mp[oper2[nm2].left],mp[oper2[nm2].right]); if(peo==0) { printf("zhizhiwuwu\n"); continue; } long long res=ans/(peo); printf("%lld\n",res); } } }} /* 30 10 31 0 3 */ /************************************************************** Problem: 1488 User: ZJC2017Final379 Language: C++ Result: Accepted Time:904 ms Memory:55584 kb****************************************************************/
阅读全文
0 0
- 1488 Problem J-qwb又偷懒了
- 之江学院2017ACM 校赛 Problem J: qwb又偷懒了(树状数组)
- 之江学院 2017 J qwb又偷懒了 树状数组
- qwb又偷懒了 思路+代码
- 2017年第0届浙江工业大学之江学院程序设计竞赛决赛—J qwb又偷懒了
- 2017年第0届浙江工业大学之江学院程序设计竞赛决赛 J: qwb又偷懒了 [BIT]【数据结构】
- J-LINK又烧了?
- 偷懒了
- 偷懒了
- Problem A: qwb与支教
- Problem B: qwb与矩阵
- Problem G: qwb去面试
- Problem J
- Problem J
- Problem J
- Problem-J
- Problem J
- Problem-J
- GN使用
- alpha-beta剪枝
- 33.TextView控件(界面上显示一段文本信息)
- iOS Runtime应用小例子 不引入类怎么创建这个类的对象和执行类的方法
- 解决Setting property 'source' to 'org.eclipse.jst.jee.server的问题
- 1488 Problem J-qwb又偷懒了
- 机器学习小分队练习题
- Ubuntu安装OpenSSL
- jsp 使用input标签 file 如何上传多个文件
- codeforces 812 B Sagheer, the Hausmeister(枚举)
- 阿里顺丰互相拉黑,刘强东却为何要力挺顺丰?
- Android Studio 生成aar包和jar包
- 冒泡排序详解
- 便条-逐行读取文件并对其更改