답안 #891254

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
891254 2023-12-22T15:21:23 Z stefanneagu RMQ (NOI17_rmq) C++17
30 / 100
96 ms 12368 KB
#include <bits/stdc++.h>

using namespace std;

const int nmax = 1e5 + 1;

struct str {
  int a, b, val;
  const bool operator < (str ult) const {
    return val < ult.val;
  }
} v[nmax];

int aint[4 * nmax], lz[4 * nmax], rmq[nmax][20];

int rmquery(int a, int b) {
  int lg = (int) log2(b - a + 1);
  return min(rmq[a][lg], rmq[b - (1 << lg) + 1][lg]);
}

void lazy(int nod, int st, int dr) {
  aint[nod] = lz[nod];
  if(st != dr) {
    lz[nod << 1] = lz[nod];
    lz[nod << 1|1] = lz[nod];
  }
  lz[nod] = 0;
}

void update(int nod, int st, int dr, int l, int r, int val) {
  if(lz[nod]) {
    lazy(nod, st, dr);
  }
  if(st > r || dr < l) {
    return;
  }
  if(l <= st && dr <= r) {
    lz[nod] = val;
    lazy(nod, st, dr);
    return;
  }
  int mid = (st + dr) / 2;
  update(nod << 1, st, mid, l, r, val);
  update(nod << 1|1, mid + 1, dr, l, r, val);
}

int query(int nod, int st, int dr, int poz) {
  if(lz[nod]) {
    lazy(nod, st, dr);
  }
  if(st == dr) {
    return aint[nod];
  }
  int mid = (st + dr) / 2;
  if(poz <= mid) {
    return query(nod << 1, st, mid, poz);
  } else {
    return query(nod << 1|1, mid + 1, dr, poz);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  for(int i = 1; i <= q; i ++) {
    int a, b, val;
    cin >> a >> b >> val;
    a ++;
    b ++;
    v[i].a = a, v[i].b = b, v[i].val = val;
  }
  sort(v + 1, v + q + 1);
  for(int i = 1; i <= q; i ++) {
    update(1, 1, n, v[i].a, v[i].b, v[i].val);
  }
  vector<int> nou(n + 1);
  for(int i = 1; i <= n; i ++) {
    nou[i] = query(1, 1, n, i);
    rmq[i][0] = nou[i];
  }
  for(int j = 1; (1 << j) <= n; j ++) {
    for(int i = 1; i + (1 << j) - 1 <= n; i ++) {
      rmq[i][j] = min(rmq[i][j - 1], rmq[i + (1 << (j - 1))][j - 1]);
    }
  }
  for(int i = 1; i <= q; i ++) {
    if(rmquery(v[i].a, v[i].b) != v[i].val) {
      for(int j = 1; j <= n; j ++) {
        cout << "-1 ";
      }
      return 0;
    }
  }
  for(int i = 1; i <= n; i ++) {
    cout << nou[i] << " ";
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 2396 KB Output is partially correct
2 Partially correct 0 ms 2396 KB Output is partially correct
3 Partially correct 1 ms 2392 KB Output is partially correct
4 Partially correct 0 ms 2396 KB Output is partially correct
5 Partially correct 0 ms 2396 KB Output is partially correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2392 KB Output is correct
11 Partially correct 1 ms 2392 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 2396 KB Output is partially correct
2 Partially correct 0 ms 2396 KB Output is partially correct
3 Partially correct 1 ms 2392 KB Output is partially correct
4 Partially correct 0 ms 2396 KB Output is partially correct
5 Partially correct 0 ms 2396 KB Output is partially correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2392 KB Output is correct
11 Partially correct 1 ms 2392 KB Output is partially correct
12 Partially correct 1 ms 2396 KB Output is partially correct
13 Partially correct 1 ms 2396 KB Output is partially correct
14 Partially correct 1 ms 2396 KB Output is partially correct
15 Partially correct 1 ms 2396 KB Output is partially correct
16 Partially correct 1 ms 2396 KB Output is partially correct
17 Partially correct 1 ms 2396 KB Output is partially correct
18 Partially correct 1 ms 2396 KB Output is partially correct
19 Partially correct 1 ms 2396 KB Output is partially correct
20 Partially correct 1 ms 2396 KB Output is partially correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Partially correct 0 ms 2396 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 2396 KB Output is partially correct
2 Partially correct 0 ms 2396 KB Output is partially correct
3 Partially correct 1 ms 2392 KB Output is partially correct
4 Partially correct 0 ms 2396 KB Output is partially correct
5 Partially correct 0 ms 2396 KB Output is partially correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2392 KB Output is correct
11 Partially correct 1 ms 2392 KB Output is partially correct
12 Partially correct 1 ms 2396 KB Output is partially correct
13 Partially correct 1 ms 2396 KB Output is partially correct
14 Partially correct 1 ms 2396 KB Output is partially correct
15 Partially correct 1 ms 2396 KB Output is partially correct
16 Partially correct 1 ms 2396 KB Output is partially correct
17 Partially correct 1 ms 2396 KB Output is partially correct
18 Partially correct 1 ms 2396 KB Output is partially correct
19 Partially correct 1 ms 2396 KB Output is partially correct
20 Partially correct 1 ms 2396 KB Output is partially correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Partially correct 0 ms 2396 KB Output is partially correct
27 Partially correct 96 ms 10892 KB Output is partially correct
28 Partially correct 91 ms 12140 KB Output is partially correct
29 Partially correct 70 ms 11552 KB Output is partially correct
30 Partially correct 91 ms 12368 KB Output is partially correct
31 Partially correct 76 ms 11664 KB Output is partially correct
32 Partially correct 86 ms 11964 KB Output is partially correct
33 Partially correct 12 ms 9820 KB Output is partially correct
34 Partially correct 9 ms 9564 KB Output is partially correct
35 Partially correct 22 ms 10588 KB Output is partially correct
36 Correct 63 ms 11860 KB Output is correct
37 Correct 94 ms 12176 KB Output is correct
38 Correct 8 ms 9816 KB Output is correct
39 Correct 74 ms 11880 KB Output is correct
40 Correct 1 ms 2392 KB Output is correct
41 Partially correct 1 ms 2392 KB Output is partially correct