Submission #1040414

# Submission time Handle Problem Language Result Execution time Memory
1040414 2024-08-01T03:45:15 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
366 ms 156948 KB
#include <bits/stdc++.h>
using namespace std;

#define all(a)              a.begin(), a.end()
#define Base                311
#define endl                '\n'
#define fi                  first
#define fii(i, a, b)        for(int i = a; i <= b; i++)
#define fid(i, a, b)        for(int i = a; i >= b; i--)
#define fill(a,n)           memset(a, n, sizeof(a));
#define getbit(i, j)        ((i >> j) & 1)
#define minimize(x, y)      x = (x > y ? y : x)
#define maximize(x, y)      x = (x < y ? y : x)
#define ins                 insert
#define int                 long long
#define ll                  long long
#define maxn                1000006 
#define MOD                 1000000007
#define name                "file"
#define pb                  push_back
#define pii                 pair< int, int >
#define pll                 pair< long long , long long >
#define re                  return
#define sz(x)               int(x.size())
#define se                  second
#define ull                 unsigned long long

void ctime () { 
    cerr << "\n" << "\nTime elapsed: " << 1000 * clock () / CLOCKS_PER_SEC << "ms\n" ;        
}

void iof () { 
    if ( fopen ( name ".inp" , "r" )) 
    {
        freopen ( name ".inp" , "r" , stdin ); 
        freopen ( name ".out" , "w", stdout );
    }
    ios_base :: sync_with_stdio ( 0 );
    cin . tie ( NULL ), cout . tie ( NULL );
}

struct ddata {
    ll pos, id, k;
};

vector<ddata> ques[maxn];
ll T[maxn];
ll a[maxn];
ll ans[maxn];
void update(int id, int l, int r, int pos, ll val)
{
    if (l > pos || r < pos) re;
    if (l == r) 
    {
        T[id] = val;
        re;
    }
    int mid = (l + r) / 2;
    update(id * 2, l, mid, pos, val);
    update(id * 2 + 1, mid + 1, r, pos, val);
    T[id] = max(T[id * 2], T[id * 2 + 1]);
}

ll get(int id, int l, int r, int u, int v)
{
    if (u > r || l > v) re 0;
    if (l >= u && r <= v) re T[id];
    int mid = (l + r) / 2;
    re max(get(id * 2, l, mid, u, v), get(id * 2 + 1, mid + 1, r, u, v));
}

signed main(){
    iof();
    int n, m;
    cin >> n >> m;
    fii(i, 1, n) 
        cin >> a[i];

    fii(i, 1, m)
    {
        ll l, r, val;
        cin >> l >> r >> val;
        ques[r].pb({l, i, val});
    }
    stack<ll> st;
    fii(i, 1, n)
    {
        while(!st.empty() && a[st.top()] <= a[i]) st.pop();
        if (st.size()) update(1, 1, n, st.top(), a[st.top()] + a[i]);
        st.push(i);
        for(auto x : ques[i])
        {
            int l = x.pos, id = x.id, k = x.k;
            if (get(1, 1, n, l, i) <= k) ans[id] = 1;
            else ans[id] = 0;
        }
    }
    fii(i, 1, m) cout << ans[i] << endl;
    ctime();
    re 0;
}

Compilation message

sortbooks.cpp: In function 'void iof()':
sortbooks.cpp:35:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         freopen ( name ".inp" , "r" , stdin );
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:36:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         freopen ( name ".out" , "w", stdout );
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 28760 KB Output is correct
2 Correct 4 ms 26716 KB Output is correct
3 Correct 4 ms 28764 KB Output is correct
4 Correct 4 ms 28764 KB Output is correct
5 Correct 4 ms 28552 KB Output is correct
6 Correct 4 ms 28764 KB Output is correct
7 Correct 4 ms 28764 KB Output is correct
8 Correct 4 ms 26716 KB Output is correct
9 Correct 4 ms 26716 KB Output is correct
10 Correct 4 ms 26716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 28760 KB Output is correct
2 Correct 4 ms 26716 KB Output is correct
3 Correct 4 ms 28764 KB Output is correct
4 Correct 4 ms 28764 KB Output is correct
5 Correct 4 ms 28552 KB Output is correct
6 Correct 4 ms 28764 KB Output is correct
7 Correct 4 ms 28764 KB Output is correct
8 Correct 4 ms 26716 KB Output is correct
9 Correct 4 ms 26716 KB Output is correct
10 Correct 4 ms 26716 KB Output is correct
11 Correct 5 ms 28764 KB Output is correct
12 Correct 6 ms 28852 KB Output is correct
13 Correct 6 ms 28764 KB Output is correct
14 Correct 6 ms 28764 KB Output is correct
15 Correct 7 ms 28764 KB Output is correct
16 Correct 5 ms 26828 KB Output is correct
17 Correct 6 ms 26972 KB Output is correct
18 Correct 5 ms 26972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 366 ms 156948 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 57 ms 38508 KB Output is correct
2 Correct 55 ms 38736 KB Output is correct
3 Correct 53 ms 34316 KB Output is correct
4 Correct 53 ms 34388 KB Output is correct
5 Correct 53 ms 34384 KB Output is correct
6 Correct 48 ms 36440 KB Output is correct
7 Correct 40 ms 36444 KB Output is correct
8 Correct 55 ms 34072 KB Output is correct
9 Correct 24 ms 32016 KB Output is correct
10 Correct 45 ms 33992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 28760 KB Output is correct
2 Correct 4 ms 26716 KB Output is correct
3 Correct 4 ms 28764 KB Output is correct
4 Correct 4 ms 28764 KB Output is correct
5 Correct 4 ms 28552 KB Output is correct
6 Correct 4 ms 28764 KB Output is correct
7 Correct 4 ms 28764 KB Output is correct
8 Correct 4 ms 26716 KB Output is correct
9 Correct 4 ms 26716 KB Output is correct
10 Correct 4 ms 26716 KB Output is correct
11 Correct 5 ms 28764 KB Output is correct
12 Correct 6 ms 28852 KB Output is correct
13 Correct 6 ms 28764 KB Output is correct
14 Correct 6 ms 28764 KB Output is correct
15 Correct 7 ms 28764 KB Output is correct
16 Correct 5 ms 26828 KB Output is correct
17 Correct 6 ms 26972 KB Output is correct
18 Correct 5 ms 26972 KB Output is correct
19 Correct 128 ms 43056 KB Output is correct
20 Correct 129 ms 43092 KB Output is correct
21 Correct 116 ms 44680 KB Output is correct
22 Correct 112 ms 44624 KB Output is correct
23 Correct 112 ms 44432 KB Output is correct
24 Correct 94 ms 38480 KB Output is correct
25 Correct 89 ms 38484 KB Output is correct
26 Correct 102 ms 38100 KB Output is correct
27 Correct 100 ms 37988 KB Output is correct
28 Correct 102 ms 37876 KB Output is correct
29 Correct 105 ms 37712 KB Output is correct
30 Correct 109 ms 37724 KB Output is correct
31 Correct 104 ms 37756 KB Output is correct
32 Correct 106 ms 37712 KB Output is correct
33 Correct 110 ms 37972 KB Output is correct
34 Correct 85 ms 42068 KB Output is correct
35 Correct 84 ms 42028 KB Output is correct
36 Correct 84 ms 42068 KB Output is correct
37 Correct 88 ms 42024 KB Output is correct
38 Correct 87 ms 42064 KB Output is correct
39 Correct 96 ms 40448 KB Output is correct
40 Correct 74 ms 36972 KB Output is correct
41 Correct 97 ms 37112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 28760 KB Output is correct
2 Correct 4 ms 26716 KB Output is correct
3 Correct 4 ms 28764 KB Output is correct
4 Correct 4 ms 28764 KB Output is correct
5 Correct 4 ms 28552 KB Output is correct
6 Correct 4 ms 28764 KB Output is correct
7 Correct 4 ms 28764 KB Output is correct
8 Correct 4 ms 26716 KB Output is correct
9 Correct 4 ms 26716 KB Output is correct
10 Correct 4 ms 26716 KB Output is correct
11 Correct 5 ms 28764 KB Output is correct
12 Correct 6 ms 28852 KB Output is correct
13 Correct 6 ms 28764 KB Output is correct
14 Correct 6 ms 28764 KB Output is correct
15 Correct 7 ms 28764 KB Output is correct
16 Correct 5 ms 26828 KB Output is correct
17 Correct 6 ms 26972 KB Output is correct
18 Correct 5 ms 26972 KB Output is correct
19 Runtime error 366 ms 156948 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -