2019.10.11考试报告

时间安排:

T1:1.5h

T2:1h

T3:0.5h

考场思路:

T1:一开始的时候想用线段树做,然后线段树写炸了,在一个单点修改上出现了问题,改用暴力做,时间复杂度O(n*q),,得了四十分

T2:一开始想用Floyd做,发现数据范围太大了,改成用拓扑排序来做

T3:本来想拿个十分的部分分,发现十分的部分分也不会写

答题情况:

T1:50

T2:64

T3:0

题目分析:

T1:题目上写的线段树,可实际上和线段树一点关系也没有,就是用一个数组储存操作3的次数,然后在每次进行操作1、2的时候,先进行一次判断,如果小于操作的次数,那就先把这个数改成最近的一次操作3的值后再进行处理,如果等于,那么就说明已经处理过,就直接处理就好了,时间复杂度:O(q)

T2:拓扑排序,数据范围太大,fFloyd,dij,spfa都会超时,所以我们就要想另外的方法,根据题目的要求,求一个最长路,那么该图一定是一个有向无环图,(如果有环,那么最长路就是+∞了)。有向无环图又叫拓扑图,可用拓扑排序+DP做。然后就打一个拓扑排序+DP就好了

T3:一条链的情况:当为一条链时,最大值一定是两个端点之一,最小值一定在某一个点上。期望得分:10分

 

 

正解:

T1:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<ctype.h>
#define int long long int 

using namespace std;

const int MAXSIZE=50000020; //读入缓存大小,不要改动 
int bufpos;
char buf[MAXSIZE];
int read(){ //读入一个int类型的整数 
    int val = 0;
    for(; buf[bufpos] < '0' || buf[bufpos] > '9'; bufpos ++);
    for(; buf[bufpos] >= '0' && buf[bufpos] <= '9'; bufpos ++)
        val = val * 10 + buf[bufpos] - '0';
    return val;
}

int a[10000010];
int b[10000010];
int ans;
int tag,lazy;

signed main()
{
    freopen("segmenttree.in","r",stdin);
    freopen("segmenttree.out","w",stdout);
    buf[fread(buf, 1, MAXSIZE, stdin)] = '\0';
    bufpos = 0;
    int n,m;
    n=read();
    m=read();
    for(int i=1;i<=m;i++)
    {
        int t;
        t=read();
        if(t==1)
        {
            int x,y;
            x=read();
            y=read();
            if(b[x]<tag)
            {
                a[x]=lazy;
                b[x]=tag;
            }
            ans-=a[x];
            a[x]=y;
            ans+=y;
        }
        if(t==2)
        {
            int x,y;
            x=read();
            y=read();
            if(b[x]<tag)
            {
                a[x]=lazy;
                b[x]=tag;
            }
            a[x]+=y;
            ans+=y;
        }
        if(t==3)
        {
            int y;
            y=read();
            tag++;
            lazy=y;
            ans=n*y;
        }
        cout<<ans<<endl;
    }
    return 0;
}
View Code

相关文章: