2018徐州網絡賽H. Ryuji doesn't want to study

題目連接:

https://nanti.jisuanke.com/t/31458html

 

題解:

創建兩個樹狀數組,第一個是,a[1]*n+a[2]*(n-1)....+a[n]*1;第二個是正常的a[1],a[2],a[3]...a[n]c++

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

Now given the features in each frames, the number of features may be different, Morgana wants to find the longest features movement.ide

Input

First line contains one integer T(1 \le T \le 10)T(1T10) , giving the test cases.this

Then the first line of each cases contains one integer nn (number of frames),spa

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

In each test case the sum number of features NN will satisfy N \le 100000N100000 .htm

Output

For each cases, output one line with one integers represents the longest length of features movement.blog

樣例輸入

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
相關文章
相關標籤/搜索