UESTC
来源:互联网 发布:c语言病毒吃内存 编辑:程序博客网 时间:2024/06/03 16:11
Car race game
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
Bob is a game programming specialist. In his new car race game, there are some racers(
Input
The first line of the input contains an integer
Output
For each data set in the input print on a separate line, on the standard output, the integer that represents the maximal amount of overtaking.
Sample input and output
22 12 252 69 43 14 99 175 56 105 63 109 109 52 2
167
#include<string.h>#include<stdio.h>#include<algorithm>using namespace std;struct data{ int pos,speed; int P=0;} y[1000003],x[1000003];long long a[1000033];long long c[1000003];long long n;bool cmp(data a,data b){ if(a.pos==b.pos) return a.speed>b.speed; return a.pos<b.pos;}bool cmp1(data a,data b){ if(a.speed==b.speed) return a.pos<b.pos; return a.speed<b.speed;}long long lowbit(long long x){ return x&(-x);}void update(long long x){ while(x<=n) { c[x]+=1; x+=lowbit(x); }}long long getsum(long long x){ long long sum=0; while(x>0) { sum+=c[x]; x-=lowbit(x); } return sum;}int main(){ while(scanf("%d",&n)==1) { memset(c,0,sizeof(c)); for(long long i=1; i<=n; i++) { scanf("%lld%lld",&x[i].pos,&x[i].speed); } sort(x+1,x+1+n,cmp); for(long long i=1;i<=n;i++) { y[i].pos=i; y[i].speed=x[i].speed; } sort(y+1,y+1+n,cmp1); long long res=0; for(long long i=1; i<=n; i++) { a[y[i].pos]=i; } for(int i=1; i<=n; i++) { update(a[i]); res+=(i-getsum(a[i])); } printf("%lld\n",res); }}
- UESTC
- UESTC
- UESTC
- UESTC
- UESTC
- UESTC
- UESTC
- UESTC
- UESTC
- UESTC
- UESTC
- UESTC
- UESTC
- UESTC
- UESTC
- UESTC
- UESTC
- UESTC
- codeforces 428(div2) A-D
- 【《Real-Time Rendering 3rd》 提炼总结】(五) 第六章 · 纹理贴图及相关技术 The Texturing
- vue.js单文件组件中非父子组件的传值
- [HDU
- Postgresql 异步流复制 详解及配置切换
- UESTC
- 【《Real-Time Rendering 3rd》 提炼总结】(四) 第五章 · 图形渲染与视觉外观 The Visual Appearance
- ftp上传和下载
- 如何正确使用Git Flow
- QT功能1:点击按钮,显示图片
- 【理论实践】快速认识allocator,并不神奇但吓退一片的内存管理机制:内存分配和对象构造分离
- poj 2553 The Bottom of a Graph 强连通缩点
- 记录一 MVC框架
- replaceAll小心使用