ACM-ICPC 2018徐州网络赛-H题 Ryuji doesn't want to study
死于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的更多相关文章
- ACM-ICPC 2018青岛网络赛-H题 Traveling on the Axis
题目:略(不知道怎么从ZOJ搬题) 地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4054 把这题的每个点分成两种情况 ...
- 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], ...
- hdu 4438 第37届ACM/ICPC 天津赛区现场赛H题
题意:Alice和Bob两个人去打猎,有两种(只)猎物老虎和狼: 杀死老虎得分x,狼得分y: 如果两个人都选择同样的猎物,则Alice得分的概率是p,则Bob得分的概率是(1-p): 但是Alice事 ...
- 2019 ICPC南京站网络赛 H题 Holy Grail(BF算法最短路)
计蒜客题目链接:https://nanti.jisuanke.com/t/41305 给定的起点是S,终点是T,反向跑一下就可以了,注意判负环以及每次查询需要添加边 AC代码: #include< ...
- ICPC 2019 徐州网络赛
ICPC 2019 徐州网络赛 比赛时间:2019.9.7 比赛链接:The Preliminary Contest for ICPC Asia Xuzhou 2019 赛后的经验总结 // 比赛完才 ...
- ACM ICPC 2018 青岛赛区 部分金牌题题解(K,L,I,G)
目录: K Airdrop I Soldier Game L Sub-cycle Graph G Repair the Artwork ———————————————————— ps:楼主脑残有点严 ...
- 2018 ACM南京网络赛H题Set解题报告
题目描述 给定\(n\)个数$a_i$,起初第\(i\)个数在第\(i\)个集合.有三种操作(共\(m\)次): 1 $u$ $v$ 将第$u$个数和第$v$个数所在集合合并 2 $u$ 将第$u$个 ...
- 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 ...
- hdu 4431 第37届ACM/ICPC 天津赛区现场赛A题 枚举
题意:就是给了13张牌.问增加哪些牌可以胡牌.m是数字,s是条,p是筒,c是数字 胡牌有以下几种情况: 1.一个对子 + 4组 3个相同的牌或者顺子. 只有m.s.p是可以构成顺子的.东西南北这样 ...
随机推荐
- JS中深拷贝数组、对象、对象数组方法(转载)
我们在JS程序中需要进行频繁的变量赋值运算,对于字符串.布尔值等可直接使用赋值运算符 “=” 即可,但是对于数组.对象.对象数组的拷贝,我们需要理解更多的内容. 首先,我们需要了解JS的浅拷贝与深拷贝 ...
- SpringBoot Actuator & SpringBoot Admin
SpringBoot Actuator提供了很多监控和管理你的spring boot应用的HTTP或者JMX端点,并且你可以有选择地开启和关闭部分功能. 当你的spring boot应用中引入依赖之后 ...
- 虚拟化技术:Xen与KVM的对比
作为开源的虚拟化技术,对比Xen和KVM可以看到,Xen以6个无与伦比的优势领先:更好的可用资源.平台支持.可管理性.实施.动态迁移和性能基准. 可用资源:Xen的问世要比KVM早4年之久(两者分别是 ...
- spring之IOC容器创建对象
1.术语了解 1.1组件/框架设计 侵入式设计 引入了框架,对现有的类的结构有影响:即需要实现或继承某些特定类. 例如: Struts框架非侵入式设计 引入了框架,对现有的类结构没有影响. 例如:Hi ...
- [C++] Memory Retrieval(内存检索)
Traverse the memory by (char*) , because every time it will increase by 1byte when i want get the i ...
- Spring获取HttpServletRequest对象
<!-- WEB.XML中配置相关的监听机制 --> <listener> <listener-class> org.springframework.web ...
- ubuntu 16.04安装ceph集群(双节点)
Ceph是一个分布式存储,可以提供对象存储.块存储和文件存储,其中对象存储和块存储可以很好地和各大云平台集成.一个Ceph集群中有Monitor节点.MDS节点(可选,用于文件存储).至少两个OSD守 ...
- Dubbo的配置及启动
Tomcat+Dubbo安装 1.将tomcat的webapps目录下的所有文件清空,讲Dubbo管理控制台的程序dubbo-admin-2.5.3.war放 到webapps中,并且解压命名为ROO ...
- linux 不在sudoers文件中、普通用户获得sudo权限
现在要让jack用户获得sudo使用权 切换到超级用户root $su root 查看/etc/sudoers权限,可以看到当前权限为440 $ ls -all /etc/sudoers -r--r- ...
- a 标签 name 属性 页面定位 (一)
a(§b) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ...