2018ccpc网络赛1010 J - YJJ's Salesman

 又是一道没a的题。。。

YJJ is a salesman who has traveled through western country. YJJ is always on journey. Either is he at the destination, or on the way to destination. 
One day, he is going to travel from city A to southeastern city B. Let us assume that A is (0,0)(0,0) on the rectangle map and B (109,109)(109,109). YJJ is so busy so he never turn back or go twice the same way, he will only move to east, south or southeast, which means, if YJJ is at (x,y)(x,y) now (0≤x≤109,0≤y≤109)(0≤x≤109,0≤y≤109), he will only forward to (x+1,y)(x+1,y), (x,y+1)(x,y+1) or (x+1,y+1)(x+1,y+1). 
On the rectangle map from (0,0)(0,0) to (109,109)(109,109), there are several villages scattering on the map. Villagers will do business deals with salesmen from northwestern, but not northern or western. In mathematical language, this means when there is a village kk on (xk,yk)(xk,yk) (1≤xk≤109,1≤yk≤109)(1≤xk≤109,1≤yk≤109), only the one who was from (xk−1,yk−1)(xk−1,yk−1) to (xk,yk)(xk,yk) will be able to earn vkvk dollars.(YJJ may get different number of dollars from different village.) 
YJJ has no time to plan the path, can you help him to find maximum of dollars YJJ can get.

The first line of the input contains an integer TT (1≤T≤10)(1≤T≤10),which is the number of test cases. 

In each case, the first line of the input contains an integer NN (1≤N≤105)(1≤N≤105).The following NN lines, the kk-th line contains 3 integers, xk,yk,vkxk,yk,vk (0≤vk≤103)(0≤vk≤103), which indicate that there is a village on (xk,yk)(xk,yk) and he can get vkvk dollars in that village. 
The positions of each village is distinct.
 

题意很明显,简单题。。。结果还是没过,,自己真是个辣鸡

然后看数据写代码吧。。 代码1000+ms

1e9 离散化 然后x相等时 y从大到小更新就行了

1e5  nlogn  线段树或者树状数组   朴素的n2肯定t了。。

一直写线段树,,一直tle。。忘记了树状数组这货。。

还是树状数组的常数小呀。。

 

#include
#include
#include
#include
#include
#include
#include
#include
#include
#define lowbit(x) (x&(-x))
int read() {
    int x = 0;
    char c = getchar();
    while (c < '0' || c > '9')c = getchar();
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x;
}
int cnt; 

struct node{
	int x,y;
	int value;
};
using namespace std;
int dp[400005];
int y[100005];
node data[100005];

int n;
bool cmp(node a,node b)
{
	if(a.x0;i-=lowbit(i)){res=max(res,dp[i]);}
    return res;
}

int main(){
	int T;
	T=read();
	while(T--){
		n=read();
		memset(dp,0,sizeof(dp));
		for(int i=0;i=j;z--)
			{
				dp[data[z].y]=max(query(data[z].y-1)+data[z].value,dp[data[z].y]);
				updata(data[z].y,dp[data[z].y]);
				m=max(m,dp[data[z].y]);
			}	
		}
		printf("%d\n",m);
	}	
}

 

你可能感兴趣的:(学习acm)