Submission #240142

# Submission time Handle Problem Language Result Execution time Memory
240142 2020-06-18T07:31:41 Z wiwiho Bridges (APIO19_bridges) C++14
0 / 100
1469 ms 4780 KB
//#define NDEBUG

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) ((a + b - 1) / b)
#define tomax(a, b) (a = max(a, b))
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

//#define TEST

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

struct Node{
    int v = 0, l = -1, r = -1;
};

vector<Node> st;
int ts = 0;
vector<int> w;
int m;

int build(int l, int r){
    int id = ts++;
    assert(l <= r);
    cerr << id << "\n";
    if(l == r){
        st[id].v = w[l];
        return id;
    }
    int m = (l + r) / 2;
    st[id].l = build(l, m);
    st[id].r = build(m + 1, r);
    st[id].v = min(st[st[id].l].v, st[st[id].r].v);
    return id;
}

void modify(int x, int v, int L, int R, int id){
    if(L == R){
        st[id].v = v;
        return;
    }
    int M = (L + R) / 2;
    if(x <= M) modify(x, v, L, M, st[id].l);
    else modify(x, v, M + 1, R, st[id].r);
    st[id].v = min(st[st[id].l].v, st[st[id].r].v);
}

int query(int l, int r, int L, int R, int id){
    if(l == L && r == R){
        return st[id].v;
    }
    int M = (L + R) / 2;
    if(r <= M) return query(l, r, L, M, st[id].l);
    else if(l > M) return query(l, r, M + 1, R, st[id].r);
    else{
        return min(query(l, M, L, M, st[id].l), query(M + 1, r, M + 1, R, st[id].r));
    }
}

int main(){
    StarBurstStream

    int n;
    cin >> n >> m;
    w.resize(m + 1);
    for(int i = 1; i <= m; i++){
        int u, v;
        cin >> u >> v;
        cin >> w[i];
    }

    st.resize(2 * m);
    build(1, m);

    int q;
    cin >> q;
    while(q--){

        int t;
        cin >> t;

        if(t == 1){
            int b, r;
            cin >> b >> r;
            modify(b, r, 1, m, 0);
        }
        else{
            int s, wl;
            cin >> s >> wl;

            int ans = 1;
            if(s != n){
                int l = s, r = m;
                while(l < r){
                    int mid = (l + r + 1) / 2;
                    if(query(s, mid, 1, m, 0) >= wl) l = mid;
                    else r = mid - 1;
                }
                if(query(s, s, 1, m, 0) < wl) l = s - 1;
                ans += l - s + 1;
            }

            if(s != 1){
                int l = 1, r = s - 1;
                while(l < r){
                    int mid = (l + r) / 2;
                    if(query(mid, s - 1, 1, m, 0) >= wl) r = mid;
                    else l = mid + 1;
                }
                if(query(s - 1, s - 1, 1, m, 0) < wl) l = s;
                ans += s - l;
            }

            cout << ans << "\n";
        }

    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 702 ms 2424 KB Output is correct
2 Correct 684 ms 2424 KB Output is correct
3 Correct 712 ms 2424 KB Output is correct
4 Correct 716 ms 2656 KB Output is correct
5 Correct 719 ms 2680 KB Output is correct
6 Correct 758 ms 2808 KB Output is correct
7 Correct 740 ms 2680 KB Output is correct
8 Correct 769 ms 2552 KB Output is correct
9 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 545 ms 1760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1469 ms 4780 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 702 ms 2424 KB Output is correct
2 Correct 684 ms 2424 KB Output is correct
3 Correct 712 ms 2424 KB Output is correct
4 Correct 716 ms 2656 KB Output is correct
5 Correct 719 ms 2680 KB Output is correct
6 Correct 758 ms 2808 KB Output is correct
7 Correct 740 ms 2680 KB Output is correct
8 Correct 769 ms 2552 KB Output is correct
9 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -