Problem Youngling Tournament

题目大意

  给一个序列a[i],每次操作可以更改一个数,每次询问 将序列排序后有多少个数a[i]>=sum[i-1]。

  n<=10^5,q<=5*10^4,a[i]<=10^12

解题分析

  可以发现,在最优情况下,该序列长度最多为logn。

  将询问离线后,用multiset来维护a[i],用树状数组来维护sum[i]。树状数组所存下标为离散化后的a[i]。

  每次查询时跳跃式地在set中查找。

  时间复杂度 O((n+m)log(n+m)+mlognlogn)

参考程序

 #include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#pragma comment(linker,"/STACK:102400000,102400000")
using namespace std; #define N 100008
#define M 50008
#define LL long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define clr(x,v) memset(x,v,sizeof(x));
#define bitcnt(x) __builtin_popcount(x)
#define rep(x,y,z) for (int x=y;x<=z;x++)
#define repd(x,y,z) for (int x=y;x>=z;x--)
const int mo = ;
const int inf = 0x3f3f3f3f;
const int INF = ;
/**************************************************************************/ int n,m,tot,flag;
LL a[N],c[N],x[N*];
int b[N];
multiset<long long> S;
struct Binary_Indexed_Tree{
LL a[N*];
void clear(){
clr(a,);
}
void insert(int x,LL val){
for (int i=x;i<=N<<;i+=i & (-i))
a[i]+=val;
}
LL sigma(int x){
LL res=;
for (int i=x;i>;i-=i & (-i))
res+=a[i];
return res;
}
LL query(int x,int y){
return sigma(y)-sigma(x-);
}
}T;
int id(LL xy){
return lower_bound(x+,x+tot+,xy)-x;
}
set <long long> :: iterator it,it1;
void query(){
int ans=; LL tmp;
it = S.begin();
it1 = it ; it1++;
if (*it==*it1) ans++;
tmp=T.sigma(id(*it));
while (){
it = S.lower_bound(tmp);
if (it==S.begin()) it++;
if (it==S.end()) break;
it1 = it; it1--;
tmp=T.sigma(id(*it1));
if (*it>=tmp) ans++;
tmp=T.sigma(id(*it));
}
printf("%d\n",ans); } int main(){
scanf("%d",&n);
rep(i,,n){
scanf("%lld",&a[i]);
x[++tot]=a[i];
}
scanf("%d",&m);
rep(i,,m){
scanf("%d%lld",&b[i],&c[i]);
x[++tot]=c[i];
}
sort(x+,x+tot+);
tot=unique(x+,x+tot+)-x;
T.clear();
rep(i,,n){
T.insert(id(a[i]),a[i]);
S.insert(a[i]);
}
query();
rep(i,,m){
S.erase(S.find(a[b[i]]));
T.insert(id(a[b[i]]),-a[b[i]]);
S.insert(c[i]);
T.insert(id(c[i]),c[i]);
a[b[i]]=c[i];
query();
} }

Gym 100960G (set+树状数组)的更多相关文章

  1. Gym - 101755G Underpalindromity (树状数组)

    Let us call underpalindromity of array b of length k the minimal number of times one need to increme ...

  2. CF Gym 100463A (树状数组求逆序数)

    题意:给你一个序列,和标准序列连线,求交点数. 题解:就是求逆序对个数,用树状数组优化就行了.具体过程就是按照顺序往树状数组了插点(根据点的大小),因为第i大的点应该排在第i位,插进去的时候他前面本该 ...

  3. GYM 100741A Queries(树状数组)

    A. Queries time limit per test 0.25 seconds memory limit per test 64 megabytes input standard input ...

  4. GYM 101889F(树状数组)

    bit扫描坐标套路题,注意有重复的点,莽WA了. const int maxn = 1e5 + 5; struct node { ll B, F, D; bool operator < (con ...

  5. Codeforces Gym 100114 H. Milestones 离线树状数组

    H. Milestones Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descripti ...

  6. Gym 101908C - Pizza Cutter - [树状数组]

    题目链接:https://codeforces.com/gym/101908/problem/C 题意: 一块正方形披萨,有 $H$ 刀是横切的,$V$ 刀是竖切的,不存在大于等于三条直线交于一点.求 ...

  7. Codeforces Gym 100269F Flight Boarding Optimization 树状数组维护dp

    Flight Boarding Optimization 题目连接: http://codeforces.com/gym/100269/attachments Description Peter is ...

  8. Gym - 100269F Flight Boarding Optimization(dp+树状数组)

    原题链接 题意: 现在有n个人,s个位置和你可以划分长k个区域你可以把s个位置划分成k个区域,这样每个人坐下你的代价是该区域内,在你之前比你小的人的数量问你怎么划分这s个位置(当然,每个区域必须是连续 ...

  9. 【容斥原理】【推导】【树状数组】Gym - 101485G - Guessing Camels

    题意:给你三个1~n的排列a,b,c,问你在 (i,j)(1<=i<=n,1<=j<=n,i≠j),有多少个有序实数对(i,j)满足在三个排列中,i都在j的前面. 暴力求的话是 ...

随机推荐

  1. Java Code Examples for PhantomJSDriverService

    Example 1 Project: thucydides   File: PhantomJSCapabilityEnhancer.java View source code Vote up 6 vo ...

  2. Log4Net 配置SQL2008数据库 并传入自定义业务对象

    最近根据业务需要,俺们老大要求我们了解一个c#的组件——Log4Net 这玩意儿从来没弄过,感觉挺深奥的,结果经过2天的研究,还算小有所成吧,基本思路已经清晰明了了,不过过程中遇到一些很奇葩的问题,和 ...

  3. XMLHttpRequest 加载进度

    XMLHttpRequest 相关资料请移步这里直接查看,我这里就不在赘述: https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpReque ...

  4. 使用hue+oozi构建任务调度系统

    oozie调度系统调研 1. 关于oozie的简单说明 oozie应用程序目录结构说明: 一个完整的oozie应用程序一般情况下至少包含三个文件及目录:job.properties.workflow. ...

  5. 《BI项目笔记》创建时间维度(1)

    SSAS Date 维度基本上在所有的 Cube 设计过程中都存在,很难见到没有时间维度的 OLAP 数据库.但是根据不同的项目需求, Date 维度的设计可能不大相同,所以在设计时间维度的时候需要搞 ...

  6. WebSocket实战之————Workerman服务器的安装启动

    安装php apt-get install php5-cli root@iZ23b64pe35Z:/home/www# php -v PHP 5.5.9-1ubuntu4.20 (cli) (buil ...

  7. Windows下安装postgresql_psycopg2时出现 "Unabled to find vcvarsall.bat" 的解决办法

    使用django时会用到postgresql的数据库,如下表: 数据库引擎设置 设置 数据库 适配器 postgresql PostgreSQL psycopg 版本 1.x, http://www. ...

  8. 【UFLDL】Exercise: Convolutional Neural Network

    这个exercise需要完成cnn中的forward pass,cost,error和gradient的计算.需要弄清楚每一层的以上四个步骤的原理,并且要充分利用matlab的矩阵运算.大概把过程总结 ...

  9. android定义启动唯一apk

    <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="ht ...

  10. Python 去剑式

    Python 去剑式 种种变化,用以体演总诀.共有三百六十种变化. 用以破解普天下各门各派的剑法.「破剑式」虽只一式,但其中于天下各门各派剑法要义兼收并蓄:虽说「无招」却是以普天下剑法之招数为根基,因 ...