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],a[2],a[3]...a[n]
#include "bits/stdc++.h"
using namespace std;
#define ll long long
const int MAXN=1e5+10;
ll sum[MAXN],ans[MAXN];
ll num[MAXN];
ll n,q;
int lowbit(int x)
{
return x&(-x);
}
void update(int i , ll x)
{
ll t=x*(n-i+1);
while(i<=n)
{
sum[i]+=x;
ans[i]+=t;
i+=lowbit(i);
}
}
ll query1(int x)
{
ll Sum=0;
while(x)
{
Sum+=sum[x];
x-=lowbit(x);
}
return Sum;
}
ll query2(int x)
{
ll Sum=0;
while(x)
{
Sum+=ans[x];
x-=lowbit(x);
}
return Sum;
}
int main()
{
while(scanf("%lld%lld",&n,&q)!=EOF)
{ for(int i=1;i<=n;i++)
{
scanf("%lld",&num[i]);
update(i,num[i]);
}
while(q--)
{
int a,b,c;
scanf("%d",&a);
if(a==1)
{
scanf("%d%d",&b,&c);
ll A1=query1(c)-query1(b-1);
ll A2=query2(c)-query2(b-1);
printf("%lld\n",A2-A1*((n-b+1)-(c-b+1)));
} else
{
scanf("%d%d",&b,&c);
ll k=c-num[b];
num[b]=c;
update(b,k);
}
}
}
return 0;
}
- 262144K
Morgana is learning computer vision, and he likes cats, too. One day he wants to find the cat movement from a cat video. To do this, he extracts cat features in each frame. A cat feature is a two-dimension vector <xx, yy>. If x_ixi= x_jxj and y_iyi = y_jyj, then <x_ixi, y_iyi> <x_jxj, y_jyj> are same features.
So if cat features are moving, we can think the cat is moving. If feature <aa, bb> is appeared in continuous frames, it will form features movement. For example, feature <aa , bb > is appeared in frame 2,3,4,7,82,3,4,7,8, then it forms two features movement 2-3-42−3−4 and 7-87−8 .
Now given the features in each frames, the number of features may be different, Morgana wants to find the longest features movement.
Input
First line contains one integer T(1 \le T \le 10)T(1≤T≤10) , giving the test cases.
Then the first line of each cases contains one integer nn (number of frames),
In The next nn lines, each line contains one integer k_iki ( the number of features) and 2k_i2ki intergers describe k_ikifeatures in ith frame.(The first two integers describe the first feature, the 33rd and 44th integer describe the second feature, and so on).
In each test case the sum number of features NN will satisfy N \le 100000N≤100000 .
Output
For each cases, output one line with one integers represents the longest length of features movement.
样例输入复制
1
8
2 1 1 2 2
2 1 1 1 4
2 1 1 2 2
2 2 2 1 4
0
0
1 1 1
1 1 1
样例输出复制
3
2018徐州网络赛H. Ryuji doesn't want to study的更多相关文章
- 2018icpc徐州网络赛-H Ryuji doesn't want to study(线段树)
题意: 有n个数的一个数组a,有两个操作: 1 l r:查询区间[l,r]内$a[l]*(r-l+1)+a[l+1]*(r-l)+a[l+2]*(r-l-1)+\cdots+a[r-1]*2+a[r] ...
- ACM-ICPC 2018徐州网络赛-H题 Ryuji doesn't want to study
死于update的一个long long写成int了 真的不想写过程了 ******** 树状数组,一个平的一个斜着的,怎么斜都行 题库链接:https://nanti.jisuanke.com/t/ ...
- ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study
262144K Ryuji is not a good student, and he doesn't want to study. But there are n books he should ...
- ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study (线段树)
Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, ea ...
- ACM-ICPC 2018 徐州赛区网络预赛 H Ryuji doesn't want to study (树状数组差分)
https://nanti.jisuanke.com/t/31460 题意 两个操作.1:查询区间[l,r]的和,设长度为L=r-l+1, sum=a[l]*L+a[l+1]*(L-1)+...+a[ ...
- ACM-ICPC 2018 徐州赛区网络预赛H Ryuji doesn't want to study(树状数组)题解
题意:给你数组a,有两个操作 1 l r,计算l到r的答案:a[l]×L+a[l+1]×(L−1)+⋯+a[r−1]×2+a[r] (L is the length of [ l, r ] that ...
- ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study(树状数组)
Output For each question, output one line with one integer represent the answer. 样例输入 5 3 1 2 3 4 5 ...
- 2018徐州网络赛 - Trace
题意:n个左下角为原点右上角在第一象限的矩形不断覆盖,求最后形成的图形的周长 x和y是独立的,分别维护两棵线段树,一棵表示x坐标下最大的y值,另一棵表示y坐标下最大的x值 从覆盖的角度来考虑,如果逆序 ...
- ACM-ICPC 2018青岛网络赛-H题 Traveling on the Axis
题目:略(不知道怎么从ZOJ搬题) 地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4054 把这题的每个点分成两种情况 ...
随机推荐
- RAC共享磁盘挂载工具
待更新: oracleasm: udev: 自己搭建个存储服务器:
- LeetCodeOJ刷题之12【Integer to Roman】
Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be within t ...
- BZOJ1951:[SDOI2010]古代猪文(Lucas,CRT)
Description “在那山的那边海的那边有一群小肥猪.他们活泼又聪明,他们调皮又灵敏.他们自由自在生活在那绿色的大草坪,他们善良勇敢相互都关心……” ——选自猪王国民歌 很久很久以前,在山的那边 ...
- 【转】onConfigurationChanged
http://blog.csdn.net/xiaodongvtion/article/details/679938 转载自该文章. 注意:onConfigurationChanged事件并不是只有屏幕 ...
- webapi2返回 已拒绝为此请求授权。
开始用的webapi2中是没有问题的,后来再项目中加了个过滤器并继承了AuthorizeAttribute 然后在全球文件中注册你的过滤器,让每次执行的时候都会进来 我项目中只重写了OnAuthori ...
- img的空白内容如何处理
给img加一个 vertical-align: bottom;
- 如何配置Java环境变量
百度经验 | 百度知道 | 百度首页 | 登录 | 注册 新闻 网页 贴吧 知道 经验 音乐 图片 视频 地图 百科 文库 帮助 发布经验 首页 分类 任务 回享 商城 特色 知道 百度经验 &g ...
- SecureCRT 个人使用爱好配置。
1.设置默认启动会话设置. 2.设置执行 ls命令显示文件夹,各种文件,不同的对比颜色 2.1 设置前: 2.2 设置后: 3. 如果出现会话框中文乱码 ,设置以下选项 4 . 更改 命令 ls -a ...
- 【TOJ 3005】Triangle(判断点是否在三角形内+卡精度)
描述 Given the coordinates of the vertices of a triangle,And a point. You just need to judge whether t ...
- vs2017中的scanf_s
在visual studio 2017中格式化输入函数不同于其他c/c++编译器使用scanf,而是使用scanf_s. scanf_s相比较于scanf来说更安全,因为使用scanf_s函数需要有一 ...