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 <xxyy>. If x_ixix_jxj and y_iyi = y_jyj, then <x_ixiy_iyi> <x_jxjy_jyj> are same features.

So if cat features are moving, we can think the cat is moving. If feature <aabb> 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-4234 and 7-878 .

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(1T10) , 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 100000N100000 .

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

猜你喜欢

转载自www.cnblogs.com/-xiangyang/p/9621967.html