Submission #321555

# Submission time Handle Problem Language Result Execution time Memory
321555 2020-11-12T18:19:27 Z tushar_2658 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1989 ms 166004 KB
#include "bits/stdc++.h"
using namespace std;

const int maxn = 1000005;
using ll = long long;

ll a[maxn];  

struct DATA {
  int l, r;
  ll k;
  int id;
};

DATA q[maxn];
vector<DATA> v[maxn];
vector<int> ed[maxn];

ll t[maxn << 2];

void upd(int node, int b, int e, int idx, ll val){
  if(idx > e or idx < b)return;
  if(b == idx && idx == e){
    t[node] = max(t[node], val);
    return;
  }
  int mid = (b + e) >> 1;
  if(idx <= mid)upd(2*node, b, mid, idx, val);
  else upd(2*node + 1, mid + 1, e, idx, val);
  t[node] = max(t[2*node], t[2*node + 1]);
}

ll query(int node, int b, int e, int i, int j){
  if(i > e or j < b)return 0;
  if(b >= i && j >= e)return t[node];
  int mid = (b + e) >> 1;
  return max(query(2*node, b, mid, i, j), query(2*node + 1, mid + 1, e, i, j));
}

int main(int argc, char const *argv[])
{
  int n, m;
  scanf("%d %d", &n, &m);
  for(int i = 1; i <= n; ++i){
    scanf("%lld", &a[i]);
  }  
  stack<int> st;
  for(int i = n; i >= 1; --i){
    while(!st.empty() && a[st.top()] < a[i]){
      ed[st.top()].push_back(i);
      st.pop();
    }
    st.push(i);
  }
  for(int i = 1; i <= m; ++i){
    scanf("%d %d %lld", &q[i].l, &q[i].r, &q[i].k);
    q[i].id = i;
    v[q[i].r].push_back(q[i]);
  }
  vector<int> ans(m + 1);
  for(int i = 1; i <= n; ++i){
    for(auto j : ed[i]){
      upd(1, 1, n, j, a[j] + a[i]);
    }
    for(auto j : v[i]){
      ans[j.id] = query(1, 1, n, j.l, j.r) <= j.k;
    }
  }
  for(int i = 1; i <= m; ++i){
    printf("%d\n", ans[i]);
  }

  return 0;
}

Compilation message

sortbooks.cpp: In function 'int main(int, const char**)':
sortbooks.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   43 |   scanf("%d %d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~~
sortbooks.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |     scanf("%lld", &a[i]);
      |     ~~~~~^~~~~~~~~~~~~~~
sortbooks.cpp:56:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   56 |     scanf("%d %d %lld", &q[i].l, &q[i].r, &q[i].k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 28 ms 47340 KB Output is correct
2 Correct 28 ms 47340 KB Output is correct
3 Correct 30 ms 47340 KB Output is correct
4 Correct 29 ms 47340 KB Output is correct
5 Correct 28 ms 47340 KB Output is correct
6 Correct 29 ms 47340 KB Output is correct
7 Correct 91 ms 47340 KB Output is correct
8 Correct 30 ms 47468 KB Output is correct
9 Correct 29 ms 47468 KB Output is correct
10 Correct 30 ms 47340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 47340 KB Output is correct
2 Correct 28 ms 47340 KB Output is correct
3 Correct 30 ms 47340 KB Output is correct
4 Correct 29 ms 47340 KB Output is correct
5 Correct 28 ms 47340 KB Output is correct
6 Correct 29 ms 47340 KB Output is correct
7 Correct 91 ms 47340 KB Output is correct
8 Correct 30 ms 47468 KB Output is correct
9 Correct 29 ms 47468 KB Output is correct
10 Correct 30 ms 47340 KB Output is correct
11 Correct 31 ms 47596 KB Output is correct
12 Correct 33 ms 47724 KB Output is correct
13 Correct 64 ms 47852 KB Output is correct
14 Correct 36 ms 48108 KB Output is correct
15 Correct 35 ms 47980 KB Output is correct
16 Correct 35 ms 47724 KB Output is correct
17 Correct 34 ms 47724 KB Output is correct
18 Correct 34 ms 47852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1964 ms 164864 KB Output is correct
2 Correct 1989 ms 164904 KB Output is correct
3 Correct 1963 ms 165020 KB Output is correct
4 Correct 1952 ms 164992 KB Output is correct
5 Correct 1498 ms 121376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 166 ms 59412 KB Output is correct
2 Correct 155 ms 59628 KB Output is correct
3 Correct 133 ms 54764 KB Output is correct
4 Correct 142 ms 54696 KB Output is correct
5 Correct 141 ms 54848 KB Output is correct
6 Correct 123 ms 55148 KB Output is correct
7 Correct 117 ms 55020 KB Output is correct
8 Correct 134 ms 56480 KB Output is correct
9 Correct 83 ms 53152 KB Output is correct
10 Correct 134 ms 55972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 47340 KB Output is correct
2 Correct 28 ms 47340 KB Output is correct
3 Correct 30 ms 47340 KB Output is correct
4 Correct 29 ms 47340 KB Output is correct
5 Correct 28 ms 47340 KB Output is correct
6 Correct 29 ms 47340 KB Output is correct
7 Correct 91 ms 47340 KB Output is correct
8 Correct 30 ms 47468 KB Output is correct
9 Correct 29 ms 47468 KB Output is correct
10 Correct 30 ms 47340 KB Output is correct
11 Correct 31 ms 47596 KB Output is correct
12 Correct 33 ms 47724 KB Output is correct
13 Correct 64 ms 47852 KB Output is correct
14 Correct 36 ms 48108 KB Output is correct
15 Correct 35 ms 47980 KB Output is correct
16 Correct 35 ms 47724 KB Output is correct
17 Correct 34 ms 47724 KB Output is correct
18 Correct 34 ms 47852 KB Output is correct
19 Correct 381 ms 71788 KB Output is correct
20 Correct 351 ms 71660 KB Output is correct
21 Correct 302 ms 72332 KB Output is correct
22 Correct 307 ms 72344 KB Output is correct
23 Correct 322 ms 72172 KB Output is correct
24 Correct 255 ms 62828 KB Output is correct
25 Correct 245 ms 62956 KB Output is correct
26 Correct 276 ms 62700 KB Output is correct
27 Correct 266 ms 62444 KB Output is correct
28 Correct 279 ms 62444 KB Output is correct
29 Correct 278 ms 62144 KB Output is correct
30 Correct 293 ms 62316 KB Output is correct
31 Correct 289 ms 62188 KB Output is correct
32 Correct 287 ms 62320 KB Output is correct
33 Correct 280 ms 62188 KB Output is correct
34 Correct 224 ms 62316 KB Output is correct
35 Correct 225 ms 62444 KB Output is correct
36 Correct 220 ms 62316 KB Output is correct
37 Correct 224 ms 62316 KB Output is correct
38 Correct 220 ms 62188 KB Output is correct
39 Correct 280 ms 64952 KB Output is correct
40 Correct 213 ms 61212 KB Output is correct
41 Correct 260 ms 64672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 47340 KB Output is correct
2 Correct 28 ms 47340 KB Output is correct
3 Correct 30 ms 47340 KB Output is correct
4 Correct 29 ms 47340 KB Output is correct
5 Correct 28 ms 47340 KB Output is correct
6 Correct 29 ms 47340 KB Output is correct
7 Correct 91 ms 47340 KB Output is correct
8 Correct 30 ms 47468 KB Output is correct
9 Correct 29 ms 47468 KB Output is correct
10 Correct 30 ms 47340 KB Output is correct
11 Correct 31 ms 47596 KB Output is correct
12 Correct 33 ms 47724 KB Output is correct
13 Correct 64 ms 47852 KB Output is correct
14 Correct 36 ms 48108 KB Output is correct
15 Correct 35 ms 47980 KB Output is correct
16 Correct 35 ms 47724 KB Output is correct
17 Correct 34 ms 47724 KB Output is correct
18 Correct 34 ms 47852 KB Output is correct
19 Correct 1964 ms 164864 KB Output is correct
20 Correct 1989 ms 164904 KB Output is correct
21 Correct 1963 ms 165020 KB Output is correct
22 Correct 1952 ms 164992 KB Output is correct
23 Correct 1498 ms 121376 KB Output is correct
24 Correct 166 ms 59412 KB Output is correct
25 Correct 155 ms 59628 KB Output is correct
26 Correct 133 ms 54764 KB Output is correct
27 Correct 142 ms 54696 KB Output is correct
28 Correct 141 ms 54848 KB Output is correct
29 Correct 123 ms 55148 KB Output is correct
30 Correct 117 ms 55020 KB Output is correct
31 Correct 134 ms 56480 KB Output is correct
32 Correct 83 ms 53152 KB Output is correct
33 Correct 134 ms 55972 KB Output is correct
34 Correct 381 ms 71788 KB Output is correct
35 Correct 351 ms 71660 KB Output is correct
36 Correct 302 ms 72332 KB Output is correct
37 Correct 307 ms 72344 KB Output is correct
38 Correct 322 ms 72172 KB Output is correct
39 Correct 255 ms 62828 KB Output is correct
40 Correct 245 ms 62956 KB Output is correct
41 Correct 276 ms 62700 KB Output is correct
42 Correct 266 ms 62444 KB Output is correct
43 Correct 279 ms 62444 KB Output is correct
44 Correct 278 ms 62144 KB Output is correct
45 Correct 293 ms 62316 KB Output is correct
46 Correct 289 ms 62188 KB Output is correct
47 Correct 287 ms 62320 KB Output is correct
48 Correct 280 ms 62188 KB Output is correct
49 Correct 224 ms 62316 KB Output is correct
50 Correct 225 ms 62444 KB Output is correct
51 Correct 220 ms 62316 KB Output is correct
52 Correct 224 ms 62316 KB Output is correct
53 Correct 220 ms 62188 KB Output is correct
54 Correct 280 ms 64952 KB Output is correct
55 Correct 213 ms 61212 KB Output is correct
56 Correct 260 ms 64672 KB Output is correct
57 Correct 1926 ms 165096 KB Output is correct
58 Correct 1958 ms 165016 KB Output is correct
59 Correct 1895 ms 165896 KB Output is correct
60 Correct 1866 ms 165868 KB Output is correct
61 Correct 1871 ms 165916 KB Output is correct
62 Correct 1869 ms 166004 KB Output is correct
63 Correct 1210 ms 124012 KB Output is correct
64 Correct 1193 ms 124292 KB Output is correct
65 Correct 1453 ms 122348 KB Output is correct
66 Correct 1472 ms 122432 KB Output is correct
67 Correct 1471 ms 122348 KB Output is correct
68 Correct 1496 ms 121324 KB Output is correct
69 Correct 1504 ms 121836 KB Output is correct
70 Correct 1485 ms 122220 KB Output is correct
71 Correct 1486 ms 122144 KB Output is correct
72 Correct 1490 ms 122252 KB Output is correct
73 Correct 1065 ms 120300 KB Output is correct
74 Correct 1058 ms 120224 KB Output is correct
75 Correct 1061 ms 120568 KB Output is correct
76 Correct 1064 ms 120300 KB Output is correct
77 Correct 1219 ms 120428 KB Output is correct
78 Correct 1388 ms 134528 KB Output is correct
79 Correct 1006 ms 115332 KB Output is correct
80 Correct 1378 ms 138384 KB Output is correct