hdu1166敌兵布阵
来源:互联网 发布:neon软件官网 编辑:程序博客网 时间:2024/05/21 10:01
靠 你知道我为什么一直TML吗!!!啊 我猜你肯定不知道 我改了一天的代码啊 一整天啊 没想到居然是用了cin和cout
一直就听说cin会很慢 没想到居然会这么慢 累觉不爱啊 感觉以后再也不会用cin cout了
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;struct treel{ int left,right; int cover;}t[500000];int n,m;int sum=0;int cover[50005];void build(int l,int r,int step){ t[step].left=l; t[step].right=r; if(l==r) { t[step].cover+=cover[l]; return ; } build(l,(l+r)/2,step*2); build((l+r)/2+1,r,step*2+1); if(l!=r) t[step].cover=t[step*2].cover+t[step*2+1].cover;}void Insert(int c,int d,int step){ if(c==t[step].left&&c==t[step].right) { t[step].cover=t[step].cover+d; return; } int mid=(t[step].left+t[step].right)>>1; if(c<=mid) Insert(c,d,step*2); if(c>mid) Insert(c,d,step*2+1); t[step].cover+=d;}void Find(int c,int d,int step){ if (c==t[step].left&&d==t[step].right) { sum=sum+t[step].cover; return; } int mid=(t[step].left+t[step].right)>>1; if (mid>=d) Find(c,d,step*2); else if(mid<c) Find(c,d,step*2+1); else { Find(c,mid,step*2); Find(mid+1,d,step*2+1); }}int main(){ int T,i,x,y; scanf("%d",&T); int z=1; while(T--) { scanf("%d",&n); memset(t,0,sizeof(struct treel)*500000); for(i=1; i<=n; i++) { cover[i]=0; scanf("%d",&cover[i]); } build(0,n,1); char que[10]; printf("Case %d:\n",z++); while(1) { scanf("%s",que); if(strcmp(que,"End")==0) break; scanf("%d%d",&x,&y); sum=0; if(strcmp(que,"Query")==0) { Find(x,y,1); printf("%d\n",sum); } else if(strcmp(que,"Add")==0) Insert(x,y,1); else Insert(x,-y,1); } } return 0;}
0 0
- hdu1166 敌兵布阵
- hdu1166 敌兵布阵
- HDU1166 敌兵布阵
- hdu1166 敌兵布阵
- hdu1166 敌兵布阵
- hdu1166(敌兵布阵)
- HDU1166:敌兵布阵
- hdu1166敌兵布阵
- HDU1166--敌兵布阵
- HDU1166 敌兵布阵
- hdu1166 敌兵布阵
- hdu1166 敌兵布阵
- hdu1166敌兵布阵
- hdu1166敌兵布阵
- hdu1166 敌兵布阵
- HDU1166 敌兵布阵
- hdu1166 敌兵布阵
- hdu1166敌兵布阵
- android环境下window adb库的编译。
- SDUT 2171 - 上升子序列
- 微软编程一小时 题目2 : Longest Repeated Sequence
- stm32下载方式之串口ISP\swd
- Ubuntu修改Hosts文件工具HostsTool使用说明
- hdu1166敌兵布阵
- Java实现表达式的运算-Android简易计算器
- 奇怪的分式
- Android 监听ContentProvider中数据的变化
- 当Yii遇上不支持pdo_mysql的服务器
- 总结使用Get、Post、Socket三种方式连接服务端与传输数据的步骤
- 安卓如何关闭软键盘?
- hdu 1562 两个月之后再看搜索
- plsql loop循环