답안 #587167

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587167 2022-07-01T12:20:04 Z MasterTaster Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
3000 ms 105924 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[4*MAXN], n, m, a[MAXN], lg[MAXN];
vector< pair < pii, pii > > all;
vector< pair < pii, int > > order;
bool ress[MAXN];
 
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 0;
    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});
        if (lg[i]!=0) 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 > >());
 
    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:67: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]
   67 |     for (int i=0; i<all.size(); i++)
      |                   ~^~~~~~~~~~~
sortbooks.cpp:69:13: warning: unused variable 'k' [-Wunused-variable]
   69 |         int k=all[i].xx.xx, t=all[i].xx.yy, l=all[i].yy.xx, r=all[i].yy.yy;
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 316 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 320 KB Output is correct
10 Correct 2 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 316 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 320 KB Output is correct
10 Correct 2 ms 320 KB Output is correct
11 Correct 8 ms 688 KB Output is correct
12 Correct 9 ms 724 KB Output is correct
13 Correct 13 ms 724 KB Output is correct
14 Correct 15 ms 852 KB Output is correct
15 Correct 15 ms 908 KB Output is correct
16 Correct 12 ms 692 KB Output is correct
17 Correct 12 ms 724 KB Output is correct
18 Correct 13 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3093 ms 105924 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 297 ms 10284 KB Output is correct
2 Correct 276 ms 10344 KB Output is correct
3 Correct 295 ms 6248 KB Output is correct
4 Correct 252 ms 6212 KB Output is correct
5 Correct 262 ms 6236 KB Output is correct
6 Correct 236 ms 6624 KB Output is correct
7 Correct 247 ms 6660 KB Output is correct
8 Correct 246 ms 9220 KB Output is correct
9 Correct 204 ms 4864 KB Output is correct
10 Correct 282 ms 9128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 316 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 320 KB Output is correct
10 Correct 2 ms 320 KB Output is correct
11 Correct 8 ms 688 KB Output is correct
12 Correct 9 ms 724 KB Output is correct
13 Correct 13 ms 724 KB Output is correct
14 Correct 15 ms 852 KB Output is correct
15 Correct 15 ms 908 KB Output is correct
16 Correct 12 ms 692 KB Output is correct
17 Correct 12 ms 724 KB Output is correct
18 Correct 13 ms 852 KB Output is correct
19 Correct 654 ms 22868 KB Output is correct
20 Correct 716 ms 22784 KB Output is correct
21 Correct 640 ms 22840 KB Output is correct
22 Correct 665 ms 22664 KB Output is correct
23 Correct 671 ms 22644 KB Output is correct
24 Correct 630 ms 14432 KB Output is correct
25 Correct 566 ms 14328 KB Output is correct
26 Correct 576 ms 14600 KB Output is correct
27 Correct 566 ms 14524 KB Output is correct
28 Correct 579 ms 14640 KB Output is correct
29 Correct 588 ms 14780 KB Output is correct
30 Correct 581 ms 14716 KB Output is correct
31 Correct 592 ms 14696 KB Output is correct
32 Correct 613 ms 14600 KB Output is correct
33 Correct 612 ms 14692 KB Output is correct
34 Correct 544 ms 14464 KB Output is correct
35 Correct 557 ms 14336 KB Output is correct
36 Correct 538 ms 14260 KB Output is correct
37 Correct 568 ms 14176 KB Output is correct
38 Correct 545 ms 14424 KB Output is correct
39 Correct 574 ms 20596 KB Output is correct
40 Correct 479 ms 13432 KB Output is correct
41 Correct 524 ms 18752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 316 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 320 KB Output is correct
10 Correct 2 ms 320 KB Output is correct
11 Correct 8 ms 688 KB Output is correct
12 Correct 9 ms 724 KB Output is correct
13 Correct 13 ms 724 KB Output is correct
14 Correct 15 ms 852 KB Output is correct
15 Correct 15 ms 908 KB Output is correct
16 Correct 12 ms 692 KB Output is correct
17 Correct 12 ms 724 KB Output is correct
18 Correct 13 ms 852 KB Output is correct
19 Execution timed out 3093 ms 105924 KB Time limit exceeded
20 Halted 0 ms 0 KB -