题目链接:

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. python入门10 循环语句

    两种循环: 1 for in 2 while #coding:utf-8 #/usr/bin/python """ 2018-11-03 dinghanhua 循环语句 ...

  2. 【mysql案例】mysql5.6.14配置my.cnf多实例,mysql_install_db初始化不读取my.cnf配置文件

    1.1.1. mysql5.6.14多实例my.cnf时,初始化不读取my.cnf配置文件 [环境描写叙述] 在多实例配置的/etc/my.cnf环境中,运行mysql_install_db后.启动M ...

  3. LA 4731 蜂窝网络

    题目链接:https://vjudge.net/problem/UVALive-4731 题意: n 个 数,分成 w 组,求整个区间的数学期望的最小值: 一个区间的数学期望公式给出:一个区间的和 * ...

  4. POJ 1986 Distance Queries 【输入YY && LCA(Tarjan离线)】

    任意门:http://poj.org/problem?id=1986 Distance Queries Time Limit: 2000MS   Memory Limit: 30000K Total ...

  5. (第七场)A Minimum Cost Perfect Matching 【位运算】

    题目链接:https://www.nowcoder.com/acm/contest/145/A A.Minimum Cost Perfect Matching You have a complete ...

  6. phpstorm常用plugins

    CodeGlance JsonOnlineViewer CSS-X-Fire Laravel Plugin PHP annotations

  7. data-ng-disabled指令

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  8. JavaWeb遗漏的知识点

    1. String javax.servlet.ServletContext.getRealPath(String path)方法 官方文档解释:Gets the real path correspo ...

  9. Xshell中使用FTP/SFTP工具下载文件

    (1)sftp host_ip,输入用户名/密码 (2)通过cd命令找到远程服务器要拷贝的文件: 通过lcd命令指定本地保存地址. (3)通过get filename拷贝文件 (4)在本地查看,已经可 ...

  10. 关于alert后,才能继续执行后续代码问题

    如果在正常情况下,代码要在alert之后才执行,解决办法:将要执行的代码用setTimeout延迟执行即可(原因:页面未加载完毕) 首先,先说明问题情况: 如下JS代码,不能正常执行,只有在最前面加上 ...