死于update的一个long long写成int了

真的不想写过程了 ********

树状数组,一个平的一个斜着的,怎么斜都行

题库链接:https://nanti.jisuanke.com/t/31460

#include <iostream>
#include <cstring> #define ll long long
#define lowbit(x) (x & -x) using namespace std; const int maxn = 1e5 + ;
int n, m;
ll t[maxn];
ll t1[maxn];
ll ans[maxn]; ll search(int pos, int r)
{
ll sum = ;
r = n - r;
while (pos)
{
sum += t[pos];
sum -= r * t1[pos];
pos -= lowbit(pos);
} return sum;
} void update(int pos, int val)
{
int x = pos;
while (pos <= n)
{
t[pos] += (n - x + ) * val;
t1[pos] += val;
pos += lowbit(pos);
}
} void update1(int pos, ll val)
{
val = val - search(pos, pos) + search(pos - ,pos);
int x = pos;
while (pos <= n)
{
t[pos] += (n - x + ) * val;
t1[pos] += val;
pos += lowbit(pos);
}
} void init()
{
memset(t, , sizeof(t));
memset(t1, , sizeof(t1)); for (int i = ; i <= n; i++)
update(i, ans[i]);
} int main()
{
ios::sync_with_stdio(false);
cin >> n >> m; for (int i = ; i <= n; i++)
cin >> ans[i]; init(); while (m--)
{
int op;
ll a, b;
cin >> op >> a >> b;
if (op == )
cout << search(b, b) - search(a - , b) << endl;
else
update1(a, b);
} return ;
}

ACM-ICPC 2018徐州网络赛-H题 Ryuji doesn't want to study的更多相关文章

  1. ACM-ICPC 2018青岛网络赛-H题 Traveling on the Axis

    题目:略(不知道怎么从ZOJ搬题) 地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4054 把这题的每个点分成两种情况 ...

  2. 2018徐州网络赛H. Ryuji doesn't want to study

    题目链接: https://nanti.jisuanke.com/t/31458 题解: 建立两个树状数组,第一个是,a[1]*n+a[2]*(n-1)....+a[n]*1;第二个是正常的a[1], ...

  3. hdu 4438 第37届ACM/ICPC 天津赛区现场赛H题

    题意:Alice和Bob两个人去打猎,有两种(只)猎物老虎和狼: 杀死老虎得分x,狼得分y: 如果两个人都选择同样的猎物,则Alice得分的概率是p,则Bob得分的概率是(1-p): 但是Alice事 ...

  4. 2019 ICPC南京站网络赛 H题 Holy Grail(BF算法最短路)

    计蒜客题目链接:https://nanti.jisuanke.com/t/41305 给定的起点是S,终点是T,反向跑一下就可以了,注意判负环以及每次查询需要添加边 AC代码: #include< ...

  5. ICPC 2019 徐州网络赛

    ICPC 2019 徐州网络赛 比赛时间:2019.9.7 比赛链接:The Preliminary Contest for ICPC Asia Xuzhou 2019 赛后的经验总结 // 比赛完才 ...

  6. ACM ICPC 2018 青岛赛区 部分金牌题题解(K,L,I,G)

     目录: K Airdrop I Soldier Game L Sub-cycle Graph G Repair the Artwork ———————————————————— ps:楼主脑残有点严 ...

  7. 2018 ACM南京网络赛H题Set解题报告

    题目描述 给定\(n\)个数$a_i$,起初第\(i\)个数在第\(i\)个集合.有三种操作(共\(m\)次): 1 $u$ $v$ 将第$u$个数和第$v$个数所在集合合并 2 $u$ 将第$u$个 ...

  8. The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 K题 center

    You are given a point set with nn points on the 2D-plane, your task is to find the smallest number o ...

  9. hdu 4431 第37届ACM/ICPC 天津赛区现场赛A题 枚举

    题意:就是给了13张牌.问增加哪些牌可以胡牌.m是数字,s是条,p是筒,c是数字 胡牌有以下几种情况: 1.一个对子 +  4组 3个相同的牌或者顺子.  只有m.s.p是可以构成顺子的.东西南北这样 ...

随机推荐

  1. mySQL中插入多条记录

    用一条INSERT向SQL中插入多条记录 2008-12-22 10:07:01|  分类: 记事本_编程技术|举报|字号 订阅     Sql 语法: 插入多行记录 Insert Into Tabl ...

  2. Setup Apache2 in Debian 9 and enable two ports for two sites

    root@debian:~# apt-get install apache2 root@debian:~# cd /etc/apache2/ root@debian:/etc/apache2# ls ...

  3. alinode 配置 pm2

    今天公司要配置阿里的一个node.js性能监控(alinode),这个东西看似配置很简单但是你不知道你配置对没对, 因为他需要1分钟后才能显示出来,而且模块依赖我等了10分钟才出来, 文档的链接htt ...

  4. 10-stack

    c++ stl栈stack介绍 C++ Stack(堆栈) 是一个容器类的改编,为程序员提供了堆栈的全部功能,——也就是说实现了一个先进后出(FILO)的数据结构. c++ stl栈stack的头文件 ...

  5. Visula Studio 2013 初始化静态浮点型数据在C++类内

    class MyClass { private: static const int intvalue= 50; static const float floatvalue = 0.07f; }; 如上 ...

  6. DSA 算法

    一.简介 DSA算法是Schnorr和ElGamal签名算法的变种,被美国NIST作为DSS(DigitalSignature Standard).它是一种公开密钥算法,用作数字签名. http:// ...

  7. Android代码速查,写给新手的朋友们[转]

    原文地址:http://www.open-open.com/lib/view/open1397286499090.html 0 android 创建按钮 Button button = new But ...

  8. 洛谷 P2569[SCOI2010]股票交易(动规+单调队列)

    //只能写出裸的动规,为什么会有人能想到用单调队列优化Orz 题目描述 最近lxhgww又迷上了投资股票,通过一段时间的观察和学习,他总结出了股票行情的一些规律. 通过一段时间的观察,lxhgww预测 ...

  9. 使用python管理Cisco设备-乾颐堂

    今天发现一个老外使用python写的管理cisco设备的小框架tratto,可以用来批量执行命令. 下载后主要有3个文件: Systems.py 定义了一些不同设备的操作系统及其常见命令. Conne ...

  10. MemoryUsage:监测java虚拟机内存使用

    通过MemoryUsage可以查看Java 虚拟机的内存池的内存使用情况.MemoryUsage类有四个值(均以字节为单位): ===Init=== java虚拟机在启动的时候向操作系统请求的初始内存 ...