题目链接:

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_iki​features 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的更多相关文章

  1. 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] ...

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

    死于update的一个long long写成int了 真的不想写过程了 ******** 树状数组,一个平的一个斜着的,怎么斜都行 题库链接:https://nanti.jisuanke.com/t/ ...

  3. 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 ...

  4. 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 ...

  5. 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[ ...

  6. 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 ...

  7. 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 ...

  8. 2018徐州网络赛 - Trace

    题意:n个左下角为原点右上角在第一象限的矩形不断覆盖,求最后形成的图形的周长 x和y是独立的,分别维护两棵线段树,一棵表示x坐标下最大的y值,另一棵表示y坐标下最大的x值 从覆盖的角度来考虑,如果逆序 ...

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

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

随机推荐

  1. npm run dev运行Vue项目报错:Node Sass does not yet support your current environment

    导入Vue项目后,#npm run dev 报错: error in ./src/pages/hello.vue Module build failed: Error: Node Sass does ...

  2. 再学UML-UML用例建模解析(一)

    UML(统一建模语言)是当前软件开发中使用最为广泛的建模技术之一,通过使用UML可以构造软件系统的需求模型(用例模型).静态模型.动态模型和架构模型.UML通过图形和文字符号来描述一个系统,它是绘制软 ...

  3. oracle_procedure

    define: 存储过程(Stored Procedure )是一组为了完成特定功能的SQL 语句 集,经编译后存储在数据库中.用户通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来执行它. ...

  4. linux虚拟机最优测试环境搭建

    目标:创建一个最优的linux虚拟机环境 环境:vmware12.0 系统:centos6.5 (* 以下配置是建立在配置完成基础网络环境后创建的,用static静态IP地址) 1.关闭selinux ...

  5. 【转载】#440 - A Class Can Implement More than One Interface

    It's possible for a class to implement more than one interface. For example, a Cow class might imple ...

  6. 【洛谷P2184】贪婪大陆

    贪婪大陆 题目链接 对于一个区间[l,r],右端点在l左边即[1,l-1]中的区间与区间[l,r]没有交集, 左端点在r右边即[r,n]中的区间与区间[l,r]没有交集, 其余区间必与[l,r]有交集 ...

  7. 【luogu P3369 【模板】普通平衡树(Treap/SBT)】 模板 Scapegoat Tree

    #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> ...

  8. 【luogu P2319 [HNOI2006]超级英雄】 题解

    题目链接:https://www.luogu.org/problemnew/show/P2319 #include <cstdio> #include <cstring> #i ...

  9. HTML5 小实例

    1.时钟: <!doctype html> <html> <head></head> <body> <canvas id=" ...

  10. 数据流管理:redux

    redux和react是两个独立的库,所以redux并不是非用不可,是在Flux框架的基础上改进的一个框架,所以一鸣惊人 redux的三大基本原则 唯一的数据源(single source of tr ...