Submission #583955

# Submission time Handle Problem Language Result Execution time Memory
583955 2022-06-26T14:32:58 Z MasterTaster Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
64 / 100
3000 ms 85228 KB
#include<iostream>
#include<map>
#include<vector>
#include<stack>
#include<algorithm>
 
#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second
#define pb push_back
#define MAXN 1000005
 
using namespace std;
 
int seg[5*MAXN], n, m, a[MAXN], lg[MAXN];
vector< pair < pii, pii > > all;
vector< pair < pii, int > > order;
int ress[MAXN];
 
void build(int node, int l, int r)
{
    if (l==r) { seg[node]=-1; return; }
    int mid=l+(r-l)/2;
    build(2*node, l, mid);
    build(2*node+1, mid+1, r);
    seg[node]=max(seg[2*node], seg[2*node+1]);
}
 
void upd(int node, int l, int r, int ind, int val)
{
    if (ind>r || ind<l) return;
    if (l==r) { seg[node]=val; return; }
 
    int mid=l+(r-l)/2;
    upd(2*node, l, mid, ind, val);
    upd(2*node+1, mid+1, r, ind, val);
    seg[node]=max(seg[2*node], seg[2*node+1]);
}
 
int maxQuery(int node, int l, int r, int left, int right)
{
    if (left>r || right<l) return -1;
    if (left<=l && right>=r) return seg[node];
 
    int mid=l+(r-l)/2;
    return max(maxQuery(2*node, l, mid, left, right), maxQuery(2*node+1, mid+1, r, left, right));
}
 
int main(){
    cin>>n>>m;
 
    for (int i=1; i<=n; i++) cin>>a[i];
 
    stack<pii> st;
    st.push({1000000001, 0});
    for (int i=1; i<=n; i++)
    {
        while (st.top().xx<=a[i]) st.pop();
        lg[i]=st.top().yy;
        //cout<<i<<" "<<lg[i]<<endl;
        st.push({a[i], i});
        all.pb({{a[i]+a[lg[i]], 0}, {i, lg[i]}});
    }
 
    for (int i=0; i<m; i++)
    {
        int l, r, k; cin>>l>>r>>k;
        order.pb({{l, r}, k});
        all.pb({{k, i+1}, {l, r}});
    }
 
    sort(all.begin(), all.end(), greater< pair < pii, pii > >());
 
    int N=all.size();
    build(1, 1, N);
    for (int i=0; i<all.size(); i++)
    {
        int k=all[i].xx.xx, t=all[i].xx.yy, l=all[i].yy.xx, r=all[i].yy.yy;
        //cout<<k<<" "<<t<<" "<<l<<" "<<r<<endl;
        if (t==0)
        {
            upd(1, 1, N, l, r);
        }
        else
        {
            int x=maxQuery(1, 1, N, l, r), temp=1;
            //cout<<x<<endl;
            if (x>=l) temp=0;
            ress[t-1]=temp;
        }
    }
 
    for (int i=0; i<m; i++)
    {
        cout<<ress[i]<<endl;
    }
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:77:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     for (int i=0; i<all.size(); i++)
      |                   ~^~~~~~~~~~~
sortbooks.cpp:79:13: warning: unused variable 'k' [-Wunused-variable]
   79 |         int k=all[i].xx.xx, t=all[i].xx.yy, l=all[i].yy.xx, r=all[i].yy.yy;
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 12 ms 752 KB Output is correct
12 Correct 10 ms 724 KB Output is correct
13 Correct 15 ms 700 KB Output is correct
14 Correct 22 ms 988 KB Output is correct
15 Correct 15 ms 976 KB Output is correct
16 Correct 19 ms 948 KB Output is correct
17 Correct 16 ms 852 KB Output is correct
18 Correct 13 ms 924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3096 ms 85228 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 276 ms 9632 KB Output is correct
2 Correct 274 ms 9872 KB Output is correct
3 Correct 266 ms 9776 KB Output is correct
4 Correct 273 ms 9828 KB Output is correct
5 Correct 262 ms 9812 KB Output is correct
6 Correct 280 ms 10064 KB Output is correct
7 Correct 253 ms 9812 KB Output is correct
8 Correct 250 ms 9864 KB Output is correct
9 Correct 210 ms 5096 KB Output is correct
10 Correct 250 ms 9836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 12 ms 752 KB Output is correct
12 Correct 10 ms 724 KB Output is correct
13 Correct 15 ms 700 KB Output is correct
14 Correct 22 ms 988 KB Output is correct
15 Correct 15 ms 976 KB Output is correct
16 Correct 19 ms 948 KB Output is correct
17 Correct 16 ms 852 KB Output is correct
18 Correct 13 ms 924 KB Output is correct
19 Correct 636 ms 19040 KB Output is correct
20 Correct 633 ms 19160 KB Output is correct
21 Correct 619 ms 19040 KB Output is correct
22 Correct 626 ms 19196 KB Output is correct
23 Correct 658 ms 19064 KB Output is correct
24 Correct 619 ms 19096 KB Output is correct
25 Correct 648 ms 19108 KB Output is correct
26 Correct 700 ms 19140 KB Output is correct
27 Correct 642 ms 19084 KB Output is correct
28 Correct 690 ms 19124 KB Output is correct
29 Correct 654 ms 19136 KB Output is correct
30 Correct 631 ms 19216 KB Output is correct
31 Correct 624 ms 19280 KB Output is correct
32 Correct 612 ms 19128 KB Output is correct
33 Correct 617 ms 19128 KB Output is correct
34 Correct 586 ms 19156 KB Output is correct
35 Correct 593 ms 19156 KB Output is correct
36 Correct 584 ms 19088 KB Output is correct
37 Correct 581 ms 19152 KB Output is correct
38 Correct 578 ms 19112 KB Output is correct
39 Correct 575 ms 19168 KB Output is correct
40 Correct 523 ms 17508 KB Output is correct
41 Correct 551 ms 19152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 12 ms 752 KB Output is correct
12 Correct 10 ms 724 KB Output is correct
13 Correct 15 ms 700 KB Output is correct
14 Correct 22 ms 988 KB Output is correct
15 Correct 15 ms 976 KB Output is correct
16 Correct 19 ms 948 KB Output is correct
17 Correct 16 ms 852 KB Output is correct
18 Correct 13 ms 924 KB Output is correct
19 Execution timed out 3096 ms 85228 KB Time limit exceeded
20 Halted 0 ms 0 KB -