当前位置:网站首页>Cfdiv1+2-pathwalks- (tree array + linear DP)
Cfdiv1+2-pathwalks- (tree array + linear DP)
2022-07-26 21:22:00 【Lovely and beautiful girl】
The question :
Is to give you a n spot m edge , Then let you choose a path , Then the order of the sides you walk , It needs to be in the order of increasing , Then the edge weight should also increase .
reflection :
At first, I felt that such a problem was graph theory torture problem , But I have found so many people , Found that this is a dp. Since the order of the edges to be given , Then it must be enumerating edges in order , Before and after , Definition dp[i] Choose the first i The maximum value of the edge . Then come to the i One side , Or start from this side , Or transfer from the front side , Transfer from the edge whose end point is the starting point of this edge , At the same time, ensure the weight of that side < Current weight . If violence starts from vector Look inside , This is a m*m Complexity . So every query needs log(m), And the weight is smaller than the current , Find a maximum . Then maintain the tree array , But what I found was that , In this way, we should establish n A tree , This space is too complicated . But I think it can be used map Build up trees , Then the actual space will not be so large , Because every time +bit(x), Not many points are actually occupied . Actually, I thought map Build up trees , It's still the time when we used to do and search collections , Need to maintain a large point , You can use it map When acc Array is ok .
Code :
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define db double
#define int long long
#define PII pair<int,int >
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const int mod = 1e9+7,inf = 1e18;
const int N = 2e5+10,M = 2010;
int T,n,m,k;
PII va[N];
int vb[N];
int dp[N];
int R = 1e5+5;
map<int,int > tr[N];
int bit(int x)
{
return x&(-x);
}
void update(int x,int value,int op)
{
while(x<=R)
{
tr[op][x] = max(tr[op][x],value);
x += bit(x);
}
}
int query(int x,int op)
{
int maxn = 0;
while(x)
{
maxn = max(maxn,tr[op][x]);
x -= bit(x);
}
return maxn;
}
signed main()
{
IOS;
cin>>n>>m;
for(int i=1;i<=m;i++)
{
cin>>va[i].fi>>va[i].se>>vb[i];
vb[i] += 1; // It is only related to the size of the weight ,+1 To prevent the following query( negative ) and update(0)
}
for(int i=1;i<=m;i++)
{
int a = va[i].fi,b = va[i].se,c = vb[i];
dp[i] = max(1ll,query(c-1,a)+1);
update(c,dp[i],b);
}
int maxn = 1;
for(int i=1;i<=m;i++) maxn = max(maxn,dp[i]);
cout<<maxn;
return 0;
}
summary :
Think more , Try more .
边栏推荐
- What is the function of the serializable interface?
- [HCIA security] user authentication
- Niuke brush questions - MySQL series
- CFdiv1+2-Pathwalks-(树状数组+线性dp)
- Leetcode linked list problem - 19. Delete the penultimate node of the linked list (learn the linked list with one question and one article)
- [MySQL series] - how much do you know about the index
- LeetCode_ Backtracking_ Medium_ 40. Combined sum II
- After chatting with byte programmers with a monthly salary of 3W, I realized that I had been doing chores
- Why didn't Tencent create a game like "original God"
- [problem] process the set [','] into (',')
猜你喜欢

和月薪3W的字节程序员聊过后,才知道自己一直在打杂...

腾讯为什么没能造创造出《原神》这样的游戏

Apaas low code platform (I) | leave complexity to yourself and simplicity to users
![[OBS] solve the problem of OBS pushing two RTMP streams + timestamp](/img/71/dbd00f69251b96b0e56de399103f72.png)
[OBS] solve the problem of OBS pushing two RTMP streams + timestamp

QT基础第一天 (1)QT,GUI(图形用户接口)开发

Explain the 190 secondary compiler (decoding table) module of SMR laminated hard disk of Western data in detail

flask 源码梗概

Increased uncertainty in BTC and eth due to the approaching interest rate hike? The US economy will face more pain

How to implement Devops with automation tools | including low code and Devops application practice

How to enter the specified user method body when debugging in idea?
随机推荐
Flutter性能优化实践 —— UI篇
Mobile phone \ landline call forwarding setting method
Interceptors
【HCIE安全】双机热备-主备备份
除了「加机器」,其实你的微服务还能这样优化
牛客刷题——Mysql系列
Pointpillars: fast encoders for object detection from point clouds reading notes
Introduction of JDBC
有关无线通信的相关内容
How to implement Devops with automation tools | including low code and Devops application practice
ECCV 2022 | 同时完成四项跟踪任务!Unicorn: 迈向目标跟踪的大统一
Set the template of core configuration file in idea
[Oracle training] - deploy Ogg known as zero downtime migration
苹果官网罕见打折,iPhone13全系优惠600元;国际象棋机器人弄伤对弈儿童手指;国内Go语言爱好者发起新编程语言|极客头条
Leetcode linked list problem - 19. Delete the penultimate node of the linked list (learn the linked list with one question and one article)
Line detection based on Hough transform (matlab)
和月薪3W的字节程序员聊过后,才知道自己一直在打杂...
Green and sustainable development of data center
[question] browser get request with token
SPI configuration