제출 #746070

#제출 시각아이디문제언어결과실행 시간메모리
746070nguyentunglamRailway Trip 2 (JOI22_ho_t4)C++17
8 / 100
2079 ms1968 KiB
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 5010;
int l[20][N], r[20][N];
int n, m, k;
int main() {
    #define task ""
    cin.tie(0) -> sync_with_stdio(0);
    if (fopen ("task.inp", "r")) {
        freopen ("task.inp", "r", stdin);
        freopen ("task.out", "w", stdout);
    }
    if (fopen (task".inp", "r")) {
        freopen (task".inp", "r", stdin);
        freopen (task".out", "w", stdout);
    }
    cin >> n >> k >> m;
    for(int i = 1; i <= n; i++) l[0][i] = r[0][i] = i;
    for(int i = 1; i <= m; i++) {
        int a, b; cin >> a >> b;
        if (a < b) for(int j = a; j <= min(a + k - 1, b - 1); j++) for(int k = j + 1; k <= b; k++) r[0][j] = max(r[0][j], b);
        else for(int j = a; j >= max(a - k + 1, b + 1); j--) for(int k = j - 1; k >= b; k--) l[0][j] = min(l[0][j], b);
    }

    int lg = log2(n);

    for(int j = 1; j <= lg; j++) for(int i = 1; i <= n; i++) {
        l[j][i] = r[j][i] = i;
        for(int k = l[j - 1][i]; k <= r[j - 1][i]; k++) {
            l[j][i] = min(l[j][i], l[j - 1][k]);
            r[j][i] = max(r[j][i], r[j - 1][k]);
        }
    }
    int q; cin >> q;
    while (q--) {
        int s, t; cin >> s >> t;
        int left = s, right = s, ans = 0;
        for(int j = lg; j >= 0; j--) {
            int ll = left, rr = right;
            for(int k = left; k <= right; k++) {
                ll = min(ll, l[j][k]);
                rr = max(rr, r[j][k]);
            }
            if (t > rr || t < ll) {
                left = ll; right = rr;
                ans += (1 << j);
            }
        }
        if (ans == (1 << lg << 1) - 1) ans = -2;
        cout << ans + 1 << endl;
    }
}

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

Main.cpp: In function 'int main()':
Main.cpp:14:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:15:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:18:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:19:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...