Submission #899135

# Submission time Handle Problem Language Result Execution time Memory
899135 2024-01-05T13:58:49 Z Nika533 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
2183 ms 116988 KB
#pragma gcc diagnostic "-std=c++1z"
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()

using namespace std;

const int N=1e6+5;
int t[N*4],arr[N],ans[N],f[N];
int n,m,T,k;
vector<pair<pii,int>> q[N];
stack<int> st;

void build(int v, int tl, int tr) {
     if (tl==tr) {
          t[v]=arr[tl];
          return;
     }
     int mid=(tl+tr)/2;
     build(v*2,tl,mid);
     build(v*2+1,mid+1,tr);
     t[v]=max(t[v*2],t[v*2+1]);
}

void update(int v, int tl, int tr, int ind, int val) {
     if (tl==tr) {
          t[v]=val;
          return;
     }
     int mid=(tl+tr)/2;
     if (ind<=mid) update(v*2,tl,mid,ind,val);
     else update(v*2+1,mid+1,tr,ind,val);
     t[v]=max(t[v*2],t[v*2+1]);
}

int query(int v, int tl, int tr, int l, int r) {
     if (tl==l && tr==r) {
          return t[v];
     }
     int mid=(tl+tr)/2;
     if (r<=mid) return query(v*2,tl,mid,l,r);
     if (l>=mid+1) return query(v*2+1,mid+1,tr,l,r);
     return max(query(v*2,tl,mid,l,mid),query(v*2+1,mid+1,tr,mid+1,r));
}

void test_case() {
     cin>>n>>m;

     for (int i=1; i<=n; i++) cin>>arr[i];

     for (int i=1; i<=m; i++) {
          int l,r,k; cin>>l>>r>>k;
          q[r].pb({{l,k},i});
     }

     for (int i=1; i<=n; i++) {
          while (st.size() && arr[st.top()]<=arr[i]) st.pop();
          if (st.size()) f[i]=st.top();
          st.push(i);
     }

     for (int r=1; r<=n; r++) {
          if (f[r]) update(1,1,n,f[r],arr[f[r]]+arr[r]);
          for (auto a:q[r]) {
               int l=a.f.f,k=a.f.s,i=a.s;
               ans[i]=(query(1,1,n,l,r)<=k);
          }
     }

     for (int i=1; i<=m; i++) cout<<ans[i]<<endl;
}
main () {
	ios :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	T=1; 
	while (T--) test_case();
}

Compilation message

sortbooks.cpp:1: warning: ignoring '#pragma gcc diagnostic' [-Wunknown-pragmas]
    1 | #pragma gcc diagnostic "-std=c++1z"
      | 
sortbooks.cpp:78:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   78 | main () {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 31324 KB Output is correct
2 Correct 6 ms 29276 KB Output is correct
3 Correct 7 ms 31324 KB Output is correct
4 Correct 6 ms 31424 KB Output is correct
5 Correct 6 ms 31412 KB Output is correct
6 Correct 7 ms 31324 KB Output is correct
7 Correct 7 ms 31324 KB Output is correct
8 Correct 8 ms 29372 KB Output is correct
9 Correct 7 ms 29276 KB Output is correct
10 Correct 7 ms 29276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 31324 KB Output is correct
2 Correct 6 ms 29276 KB Output is correct
3 Correct 7 ms 31324 KB Output is correct
4 Correct 6 ms 31424 KB Output is correct
5 Correct 6 ms 31412 KB Output is correct
6 Correct 7 ms 31324 KB Output is correct
7 Correct 7 ms 31324 KB Output is correct
8 Correct 8 ms 29372 KB Output is correct
9 Correct 7 ms 29276 KB Output is correct
10 Correct 7 ms 29276 KB Output is correct
11 Correct 13 ms 31492 KB Output is correct
12 Correct 11 ms 33628 KB Output is correct
13 Correct 12 ms 33680 KB Output is correct
14 Correct 16 ms 33800 KB Output is correct
15 Correct 15 ms 33576 KB Output is correct
16 Correct 14 ms 31580 KB Output is correct
17 Correct 14 ms 31576 KB Output is correct
18 Correct 14 ms 31576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2133 ms 98492 KB Output is correct
2 Correct 2093 ms 114892 KB Output is correct
3 Correct 2055 ms 115480 KB Output is correct
4 Correct 2156 ms 114928 KB Output is correct
5 Correct 1885 ms 92936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 179 ms 39080 KB Output is correct
2 Correct 168 ms 40264 KB Output is correct
3 Correct 176 ms 36068 KB Output is correct
4 Correct 173 ms 36948 KB Output is correct
5 Correct 166 ms 36256 KB Output is correct
6 Correct 161 ms 40212 KB Output is correct
7 Correct 151 ms 40276 KB Output is correct
8 Correct 158 ms 35648 KB Output is correct
9 Correct 135 ms 33284 KB Output is correct
10 Correct 157 ms 35504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 31324 KB Output is correct
2 Correct 6 ms 29276 KB Output is correct
3 Correct 7 ms 31324 KB Output is correct
4 Correct 6 ms 31424 KB Output is correct
5 Correct 6 ms 31412 KB Output is correct
6 Correct 7 ms 31324 KB Output is correct
7 Correct 7 ms 31324 KB Output is correct
8 Correct 8 ms 29372 KB Output is correct
9 Correct 7 ms 29276 KB Output is correct
10 Correct 7 ms 29276 KB Output is correct
11 Correct 13 ms 31492 KB Output is correct
12 Correct 11 ms 33628 KB Output is correct
13 Correct 12 ms 33680 KB Output is correct
14 Correct 16 ms 33800 KB Output is correct
15 Correct 15 ms 33576 KB Output is correct
16 Correct 14 ms 31580 KB Output is correct
17 Correct 14 ms 31576 KB Output is correct
18 Correct 14 ms 31576 KB Output is correct
19 Correct 368 ms 49472 KB Output is correct
20 Correct 365 ms 50084 KB Output is correct
21 Correct 340 ms 50648 KB Output is correct
22 Correct 340 ms 50516 KB Output is correct
23 Correct 342 ms 50516 KB Output is correct
24 Correct 315 ms 42320 KB Output is correct
25 Correct 368 ms 42232 KB Output is correct
26 Correct 329 ms 42120 KB Output is correct
27 Correct 358 ms 42164 KB Output is correct
28 Correct 346 ms 42108 KB Output is correct
29 Correct 344 ms 41808 KB Output is correct
30 Correct 344 ms 41888 KB Output is correct
31 Correct 348 ms 41812 KB Output is correct
32 Correct 352 ms 41844 KB Output is correct
33 Correct 356 ms 41812 KB Output is correct
34 Correct 325 ms 46204 KB Output is correct
35 Correct 311 ms 45800 KB Output is correct
36 Correct 341 ms 45792 KB Output is correct
37 Correct 331 ms 45908 KB Output is correct
38 Correct 355 ms 45872 KB Output is correct
39 Correct 334 ms 41984 KB Output is correct
40 Correct 313 ms 39936 KB Output is correct
41 Correct 346 ms 42296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 31324 KB Output is correct
2 Correct 6 ms 29276 KB Output is correct
3 Correct 7 ms 31324 KB Output is correct
4 Correct 6 ms 31424 KB Output is correct
5 Correct 6 ms 31412 KB Output is correct
6 Correct 7 ms 31324 KB Output is correct
7 Correct 7 ms 31324 KB Output is correct
8 Correct 8 ms 29372 KB Output is correct
9 Correct 7 ms 29276 KB Output is correct
10 Correct 7 ms 29276 KB Output is correct
11 Correct 13 ms 31492 KB Output is correct
12 Correct 11 ms 33628 KB Output is correct
13 Correct 12 ms 33680 KB Output is correct
14 Correct 16 ms 33800 KB Output is correct
15 Correct 15 ms 33576 KB Output is correct
16 Correct 14 ms 31580 KB Output is correct
17 Correct 14 ms 31576 KB Output is correct
18 Correct 14 ms 31576 KB Output is correct
19 Correct 2133 ms 98492 KB Output is correct
20 Correct 2093 ms 114892 KB Output is correct
21 Correct 2055 ms 115480 KB Output is correct
22 Correct 2156 ms 114928 KB Output is correct
23 Correct 1885 ms 92936 KB Output is correct
24 Correct 179 ms 39080 KB Output is correct
25 Correct 168 ms 40264 KB Output is correct
26 Correct 176 ms 36068 KB Output is correct
27 Correct 173 ms 36948 KB Output is correct
28 Correct 166 ms 36256 KB Output is correct
29 Correct 161 ms 40212 KB Output is correct
30 Correct 151 ms 40276 KB Output is correct
31 Correct 158 ms 35648 KB Output is correct
32 Correct 135 ms 33284 KB Output is correct
33 Correct 157 ms 35504 KB Output is correct
34 Correct 368 ms 49472 KB Output is correct
35 Correct 365 ms 50084 KB Output is correct
36 Correct 340 ms 50648 KB Output is correct
37 Correct 340 ms 50516 KB Output is correct
38 Correct 342 ms 50516 KB Output is correct
39 Correct 315 ms 42320 KB Output is correct
40 Correct 368 ms 42232 KB Output is correct
41 Correct 329 ms 42120 KB Output is correct
42 Correct 358 ms 42164 KB Output is correct
43 Correct 346 ms 42108 KB Output is correct
44 Correct 344 ms 41808 KB Output is correct
45 Correct 344 ms 41888 KB Output is correct
46 Correct 348 ms 41812 KB Output is correct
47 Correct 352 ms 41844 KB Output is correct
48 Correct 356 ms 41812 KB Output is correct
49 Correct 325 ms 46204 KB Output is correct
50 Correct 311 ms 45800 KB Output is correct
51 Correct 341 ms 45792 KB Output is correct
52 Correct 331 ms 45908 KB Output is correct
53 Correct 355 ms 45872 KB Output is correct
54 Correct 334 ms 41984 KB Output is correct
55 Correct 313 ms 39936 KB Output is correct
56 Correct 346 ms 42296 KB Output is correct
57 Correct 2183 ms 115728 KB Output is correct
58 Correct 2068 ms 115400 KB Output is correct
59 Correct 2007 ms 116372 KB Output is correct
60 Correct 1990 ms 116988 KB Output is correct
61 Correct 2041 ms 116048 KB Output is correct
62 Correct 1967 ms 116236 KB Output is correct
63 Correct 1668 ms 95240 KB Output is correct
64 Correct 1594 ms 95000 KB Output is correct
65 Correct 1815 ms 94152 KB Output is correct
66 Correct 1870 ms 94208 KB Output is correct
67 Correct 1875 ms 94012 KB Output is correct
68 Correct 1847 ms 93100 KB Output is correct
69 Correct 1899 ms 93300 KB Output is correct
70 Correct 1899 ms 93200 KB Output is correct
71 Correct 1868 ms 93168 KB Output is correct
72 Correct 1874 ms 76624 KB Output is correct
73 Correct 1572 ms 82116 KB Output is correct
74 Correct 1565 ms 82300 KB Output is correct
75 Correct 1537 ms 82864 KB Output is correct
76 Correct 1548 ms 82904 KB Output is correct
77 Correct 1559 ms 82200 KB Output is correct
78 Correct 1769 ms 84840 KB Output is correct
79 Correct 1559 ms 69516 KB Output is correct
80 Correct 1732 ms 80736 KB Output is correct