sdut2880---Devour Magic(山东省第五届ACM题)

#include<stdio.h>
#include<string.h>
#include<algorithm>
#define M 300000
#define inf 0x3f3f3f3f
using namespace std;
int maxx,minn;
long long sum;
int r,c,m;
struct T
{
    int left,right,min,max,sum;
    int add,set;
}tree[M];
struct e
{
    int t,l,r;
}ss[111111];

int cmp(e a, e b)
{
    return a.t<b.t;
}

void build(int l,int r,int i)
{
    tree[i].left=l;tree[i].right=r;tree[i].set=-1;
    tree[i].add=tree[i].sum=tree[i].max=tree[i].min=0;
    if(l==r)return;
    int mid=l+(r-l)/2;
    build(l,mid,i<<1);
    build(mid+1,r,i<<1|1);
}

void pushdown(int i)
{
    if(tree[i].left>=tree[i].right)return;
    if(tree[i].set!=-1)
    {
        tree[i<<1].set=tree[i<<1|1].set=tree[i].set;
        tree[i<<1].min=tree[i<<1|1].min=tree[i].set;
        tree[i<<1].max=tree[i<<1|1].max=tree[i].set;
        tree[i<<1].add=tree[i<<1|1].add=0;
        tree[i<<1].sum=(tree[i<<1].right-tree[i<<1].left+1)*tree[i].set;
        tree[i<<1|1].sum=(tree[i<<1|1].right-tree[i<<1|1].left+1)*tree[i].set;
    }
    if(tree[i].add>0)
    {
        int add=tree[i].add;
        tree[i<<1].add+=add;tree[i<<1|1].add+=add;
        tree[i<<1].min+=add;tree[i<<1|1].min+=add;
        tree[i<<1].max+=add;tree[i<<1|1].max+=add;
        tree[i<<1].sum+=add*(tree[i<<1].right-tree[i<<1].left+1);
        tree[i<<1|1].sum+=add*(tree[i<<1|1].right-tree[i<<1|1].left+1);
    }
}

void maintain(int i)
{
    if(tree[i].left>=tree[i].right)return;
    tree[i].max=max(tree[i<<1].max,tree[i<<1|1].max);
    tree[i].min=min(tree[i<<1].min,tree[i<<1|1].min);
    tree[i].sum=tree[i<<1].sum+tree[i<<1|1].sum;
}

void update_add(int l,int r,int val,int i)//区间添加
{
    if(tree[i].left==l&&tree[i].right==r)
    {
        tree[i].add+=val;
        tree[i].max+=val;
        tree[i].min+=val;
        tree[i].sum+=(tree[i].right-tree[i].left+1)*val;
        return;
    }
    pushdown(i);
    tree[i].set=-1;
    tree[i].add=0;
    int mid=tree[i].left+(tree[i].right-tree[i].left)/2;
    if(r<=mid)update_add(l,r,val,i<<1);
    else if(l>mid)update_add(l,r,val,i<<1|1);
    else
    {
        update_add(l,mid,val,i<<1);
        update_add(mid+1,r,val,i<<1|1);
    }
    maintain(i);
}

void update_set(int l,int r,int val,int i)//区间修改
{
   // printf("set\n");
    if(tree[i].left==l&&tree[i].right==r)
    {
        tree[i].set=tree[i].max=tree[i].min=val;
        tree[i].add=0;
        tree[i].sum=(tree[i].right-tree[i].left+1)*val;
        return;
    }
    pushdown(i);
    tree[i].set=-1;
    tree[i].add=0;
    int mid=tree[i].left+(tree[i].right-tree[i].left)/2;
    if(r<=mid)update_set(l,r,val,i<<1);
    else if(l>mid)update_set(l,r,val,i<<1|1);
    else
    {
        update_set(l,mid,val,i<<1);
        update_set(mid+1,r,val,i<<1|1);
    }
    maintain(i);
}

void query(int l,int r,int i)//区间查询
{
    if(tree[i].left==l&&tree[i].right==r)
    {
       sum+=tree[i].sum;
       minn=min(minn,tree[i].min);
       maxx=max(maxx,tree[i].max);
        return;
    }
    pushdown(i);
    tree[i].set=-1;tree[i].add=0;
    int mid=tree[i].left+(tree[i].right-tree[i].left)/2;
    if(r<=mid)query(l,r,i<<1);
    else if(l>mid)query(l,r,i<<1|1);
    else
    {
        query(l,mid,i<<1);
        query(mid+1,r,i<<1|1);
    }
    maintain(i);
}

int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {   long long ssum=0;
        int i,re;
        memset(tree,0,sizeof(tree));
        memset(ss,0,sizeof(ss));
        int op,k=0;

        scanf("%d%d",&re,&op);
        build(1,re,1);
        ss[0].t=0;
        for(i=1;i<=op;i++)
            scanf("%d%d%d",&ss[i].t,&ss[i].l,&ss[i].r);
            sort(ss+1,ss+1+op,cmp);

        for(i=1;i<=op;i++)
        {
            int tr=ss[i].t-ss[i-1].t;
            update_add(1,re,tr,1);

            query(ss[i].l,ss[i].r,1);
            ssum+=sum;
            sum=0;
            update_set(ss[i].l,ss[i].r,0,1);
        }
        printf("%lld\n",ssum);

    }
    return 0;
}

/**************************************
	Problem id	: SDUT OJ 2880
	User name	: rain
	Result		: Wrong Answer
	Take Memory	: 9800K
	Take Time	: 710MS
	Submit Time	: 2015-04-16 17:16:03
**************************************/

re无数然后WA无数就找到一个小错误导致不能AC,add那个地方是所有的都+1,想的很清楚但是就是写错了,蛋疼。

时间: 2024-10-13 06:20:40

sdut2880---Devour Magic(山东省第五届ACM题)的相关文章

angry_birds_again_and_again(2014年山东省第五届ACM大学生程序设计竞赛A题)

http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2877 题目描述 The problems called "Angry Birds" and "Angry Birds Again and Again" has been solved by many teams in the series of contest in 2011 Multi-University Tr

SDUT2880 Devour Magic 线段树(set+add标记)

Devour Magic Time Limit: 2000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 In Warcraft III, Destroyer is a large flying unit that must consume magic to sustain its mana. Breaking free of the obsidian stone that holds them, these monstrous creatures roar

2014年山东省第五届ACM大学生程序设计竞赛解题报告

A  angry_birds_again_and_again http://www.sdutacm.org/sdutoj/problem.php?action=showproblem&problemid=2877 数学题,求抛物线和直线围成的面积,用积分来做. 设方程 y=ax^2+bx+c ,图中曲线经过原点,所以c=0. 对方程求导 y'=2ax+b ,  y'代表斜率,那么原点(0,0)这一点,代人y'=b,即该点的斜率,根据题意b=tan( α) 如图:在题目中x=tx这一点时,容易混,

Devour Magic 线段树

点击打开链接 Devour Magic Time Limit: 2000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 In Warcraft III, Destroyer is a large flying unit that must consume magic to sustain its mana. Breaking free of the obsidian stone that holds them, these monstrous creatur

山东省第五届省赛回顾 Full Binary Tree

Full Binary Tree 题目链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2882 Time Limit: 2000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 In computer science, a binary tree is a tree data structure in which each node has at most tw

2014山东省“浪潮杯”第五届ACM省赛总结

一次比赛做一次总结,弱菜又来总结了-- 我这种大四的又死皮赖来混省赛了,貌似就我和山大威海的某哥们(不详其大名)了吧.颁奖前和他聊天,得知他去百度了,真是不错,ORZ之. 比赛流水账: 题目目前不知道哪有,过几天填坑. 没发题目前,我们赌A题可能是水题,由于我是主coder,我去读A,剩下的一个从前往后,一个从后往前. 结果--,看到A有一个貌似是几何的图--,我还是硬头皮读了.读到一半,3分钟刷榜,发现E有出,让ZK读E,ZK先告诉我了B题题意,转而读E.B题是一个有环形关系的期望,我扫了一下

sdut 2603 Rescue The Princess(算是解析几何吧)(山东省第四届ACM省赛A题)

题目地址:sdut 2603 Rescue The Princess Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Several days ago, a beast caught a beautiful princess and the princess was put in prison. To rescue the princess, a prince who wanted to marry the princess

Sdut 2416 Fruit Ninja II(山东省第三届ACM省赛 J 题)(解析几何)

Time Limit: 5000MS Memory limit: 65536K 题目描写叙述 Haveyou ever played a popular game named "Fruit Ninja"? Fruit Ninja (known as Fruit Ninja HD on the iPad and Fruit Ninja THD for NvidiaTegra 2 based Android devices) is a video game developed by Hal

Sdut2411 Pixel density 山东省第三届ACM省赛(输入输出字符串处理)

本文出处:http://blog.csdn.net/svitter 原题:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2411 题意:给你一个串,让你依据那个串来输出ppi.坑特别多.ppi的计算方法是dp / inches; dp = sqrt(wp*wp + hp * hp); 现在我来说说这个题目有多坑: 给你的串的格式是这样: name + inches+ "inches"