답안 #348440

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
348440 2021-01-15T02:41:05 Z casperwang Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1380 ms 45164 KB
#include <bits/stdc++.h>
#define tiiii tuple<int,int,int,int>
#define All(x) x.begin(), x.end()
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }

const int MAXN = 1000000;
int n, m;
int w[MAXN+1];
vector <tiiii> qry;
vector <bool> ans;
stack <int> stk;

class Seg {
  private:
    int arr[MAXN*4+5];
    void pull(int now) {
      arr[now] = max(arr[now*2], arr[now*2+1]);
    }
  public:
    void mdy(int p, int k, int now=1, int l=1, int r=n) {
      if (l == p && r == p) {
        arr[now] = max(arr[now], k);
        return;
      } else if (l > p || r < p) return;
      int mid = l + r >> 1;
      mdy(p, k, now*2  , l, mid);
      mdy(p, k, now*2+1,mid+1,r);
      pull(now);
      return;
    }
    int qry(int ql, int qr, int now=1, int l=1, int r=n) {
      if (ql <= l && r <= qr) {
        return arr[now];
      } else if (l > qr || r < ql) return 0;
      int mid = l + r >> 1, mmax = 0;
      mmax = max(mmax, qry(ql, qr, now*2  , l, mid));
      mmax = max(mmax, qry(ql, qr, now*2+1,mid+1,r));
      return mmax;
    }
} seg;

void add(int id) {
  while (stk.size() && w[id] >= w[stk.top()])
    stk.pop();
  if (stk.size())
    seg.mdy(stk.top(), w[stk.top()] + w[id]);
  stk.push(id);
}

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> w[i];
  qry.resize(m);
  for (int i = 0; i < m; i++) {
    auto &[r, l, k, id] = qry[i];
    cin >> l >> r >> k;
    id = i;
  }
  sort(All(qry));
  ans.resize(m);
  int nowR = 0;
  for (int i = 0; i < m; i++) {
    auto &[r, l, k, id] = qry[i];
    while (nowR < r)
      add(++nowR);
    ans[id] = seg.qry(l, r) <= k;
  }
  for (int i = 0 ; i < m; i++)
    cout << ans[i] << '\n';
}

Compilation message

sortbooks.cpp: In member function 'void Seg::mdy(int, int, int, int, int)':
sortbooks.cpp:29:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   29 |       int mid = l + r >> 1;
      |                 ~~^~~
sortbooks.cpp: In member function 'int Seg::qry(int, int, int, int, int)':
sortbooks.cpp:39:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   39 |       int mid = l + r >> 1, mmax = 0;
      |                 ~~^~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:61:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   61 |     auto &[r, l, k, id] = qry[i];
      |           ^
sortbooks.cpp:69:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   69 |     auto &[r, l, k, id] = qry[i];
      |           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 3 ms 492 KB Output is correct
12 Correct 4 ms 620 KB Output is correct
13 Correct 4 ms 620 KB Output is correct
14 Correct 6 ms 748 KB Output is correct
15 Correct 6 ms 748 KB Output is correct
16 Correct 4 ms 620 KB Output is correct
17 Correct 4 ms 620 KB Output is correct
18 Correct 5 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1380 ms 43328 KB Output is correct
2 Correct 1339 ms 34636 KB Output is correct
3 Correct 1329 ms 34412 KB Output is correct
4 Correct 1339 ms 34540 KB Output is correct
5 Correct 984 ms 26348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 5612 KB Output is correct
2 Correct 103 ms 5552 KB Output is correct
3 Correct 83 ms 4460 KB Output is correct
4 Correct 82 ms 4588 KB Output is correct
5 Correct 84 ms 4588 KB Output is correct
6 Correct 76 ms 4460 KB Output is correct
7 Correct 77 ms 4376 KB Output is correct
8 Correct 84 ms 4204 KB Output is correct
9 Correct 49 ms 3436 KB Output is correct
10 Correct 83 ms 4332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 3 ms 492 KB Output is correct
12 Correct 4 ms 620 KB Output is correct
13 Correct 4 ms 620 KB Output is correct
14 Correct 6 ms 748 KB Output is correct
15 Correct 6 ms 748 KB Output is correct
16 Correct 4 ms 620 KB Output is correct
17 Correct 4 ms 620 KB Output is correct
18 Correct 5 ms 620 KB Output is correct
19 Correct 244 ms 13424 KB Output is correct
20 Correct 246 ms 13420 KB Output is correct
21 Correct 231 ms 13164 KB Output is correct
22 Correct 227 ms 13204 KB Output is correct
23 Correct 228 ms 13164 KB Output is correct
24 Correct 175 ms 10988 KB Output is correct
25 Correct 178 ms 10988 KB Output is correct
26 Correct 186 ms 11244 KB Output is correct
27 Correct 187 ms 11376 KB Output is correct
28 Correct 193 ms 11244 KB Output is correct
29 Correct 187 ms 11244 KB Output is correct
30 Correct 190 ms 11372 KB Output is correct
31 Correct 189 ms 11244 KB Output is correct
32 Correct 189 ms 11244 KB Output is correct
33 Correct 196 ms 11380 KB Output is correct
34 Correct 180 ms 10988 KB Output is correct
35 Correct 178 ms 10988 KB Output is correct
36 Correct 170 ms 10732 KB Output is correct
37 Correct 170 ms 10732 KB Output is correct
38 Correct 176 ms 10988 KB Output is correct
39 Correct 182 ms 10732 KB Output is correct
40 Correct 142 ms 8940 KB Output is correct
41 Correct 179 ms 9452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 3 ms 492 KB Output is correct
12 Correct 4 ms 620 KB Output is correct
13 Correct 4 ms 620 KB Output is correct
14 Correct 6 ms 748 KB Output is correct
15 Correct 6 ms 748 KB Output is correct
16 Correct 4 ms 620 KB Output is correct
17 Correct 4 ms 620 KB Output is correct
18 Correct 5 ms 620 KB Output is correct
19 Correct 1380 ms 43328 KB Output is correct
20 Correct 1339 ms 34636 KB Output is correct
21 Correct 1329 ms 34412 KB Output is correct
22 Correct 1339 ms 34540 KB Output is correct
23 Correct 984 ms 26348 KB Output is correct
24 Correct 105 ms 5612 KB Output is correct
25 Correct 103 ms 5552 KB Output is correct
26 Correct 83 ms 4460 KB Output is correct
27 Correct 82 ms 4588 KB Output is correct
28 Correct 84 ms 4588 KB Output is correct
29 Correct 76 ms 4460 KB Output is correct
30 Correct 77 ms 4376 KB Output is correct
31 Correct 84 ms 4204 KB Output is correct
32 Correct 49 ms 3436 KB Output is correct
33 Correct 83 ms 4332 KB Output is correct
34 Correct 244 ms 13424 KB Output is correct
35 Correct 246 ms 13420 KB Output is correct
36 Correct 231 ms 13164 KB Output is correct
37 Correct 227 ms 13204 KB Output is correct
38 Correct 228 ms 13164 KB Output is correct
39 Correct 175 ms 10988 KB Output is correct
40 Correct 178 ms 10988 KB Output is correct
41 Correct 186 ms 11244 KB Output is correct
42 Correct 187 ms 11376 KB Output is correct
43 Correct 193 ms 11244 KB Output is correct
44 Correct 187 ms 11244 KB Output is correct
45 Correct 190 ms 11372 KB Output is correct
46 Correct 189 ms 11244 KB Output is correct
47 Correct 189 ms 11244 KB Output is correct
48 Correct 196 ms 11380 KB Output is correct
49 Correct 180 ms 10988 KB Output is correct
50 Correct 178 ms 10988 KB Output is correct
51 Correct 170 ms 10732 KB Output is correct
52 Correct 170 ms 10732 KB Output is correct
53 Correct 176 ms 10988 KB Output is correct
54 Correct 182 ms 10732 KB Output is correct
55 Correct 142 ms 8940 KB Output is correct
56 Correct 179 ms 9452 KB Output is correct
57 Correct 1335 ms 44140 KB Output is correct
58 Correct 1340 ms 45164 KB Output is correct
59 Correct 1305 ms 43884 KB Output is correct
60 Correct 1299 ms 44524 KB Output is correct
61 Correct 1305 ms 43616 KB Output is correct
62 Correct 1305 ms 44524 KB Output is correct
63 Correct 904 ms 34760 KB Output is correct
64 Correct 916 ms 34796 KB Output is correct
65 Correct 982 ms 36972 KB Output is correct
66 Correct 982 ms 39328 KB Output is correct
67 Correct 988 ms 37740 KB Output is correct
68 Correct 993 ms 40044 KB Output is correct
69 Correct 991 ms 37132 KB Output is correct
70 Correct 998 ms 35436 KB Output is correct
71 Correct 987 ms 28908 KB Output is correct
72 Correct 992 ms 33644 KB Output is correct
73 Correct 932 ms 34412 KB Output is correct
74 Correct 920 ms 34800 KB Output is correct
75 Correct 892 ms 34412 KB Output is correct
76 Correct 895 ms 23964 KB Output is correct
77 Correct 894 ms 33516 KB Output is correct
78 Correct 973 ms 32876 KB Output is correct
79 Correct 720 ms 24940 KB Output is correct
80 Correct 997 ms 23464 KB Output is correct