제출 #683249

#제출 시각아이디문제언어결과실행 시간메모리
683249NursikBridges (APIO19_bridges)C++14
0 / 100
397 ms28568 KiB
#include <stdio.h>
 
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
 
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ld long double
#define bug cout << "bug\n";

const ll maxn = 1e6 + 1, maxm = 2e2 + 1;
const ll mod = 1e9 + 7, inf = 1e9, block = 550, hb = 126067, base = 1000050017,
         biginf = 5e18;
const ld eps = 1e-15;
using namespace std;

int subtask1 = 1, subtask2 = 1;
int n, m, q;
int u[maxn], v[maxn], d[maxn], used[maxn], t[maxn * 4];
vector<pair<int, int>> g[maxn];
void upd(int pos, int val, int v = 1, int tl = 1, int tr = n - 1){
    if (tl == tr){
        t[v] = val;
        return;
    }
    int tm = (tl + tr) / 2;
    if (pos <= tm)
        upd(pos, val, v + v, tl, tm);
    else
        upd(pos, val, v + v + 1, tm + 1, tr);
    t[v] = min(t[v + v], t[v + v + 1]);
}
int get(int l, int r, int v = 1, int tl = 1, int tr = n - 1){
    if (l <= tl && tr <= r)
        return t[v];
    if (l > tr || r < tl)
        return inf;
    int tm = (tl + tr) / 2;
    return min(get(l, r, v + v, tl, tm), get(l, r, v + v + 1, tm + 1, tr));
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> m;
    subtask2 &= (m == n - 1);
    for (int i = 1; i <= m; ++i){
        cin >> u[i] >> v[i] >> d[i];
        g[u[i]].pb(mp(v[i], i));
        g[v[i]].pb(mp(u[i], i));
        subtask2 &= (u[i] == i && v[i] == i + 1);
        upd(i, d[i]);
    }
    cin >> q;
    subtask1 &= (n <= 1000 && m <= 1000 && q <= 10000);
    if (subtask1){
    for (int i = 1; i <= q; ++i){
        int type;
        cin >> type;
        if (type == 1){
            int x, y;
            cin >> x >> y;
            d[x] = y;
        }
        else{
            int x, y;
            cin >> x >> y;
            for (int j = 1; j <= n; ++j){
                used[j] = 0;
            }
            queue<int> q;
            q.push(x);
            used[x] = 1;
            while (q.size() > 0){
                int v = q.front();
                q.pop();
                for (auto to : g[v]){
                    pair<int, int> nx = to;
                    if (d[nx.s] >= y && used[nx.f] == 0){
                        used[nx.f] = 1;
                        q.push(nx.f);
                    }
                }
            }
            int ans = 0;
            for (int j = 1; j <= n; ++j){
                ans += used[j];
            }
            cout << ans << '\n';
        }
    }
    }
    if (subtask2){
        for (int i = 1; i <= q; ++i){
            int type;
            cin >> type;
            if (type == 1){
                int x, y;
                cin >> x >> y;
                upd(x, y);
            }
            else{
                int x, y;
                cin >> x >> y;
                int kol = 1;
                int l = 1, r = x - 1, ans = -1;
                while (l <= r){
                    int mid = (l + r) / 2;
                    if (get(mid, x - 1) >= y){
                        r = mid - 1, ans = mid;
                    }
                    else{
                        l = mid + 1;
                    }
                }
                if (ans != -1){
                    kol += (x - ans);
                }
                l = x, r = n - 1, ans = -1;
                while (l <= r){
                    int mid = (l + r) / 2;
                    if (get(x, mid) >= y){
                        r = mid - 1, ans = mid;
                    }
                    else{
                        l = mid + 1;
                    }
                }
                if (ans != -1){
                    kol += (ans - x + 1);
                }
                cout << kol << '\n';
            }
        }
    }
}
/*
 */



#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...