【没A】【HDU 5654】 xiaoxin and his watermelon candy|主席树
来源:互联网 发布:asp与php 编辑:程序博客网 时间:2024/05/13 13:00
好迷啊
我本地对拍全对
然后自己造大数据 别人的ac代码 跑13s+
我的 才 3.7s 为啥我的交上去就TLE了??
题目数据专门卡我 ?
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int MAXN=2e6+10;int T,n,m;int cnt,num[MAXN],pre[MAXN],fst[MAXN],root[MAXN];inline int read(){int x=0;char c=getchar();while(c<'0'||c>'9') c=getchar();while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();return x;}struct DIAN{int x,y,z;int id;int hash;bool ok;}dian[MAXN];struct SEG{int l,r;int sum;}seg[MAXN*20];inline bool cmp1(DIAN a,DIAN b){if(a.x!=b.x) return a.x<b.x;if(a.y!=b.y) return a.y<b.y;return a.z<b.z;}inline bool cmp2(DIAN a,DIAN b){return a.id<b.id;}inline void seg_add(int &now,int last,int l,int r,int loc){if(now==0){now=++cnt;seg[now].l=0;seg[now].r=0;seg[now].sum=0;}if(l==r){seg[now].sum=seg[last].sum+1;return ;}int mid=(l+r)/2;if(loc<=mid) seg_add(seg[now].l,seg[last].l,l,mid,loc),seg[now].r=seg[last].r;else seg_add(seg[now].r,seg[last].r,mid+1,r,loc),seg[now].l=seg[last].l;seg[now].sum=seg[seg[now].l].sum+seg[seg[now].r].sum;}inline int seg_q(int LL,int RR,int l,int r,int loc){if(r<=loc){return seg[RR].sum-seg[LL].sum;}int mid=(l+r)/2;if(loc<=mid) return seg_q(seg[LL].l,seg[RR].l,l,mid,loc);else return seg_q(seg[LL].l,seg[RR].l,l,mid,loc)+seg_q(seg[LL].r,seg[RR].r,mid+1,r,loc);}int main(){T=read();while(T--){cnt=0;memset(root,0,sizeof(root));memset(fst,0,sizeof(fst));n=read();for(int i=1;i<=n;i++) num[i]=read();for(int j=1;j<=n-2;j++) {dian[j].id=j;dian[j].x=num[j];dian[j].y=num[j+1];dian[j].z=num[j+2];if(num[j]<=num[j+1]&&num[j+1]<+num[j+2])dian[j].ok=true;else dian[j].ok=false;}sort(dian+1,dian+1+n-2,cmp1);dian[1].hash=1;for(int i=2;i<=n-2;i++){if(dian[i].x==dian[i-1].x&&dian[i].y==dian[i-1].y&&dian[i].z==dian[i-1].z)dian[i].hash=dian[i-1].hash;elsedian[i].hash=dian[i-1].hash+1;}sort(dian+1,dian+1+n-2,cmp2);for(int i=1;i<=n-2;i++){if(dian[i].ok==true){pre[i]=fst[dian[i].hash];fst[dian[i].hash]=i;}elsepre[i]=n;}for(int i=1;i<=n-2;i++)seg_add(root[i],root[i-1],0,n,pre[i]);scanf("%d",&m);for(int i=1;i<=m;i++){int l,r;l=read();r=read();if(r-l<2) printf("0\n");elseprintf("%d\n",seg_q(root[l-1],root[r-2],0,n,l-1));}}return 0;}
0 0
- 【没A】【HDU 5654】 xiaoxin and his watermelon candy|主席树
- HDU 5654 xiaoxin and his watermelon candy
- HDU 5654 xiaoxin and his watermelon candy
- HDU 5654 xiaoxin and his watermelon candy 归并树
- 线段树+离线 hdu5654 xiaoxin and his watermelon candy
- dp hdu5653 xiaoxin and his watermelon candy
- HDU5654 xiaoxin and his watermelon candy 莫队
- 【HDOJ 5654】 xiaoxin and his watermelon candy(离线+树状数组)
- [hdu5654 xiaoxin and his watermelon candy]区间内不同数的个数
- 【HDU5654 BestCoder Round 77 (div1) D】【前驱位置思想 排序 树状数组】xiaoxin and his watermelon candy 区间内多少个不同连续单升三元
- A Boy and His Tree
- a boy and his tree
- a boy and his tree
- A. Watermelon
- A - Watermelon
- A. Watermelon
- A Boy and His Tree 男孩和树
- HDU 5651 xiaoxin juju needs help A/B%C
- 第二周项目4——(1)用循环求π的近似值
- Java实用篇------文件的压缩
- 1的个数
- CodeForces 632A Grandma Laura and Apples(水题)
- 第四周 项目4-程序分析(1)
- 【没A】【HDU 5654】 xiaoxin and his watermelon candy|主席树
- 第二周—输出Fibonacci数列
- CodeForces 632B Alice, Bob, Two Teams
- POJ 3069 Saruman's Army
- windows平台上用arm-none-linux-gnueabi-g++4.6.3交叉编译websocket++
- 第五周项目1-三角形锥形(1)
- 第五周项目(1)-构造三角形类(4)
- APP接口测试
- 求2个数的最大公约数