제출 #984416

#제출 시각아이디문제언어결과실행 시간메모리
984416saayan007다리 (APIO19_bridges)C++17
0 / 100
13 ms7040 KiB
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
#define repd(i, a, b) for(int (i) = (a); i >= (b); --i)

#define em emplace
#define eb emplace_back

#define pi pair<int, int>
#define fr first
#define sc second
#define mp make_pair

const char nl = '\n';
const int mod = 1e9 + 7;
const int inf = 1e17;

struct SGT {
    int n, m;
    vector<int> a;

    SGT() {}
    SGT(int N, int wt[]) {
        n = 1; while(n < N + 1) n *= 2;
        a.resize(2*n, -inf);
        m = N - 1;
        rep(i, 1, N - 1) {
            a[i + n] = wt[i];
        }
        repd(i, n - 1, 1) calc(i);
    }

    void mod(int x, int v) {
        x += n;
        a[x] = v;
        for(x /= 2; x > 0; x /= 2) calc(x);
    }

    void calc(int i) {
        if(i >= n) a[i] = min(a[2*i], a[2*i + 1]);
    }

    int left(int x, int lx, int rx, int pos, int val) {
        if(rx < pos) return n;
        if(a[x] >= val) return n;
        int d = (lx + rx) / 2;
        if(d < pos) return left(2*x + 1, d + 1, rx, pos, val);
        int ans = left(2*x, lx, d, pos, val);
        if(ans < n) return ans;
        return left(2*x + 1, d + 1, rx, pos, val);
    }

    int left(int pos, int val) { // first i >= pos with a[i] < val
        return min(m + 1, left(1, 0, n - 1, pos, val));
    }

    int right(int x, int lx, int rx, int pos, int val) {
        if(lx > pos) return 0;
        if(a[x] >= val) return 0;
        int d = (lx + rx) / 2;
        if(pos < d + 1) return right(2*x, lx, d, pos, val);
        int ans = right(2*x + 1, d + 1, rx, pos, val);
        if(ans > 0) return ans;
        return right(2*x, lx, d, pos, val);
    }

    int right(int pos, int val) { // first i <= pos with a[i] < val
        return max(1ll, right(1, 0, n - 1, pos, val));
    }
};

#warning constants according to subtask
const int N = 5e4L + 10;
const int M = 1e5L + 10;
int n, m, q;
int ed[M][3];
int wt[N];
SGT sgt;

void modify(int b, int r) {
    wt[b] = r;
    sgt.mod(b, r);
}

void query(int s, int w) {
    int r = sgt.left(s, w);
    int l = sgt.right(s - 1, w);
    cout << r - l << nl;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;
    rep(i, 1, m) {
        int u, v, d;
        cin >> u >> v >> d;
        assert(u == i);
        assert(v == i + 1);
        wt[u] = d;
    }

    sgt = SGT(n + 1, wt);

    cin >> q;
    rep(i, 1, q) {
        int t; cin >> t;
        if(t == 1) {
            int b, r; cin >> b >> r;
            modify(b, r);
        }
        else {
            int s, w; cin >> s >> w;
            query(s, w);
        }
    }
}

컴파일 시 표준 에러 (stderr) 메시지

bridges.cpp:74:2: warning: #warning constants according to subtask [-Wcpp]
   74 | #warning constants according to subtask
      |  ^~~~~~~
bridges.cpp: In constructor 'SGT::SGT(long long int, long long int*)':
bridges.cpp:5:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
bridges.cpp:29:9: note: in expansion of macro 'rep'
   29 |         rep(i, 1, N - 1) {
      |         ^~~
bridges.cpp:6:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define repd(i, a, b) for(int (i) = (a); i >= (b); --i)
      |                               ^
bridges.cpp:32:9: note: in expansion of macro 'repd'
   32 |         repd(i, n - 1, 1) calc(i);
      |         ^~~~
bridges.cpp: In function 'int32_t main()':
bridges.cpp:5:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
bridges.cpp:98:5: note: in expansion of macro 'rep'
   98 |     rep(i, 1, m) {
      |     ^~~
bridges.cpp:5:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
bridges.cpp:109:5: note: in expansion of macro 'rep'
  109 |     rep(i, 1, q) {
      |     ^~~
#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...