20190813 analog test (lower) +14

Two examinations twice Cry

Although the first operation SB T2 is lost 20 minutes, but barely from 17 to 15 minutes dry hair stuck first line room

When I just relax, the coach came the news: after the next test sub-room

WTF? ! ? ! ? Well continue to test

T130min cut off (due to the violence and will not fight no beat), T250pts violent kick, and after 30min think there are positive solutions to no avail 1h, they moved to T3

T3 significant digit DP, however, since the error status is defined not out of tune, and finally thrown up with force called 3min

T3 then burst zero, and because I have defined a variable charge cycle of death and then it

When I finished watching rank19 see the rankings, just finished feel to play, the result of an overall list, or rank15? !

Then I Gou in the first room

How should I say, this time the exam is always out of shape, even though the latter has been adjusted, however mistakes can not restore the previous

keep working hard

0813:

T1: Week

Explosive search, do not explain

T2: any

emmm ..... This question my ideas and others are not the same, say something about

Suppose we are to count the contribution line by line, on the line contribution is x, the contribution of this line is how much

We turn first out prefix number and the sum of each row of blocks, and each row and link_x prefixes and the number of edges connected on line

Then obviously our contribution to this line of sum-link_x, this thing can be two-dimensional prefix and maintenance, can be O (1) query

However, this will be problems, because we left edge and the prefix may be wrong

We can deal with the prefix and link_y each column and connected to the left to solve this problem

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mx[4]={1,-1,0,0},my[4]={0,0,1,-1};
int n,m,q,ans,now,xxx,yyy,xx,yy,sol[2002][2002],slm[2002][2002],sim[2002][2002];
char s[2010][2010];
int main(){
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=n;i++)
        scanf("%s",s[i]+1);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            sol[i][j]=sol[i][j-1]+sol[i-1][j]-sol[i-1][j-1];
            if(s[i][j-1]!='1'&&s[i][j]=='1') sol[i][j]++;
            slm[i][j]=slm[i][j-1]+slm[i-1][j]-slm[i-1][j-1];
            if(s[i][j]=='1'&&s[i-1][j]=='1') slm[i][j]++;
            sim[i][j]=sim[i-1][j];
            if(s[i][j]==s[i][j-1]&&s[i][j]=='1') sim[i][j]++;
        }
    }
    while(scanf("%d%d%d%d",&xxx,&yyy,&xx,&yy)==4){
        ans=sol[xx][yy]-sol[xxx-1][yy]-sol[xx][yyy-1]+sol[xxx-1][yyy-1]+sim[xx][yyy]-sim[xxx-1][yyy];
        if(xx-xxx>=1) ans-=slm[xx][yy]-slm[xxx][yy]-slm[xx][yyy-1]+slm[xxx][yyy-1];
        printf("%d\n",ans);
    }
    return 0;
}
View Code

T3: Fly

首先,我们仔细观察鬼畜值的定义,会惊奇的发现他让求的就是C(x,2),即两两相交的个数

又由于y单调递增,问题进一步转化为求逆序对数

然而这题卡内存,我们需要一些特殊的处理方法

我们发现X是由多段等差数列组成的

考虑等差数列中两项Xi和Xi+1的关联,发现Xi+1的答案就是Xi的答案-之前循环次数

因为之前每个数列必有一个数和Xi构成逆序对而和Xi+1构不成逆序对

对每个数列第一项特殊处理就好了

第一个不完整的数列需要加特判

#include<bits/stdc++.h>
#define ll long long
#define cri const register int
#define re register
using namespace std;
ll c[100010],a;
inline void add(cri x){
    for(int i=x;i<=a;i+=i&-i) c[i]++;
}
inline ll get(cri x){
    ll ans=0;
    for(int i=x;i>=1;i-=i&-i) ans+=c[i];
    return ans;
}
int main(){
    ll n,X,mod,x,lst,ans=0,num=0,i,lans;
    scanf("%lld%lld%lld%lld",&n,&X,&a,&mod);
    if(X<a) add(X+1);
    lst=X;
    x=(X+a)%mod;
    for(i=2;i<=n&&x>=a;i++){
        lst=x;
        x+=a;
        if(x>=mod) x-=mod;
    }
    for(i;i<=n;i++){
        if(x<a) ans+=(lst=i-1-(get(x+1))),num++,add(x+1);
        else ans+=(lst=lst-num+(x<X));
        x+=a;
        if(x>=mod) x-=mod;
    }
    printf("%lld",ans);

}
View Code

未完待续咕了

 

Guess you like

Origin www.cnblogs.com/mikufun-hzoi-cpp/p/11355716.html