CSP 记

csp

开考建好文件夹编译器不能用搞了半天换了台电脑
四道题看完一个小时过去了
第一题不会正解写了部分分还有点悬
第二题写暴力因为一个小错误调了半天
看时间不多了已经有点慌了
也没想正解直接开了下一题
从T3 T4选了T4写了部分分还写挂了
没有稳定好心态
和平常考试的感觉差了很多

T2

[CSP-S 2022] 假期计划
考场上没想正解用ST表写了个暴力痛失40分
正解:
根据\(A,B\)正负性分情况讨论
线段树维护信息

std:

#include<bits/stdc++.h>
#define ls p<<1
#define rs p<<1|1
#define lson ls,l,mid
#define rson rs,mid+1,r
#define root 1,1,tot
using namespace std;

const int N = 1e5+9;
int n,m,q,A[N],B[N],tot;

struct tree
{
    int l,r,AMX,AMI,Ami,Amx,BMX,BMI;
    bool A0;
    tree()
    {
        l = r = 0;
        return;
    }
}t[N<<2];

tree operator +(const tree &l,const tree &r)
{
    tree p;
    p.l = l.l,p.r = r.r;
    p.AMX = max(l.AMX,r.AMX),p.AMI = min(l.AMI,r.AMI);
    p.BMX = max(l.BMX,r.BMX),p.BMI = min(l.BMI,r.BMI);
    p.Amx = max(l.Amx,r.Amx),p.Ami = min(l.Ami,r.Ami);
    p.A0 = l.A0|r.A0;
    return p;
}

void pushup(int p)
{
    t[p] = t[ls] + t[rs];
    return;
}

void build(int p,int l,int r)
{
    if(l == r)
    {
        t[p].l = t[p].r = l;

        t[p].AMX = t[p].AMI = A[l];
        
        t[p].BMX = t[p].BMI = B[l];

        if(A[l] >= 0)t[p].Ami = A[l],t[p].Amx = INT_MIN;
        else t[p].Ami = INT_MAX,t[p].Amx = A[l];
        if(A[l] == 0)t[p].A0 = 1;

        return;
    }

    int mid = l+r>>1;
    build(lson);
    build(rson);
    pushup(p);
    return;
}

tree query(int p,int l,int r,int L,int R)
{
    if(L <= l && R >= r)return t[p];

    int mid = l+r>>1;
    if(R <= mid)return query(lson,L,R);
    else if(L > mid)return query(rson,L,R);
    else return query(lson,L,R) + query(rson,L,R); 
}

int main()
{

    scanf("%d%d%d",&n,&m,&q);
    tot = max(n,m);
    for(int i = 1;i <= n;i++)scanf("%d",A+i);
    for(int i = 1;i <= m;i++)scanf("%d",B+i);
    build(root);

    while(q--)
    {
        int l1,r1,l2,r2;
        scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
        tree a = query(root,l1,r1);
        tree b = query(root,l2,r2);
        
        if(b.BMI >= 0)
        {
            if(a.AMX < 0)printf("%lld\n",1ll*a.AMX*b.BMX);
            else printf("%lld\n",1ll*a.AMX*b.BMI);
        }
        else if (b.BMX < 0)
        {
            if(a.AMI >= 0)printf("%lld\n",1ll*a.AMI*b.BMI);
            else printf("%lld\n",1ll*a.AMI*b.BMX);
        }
        else 
        {
            if(a.AMX < 0)printf("%lld\n",1ll*a.AMX*b.BMX);
            else if(a.AMI >= 0)printf("%lld\n",1ll*a.AMI*b.BMI);
            else if(a.A0)printf("0\n");
            else printf("%lld\n",max(1ll*a.Ami*b.BMI,1ll*a.Amx*b.BMX));
        }

    }

    return 0;
}
posted @ 2022-10-30 11:13  AC7  阅读(36)  评论(0)    收藏  举报