zoukankan      html  css  js  c++  java
  • Codeforces 960F

    960F - Pathwalks

    思路:

    ORZ 杜老师

    用map写1e5个树状数组,骚操作

    记Q为query和update次数,则节点个数约为Q*log(N)

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    #define LL long long 
    #define pb push_back
    #define mem(a, b) memset(a, b, sizeof(a))
    
    const int N = 1e5 + 5;
    map<int, int> bits[N];
    int query(int u, int x){
        int ans = 0;
        while (x) {
            ans = max(ans, bits[u][x]);
            x -= x&-x;
        }
        return ans;
    }
    void update(int u, int x, int v) {
        while(x < N){
            bits[u][x] = max(bits[u][x], v);
            x += x&-x;
        }
    }
    int main() {
        int n, m, u, v, w;
        scanf("%d%d", &n, &m);
        for (int i = 0; i < m; i++) {
            scanf("%d%d%d", &u, &v, &w);
            w++; 
            update(v, w, query(u, w - 1) + 1);
        }
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            ans = max(ans, query(i, 100001));
        }
        printf("%d
    ", ans);
        return 0;
    }
  • 相关阅读:
    test
    4css
    3css
    2css
    5html
    1css
    4html
    3html
    2html
    1.3 tensorflow2.0 常用函数
  • 原文地址:https://www.cnblogs.com/widsom/p/8747880.html
Copyright © 2011-2022 走看看