多校第七场 1004 hdu 5372 Segment Game(树状数组)
来源:互联网 发布:意大利帅哥知乎 编辑:程序博客网 时间:2024/05/29 01:53
AC代码:
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#define MAX 200007using namespace std;int c[2][MAX<<1],n,cnt;int id[MAX];int lowbit ( int x ){ return x&-x;}void add ( int x , int v , int f ){ while ( x <= cnt ) { c[f][x]+=v; x += lowbit ( x ); }}int sum ( int x , int f ){ int ret = 0; while ( x ) { ret += c[f][x]; x -= lowbit ( x ); } return ret;}struct{ int l,r,f;}a[MAX];int tid[MAX<<1];struct Node{ int v,id; bool operator < ( const Node& a ) const { return v < a.v; }}b[MAX<<1];int main ( ){ int x,y,cc=1; while ( ~scanf ( "%d" , &n ) ) { memset ( c , 0 , sizeof ( c ) ); int m = 0,op=1; for ( int i = 1 ; i <= n ; i++ ) { scanf ( "%d%d" , &x , &y ); a[i].f = x; if ( !x ) { b[m].v = y; id[op] = i-1; } else b[m].v = b[id[y]<<1].v; b[m++].id = i<<1; if ( !x ) { b[m].v = y+op; op++; } else b[m].v = b[id[y]<<1|1].v; b[m++].id = i<<1|1; } sort ( b , b+m ); cnt = 0; tid[b[0].id] = ++cnt; for ( int i = 1 ; i < m ; i++ ) if ( b[i].v == b[i-1].v ) tid[b[i].id] = cnt; else tid[b[i].id] = ++cnt; memset ( c , 0 , sizeof ( c )); for ( int i = 1 ; i <= n ; i++ ) { a[i].l = tid[i<<1]; a[i].r = tid[i<<1|1]; } printf ( "Case #%d:\n" , cc++ ); for ( int i = 1 ; i <= n ; i++ ) { int l = cnt+1-a[i].l; int r = cnt+1-a[i].r; //cout <<"yes : " << i << " " << l << " " << r << endl; //cout << l << " " << r << endl; if ( a[i].f ) { add ( l , -1 , 0 ); add ( r , -1 , 1 ); } else { //cout << sum( l-1 , 0 ) << " " << sum ( r-1 , 1 ) << endl; printf ( "%d\n" , sum( l , 0 ) - sum( r-1, 1 )); add ( l , 1 , 0 ); add ( r , 1 , 1 ); } } }}
0 0
- 多校第七场 1004 hdu 5372 Segment Game(树状数组)
- HDU 5372 Segment Game 树状数组
- 【树状数组】 HDU 5372 Segment Game
- hdu 5372 Segment Game(树状数组)
- HDU 5372 - Segment Game(树状数组)
- 【HDU 5372】Segment Game(树状数组)
- HDU 5372 Segment Game 树状数组
- HDU 5372 Segment Game(树状数组)
- [HDU 5372] Segment Game (树状数组)
- [树状数组] hdu 5372 Segment Game
- 2015多校第7场 HDU 5372 Segment Game 树状数组,思维
- hdu 5372 Segment Game 2015多校联合训练赛#7 树状数组
- HDU 5372 Segment Game(树状数组)——多校练习7
- Segment Game (hdu 5372 树状数组+离散化)
- hdu 5372 Segment Game(树状数组+离散化)
- hdu 5372 Segment Game (树状数组+离散化)
- HDU 5372 Segment Game (树状数组+离散化)
- HDU 5372 Segment Game (MUT#7 树状数组+离散化)
- 从今天开始学OC,一天一更,让我们共同进步。
- 201301 JAVA题目0-1级
- 《开源公开课分享》:Java开源框架案例视频分享
- error: Error retrieving parent for item: No resource found that matches the given name
- html笔记
- 多校第七场 1004 hdu 5372 Segment Game(树状数组)
- 30-CSS-02-CSS(和html结合的方式三四)
- 网络流
- abap chain endchain
- 数据库之Case When
- 基于消息机制的异步架构之回调函数注册
- LintCode-和大于S的最小子数组
- Codeforces Round #315 -Primes or Palindromes?(回文&&素数)
- tableView从后往前传值