反思8.22

时间:2019-08-22
本文章向大家介绍反思8.22,主要包括反思8.22使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

第一题傻了$80$分错了

第二题我打了个什么玩意

凭空多一个$log$常数还极大

还打了个特别蠢的二分

void pre(ll l,ll r,ll now,ll nowmax){
    if(l>r) return ;
    if(l==r) {
        sum[nowmax]++;
//        printf("l=%lld nowmax=%lld \n",l,nowmax);
        return ;
    }
//    printf("l=%lld r=%lld nowmax=%lld r-l=%lld\n",l,r,nowmax,r-l+1);
    sum[nowmax]+=r-l+1+(r-now)*(now-l);
    maxn=0,ida=0;
    if(l<=now-1)
    {    
        seg_max(1,l,now-1);
        pre(l,now-1,ida,maxn);
    }
    maxn=0,ida=0;
    if(now+1<=r)
    {
        seg_max(1,now+1,r);
        pre(now+1,r,ida,maxn);
    }
}

连单调队列都没想到

代码还极长

数据结构学傻了

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define A 2222222
ll n,q,mx,mn=0x7fffffffff,ida,maxn,idb;
ll a[A],sum[A*100];
char c[10];
struct node{
    ll id,val;
    friend bool operator < (const node &a,const node &b){
        return a.val<b.val;
    }
};
struct tree{
    ll l,r,val,id;
}tr[A<<1];
void pushup(ll p){
    if(tr[p<<1].val>tr[p<<1|1].val){
        tr[p].val=tr[p<<1].val;
        tr[p].id=tr[p<<1].id;
    }
    else {
        tr[p].val=tr[p<<1|1].val;
        tr[p].id=tr[p<<1|1].id;
    }
}
void built(ll p,ll l,ll r){
    tr[p].l=l,tr[p].r=r;
    if(l==r){
        tr[p].val=a[l];
        tr[p].id=l;
        return ;
    }
    ll mid=(l+r)>>1;
    built(p<<1,l,mid);
    built(p<<1|1,mid+1,r);
    pushup(p);
}
void seg_max(ll p,ll l,ll r){
//    printf("p=%lld l=%lld r=%lld l=%lld r=%lld\n",p,l,r,tr[p].l,tr[p].r);
    if(tr[p].l>=l&&tr[p].r<=r){
        if(tr[p].val>maxn){
            maxn=tr[p].val;
            ida=tr[p].id;
        }
        return ;
    }
    ll mid=(tr[p].l+tr[p].r)>>1;
    if(mid>=l)
        seg_max(p<<1,l,r);
    if(mid<r)
        seg_max(p<<1|1,l,r);
}
void pre(ll l,ll r,ll now,ll nowmax){
    if(l>r) return ;
    if(l==r) {
        sum[nowmax]++;
//        printf("l=%lld nowmax=%lld \n",l,nowmax);
        return ;
    }
//    printf("l=%lld r=%lld nowmax=%lld r-l=%lld\n",l,r,nowmax,r-l+1);
    sum[nowmax]+=r-l+1+(r-now)*(now-l);
    maxn=0,ida=0;
    if(l<=now-1)
    {    
        seg_max(1,l,now-1);
        pre(l,now-1,ida,maxn);
    }
    maxn=0,ida=0;
    if(now+1<=r)
    {
        seg_max(1,now+1,r);
        pre(now+1,r,ida,maxn);
    }
}
int main(){
    scanf("%lld%lld",&n,&q);
    for(ll i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        if(a[i]>mx){
            ida=i;
            mx=a[i];
        }
        mn=min(mn,a[i]);
    }
    built(1,1,n);
    pre(1,n,ida,mx);
    for(ll i=mn;i<=mx;i++){
        sum[i]+=sum[i-1];
    }
    for(ll i=1,que;i<=q;i++){
        scanf("%s",c+1);
        scanf("%lld",&que);
        if(c[1]=='<'){
            if(que>mx){
                printf("%lld\n",sum[mx]);
                continue ;
            }
            if(que<mn){
                printf("0\n");
                continue ;
            }
            printf("%lld\n",sum[que-1]);
        }
        else if(c[1]=='='){
            if(que>mx||que<mn){
                printf("0\n");
                continue ;
            }
            printf("%lld\n",sum[que]-sum[que-1]);
        }
        else if(c[1]=='>'){
            if(que>mx){
                printf("0\n");
                continue ;
            }
            if(que<mn){
                printf("%lld\n",sum[mx]);
                continue ;
            }
            printf("%lld\n",sum[mx]-sum[que]);
        }
    }
}
View Code

$t3$暴力调了一年!!!!!!!!!!

原文地址:https://www.cnblogs.com/znsbc-13/p/11393197.html