传送门:zoj 3279 Ants

Ants


Time Limit: 2 Seconds      Memory Limit: 32768 KB

echo is a curious and clever girl, and she is addicted to the ants recently.

She knows that the ants are divided into many levels depends on ability, also, she finds the number of each level will change.

Now, she will give two kinds of operations as follow :

First, "p a b", the number of ants in level a change to b.

Second, "q x", it means if the ant's ability is rank xth in all ants, what level will it in?

Input

There are multi-cases, and you should use EOF to check whether it is in the end of the input. The first line is an integer n, means the number of level. (1 <= n <= 100000). The second line follows n integers, the ith integer means the number in level i. The third line is an integer k, means the total number of operations. Then following k lines, each line will be "p a b" or "q x", and 1 <= x <= total ants, 1 <= a <= n, 0 <= b. What's more, the total number of ants won't exceed 2000000000 in any time.

Output

Output each query in order, one query each line.

Sample Input

3
1 2 3
3
q 2
p 1 2
q 2

Sample Output

2
1

Author: Lin, Yue
Source: ZOJ Monthly, December 2009

 

题意:

给你每个等级蚂蚁的数量 有两种操作:

(1)rank x的蚂蚁的等级是多少

(2)将等级为a的数量更改为b

题解:

还是一个简单的线段树,处理区间要仔细(调了一晚上bug-.-)

代码:

#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <utility>
#include <vector>
#define mem(arr, num) memset(arr, 0, sizeof(arr))
#define _for(i, a, b) for (int i = a; i <= b; i++)
#define __for(i, a, b) for (int i = a; i >= b; i--)
#define IO                     \
  ios::sync_with_stdio(false); \
  cin.tie();                  \
  cout.tie();
using namespace std;
typedef long long ll;
const ll inf = 0x3f3f3f3f;
;
const ll mod = 1000000007LL;
 << ;
ll dat[N];
int num;
int tree_node;
void init(int n)
{
    tree_node = ;
    while(tree_node < n)
        tree_node <<= ;
    _for(i, , tree_node *  -) dat[i] = ;
}
void update(int pos, int date)
{
    pos += tree_node - ;
    dat[pos] = date;
    )
    {
        pos >>= ;
        dat[pos] = dat[pos<<] + dat[pos<<|];
    }
}
int query(int rank, int k)
{
    )
        return k;
    ])
        );
    else
        ], k<<|);
}
void solve()
{
    ll x,p,q;
    char str;
    _for(i, , num)
    {
        scanf("%lld",&x);
        update(i,x);
    }
    scanf("%lld",&x);

    ; i <= x; i++)
    {
        getchar();
        scanf("%c",&str);
        if(str=='q')
        {
            scanf("%lld",&p);
            ])
            {
                printf("%d\n",num);
            }
            else
                printf() - tree_node + );
        }
        else
        {
            scanf("%lld%lld",&p,&q);
            update(p,q);
        }
    }
}
int main()
{

    while(scanf("%d",&num)!=EOF)
    {
        init(num);
        solve();
    }
    ;
}

ZOJ 3279-Ants(线段树)的更多相关文章

  1. ZOJ - 1610 经典线段树染色问题

    这个是一个经典线段树染色问题,不过题目给的是左右左右坐标,即[0,3]包含0-1这一段 1-2这一段 2-3这一段,和传统的染色不太一样,不过其实也不用太着急. 我们把左边的坐标+1,即可,那么[0, ...

  2. zoj 3349 dp + 线段树优化

    题目:给出一个序列,找出一个最长的子序列,相邻的两个数的差在d以内. /* 线段树优化dp dp[i]表示前i个数的最长为多少,则dp[i]=max(dp[j]+1) abs(a[i]-a[j])&l ...

  3. 线段树区间染色 ZOJ 1610

    Count the Colors ZOJ - 1610 传送门 线段树区间染色求染色的片段数 #include <cstdio> #include <iostream> #in ...

  4. ZOJ 1610 Count the Colors (线段树区间更新)

    题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...

  5. ZOJ 3597 Hit the Target! (线段树扫描线 -- 矩形所能覆盖的最多的点数)

    ZOJ 3597 题意是说有n把枪,有m个靶子,每把枪只有一发子弹(也就是说一把枪最多只能打一个靶子), 告诉你第 i 把枪可以打到第j个靶, 现在等概率的出现一个连续的P把枪,在知道这P把枪之后,你 ...

  6. zoj 3511 Cake Robbery(线段树)

    problemCode=3511" target="_blank" style="">题目链接:zoj 3511 Cake Robbery 题目 ...

  7. ZOJ 1859 Matrix Searching(二维线段树)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1859 Matrix Searching Time Limit: 10 Seco ...

  8. zoj 1610 Count the Colors(线段树延迟更新)

    所谓的懒操作模板题. 学好acm,英语很重要.做题的时候看不明白题目的意思,我还拉着队友一块儿帮忙分析题意.最后确定了是线段树延迟更新果题.我就欣欣然上手敲了出来. 然后是漫长的段错误.... 第一次 ...

  9. 主席树[可持久化线段树](hdu 2665 Kth number、SP 10628 Count on a tree、ZOJ 2112 Dynamic Rankings、codeforces 813E Army Creation、codeforces960F:Pathwalks )

    在今天三黑(恶意评分刷上去的那种)两紫的智推中,突然出现了P3834 [模板]可持久化线段树 1(主席树)就突然有了不详的预感2333 果然...然后我gg了!被大佬虐了! hdu 2665 Kth ...

随机推荐

  1. 用HTML5 File API 实现截图粘贴上传、拖拽上传

    <!DOCTYPE html><html><head> <title>test chrome paste image</title> < ...

  2. 删除linux上7天前后缀名.sql的文件

    #!/bin/bash#delete the file of 7 days agofind /data/mysqlbackup/ -mtime +7 -name "*.sql" - ...

  3. 基于FPGA的HDTV视频图像灰度直方图统计算法设计

    随着HDTV的普及,以LCD-TV为主的高清数字电视逐渐进入蓬勃发展时期.与传统CRT电视不同的是,这些高清数字电视需要较复杂的视频处理电路来驱动,比如:模数转换(A/D Converter).去隔行 ...

  4. [cerc2012][Gym100624B]20181013

  5. FJOI游记(日记向 不定期更新)

    emmmm说实话只是突发奇想开个blog记录记录自己的内心想法罢了.. 2017/12/22:刷了一周的计算几何..刷的死去活来..结果还是被D惨了...譬如都不会考,要考我都不会什么的...感觉内心 ...

  6. C++之容器

    容器,迭代器与容器适配器 所谓容器,即是将最常运用的一些数据结构(data structures)用类模板实现出来,用于容纳特定类型的对象.根据数据在容器中排列的特性,容器可概分为序列式(sequen ...

  7. Linux-进程间通信(三): 共享内存

    1. 共享内存: 共享内存方式可以在多个进程直接共享数据,因为其直接使用内存,不要多余的拷贝,是速度最快的IPC方式: 共享内存有两种实现方式,使用mmap和shm方式,如下图: (1) mmap方式 ...

  8. golang相关问题

          [转载][翻译]Go的50坑:新Golang开发者要注意的陷阱.技巧和常见错误[1] Golang作为一个略古怪而新的语言,有自己一套特色和哲学.从其他语言转来的开发者在刚接触到的时候往往 ...

  9. JDBC数据源连接池(2)---C3P0

    我们接着<JDBC数据源连接池(1)---DBCP>继续介绍数据源连接池. 首先,在Web项目的WebContent--->WEB-INF--->lib文件夹中添加C3P0的j ...

  10. Redis在CentOS 7上的安装部署

    简介: Redis是一种高级key-value数据库.它跟memcached类似,不过数据可以持久化,而且支持的数据类型很丰富.有字符串,链表,集 合和有序集合.支持在服务器端计算集合的并,交和补集( ...