답안 #168564

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168564 2019-12-13T18:36:33 Z beso123 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
64 / 100
3000 ms 57296 KB
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,pair<int,pair<int,int>>>
#define x first
#define y second.first
#define z second.second.first
#define p second.second.second
using namespace std;
const int N=(1e6)+3;
int n,q,a[N],t[4*N],gr[N],ans[N];
vector<pii> Q;
stack<int> st;
void UPD(int v,int i,int j,int pos,int val){
    if(i==j && pos==i){
       t[v]=val;
       return;
    }
    int mid=(i+j)/2;
    if(pos<=mid)
        UPD(v*2,i,mid,pos,val);
    else
        UPD(v*2+1,mid+1,j,pos,val);
    t[v]=max(t[v*2],t[v*2+1]);
}
int GET(int v,int i,int j,int l,int r){
    if(l>r)
        return -LONG_LONG_MAX;
    if(i==l && j==r)
        return t[v];
    int mid=(i+j)/2;
    int g1=GET(v*2,i,mid,l,min(r,mid));
    int g2=GET(v*2+1,mid+1,j,max(mid+1,l),r);
    return max(g1,g2);
}
bool comp_sort(pii a,pii b){
    return a.y<b.y;
}
main(){
cin>>n>>q;
for(int k=1;k<=n;k++)
    cin>>a[k];
a[0]=LONG_LONG_MAX;
st.push(0);
for(int k=1;k<=n;k++){
    while(a[st.top()]<=a[k]){
        st.pop();
    }
    gr[k]=st.top();
    st.push(k);
}
for(int k=1;k<=q;k++){
   int a,b,c;
   cin>>a>>b>>c;
   Q.push_back({a,{b,{c,k}}});
}
sort(Q.begin(),Q.end(),comp_sort);
int j=0;
for(int k=1;k<=n;k++){
   if(gr[k])
    UPD(1,1,n,gr[k],a[gr[k]]+a[k]);
    while(j<Q.size() && Q[j].y==k){
        if(GET(1,1,n,Q[j].x,Q[j].y)<=Q[j].z)
            ans[Q[j].p]=1;
        j++;
    }
}
for(int k=1;k<=q;k++)
    cout<<ans[k]<<endl;
return 0;
}

Compilation message

sortbooks.cpp:38:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:59:4: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
    if(gr[k])
    ^~
sortbooks.cpp:61:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
     while(j<Q.size() && Q[j].y==k){
     ^~~~~
sortbooks.cpp:61:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(j<Q.size() && Q[j].y==k){
           ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 17 ms 760 KB Output is correct
12 Correct 18 ms 888 KB Output is correct
13 Correct 21 ms 1016 KB Output is correct
14 Correct 30 ms 1100 KB Output is correct
15 Correct 30 ms 1012 KB Output is correct
16 Correct 26 ms 888 KB Output is correct
17 Correct 25 ms 888 KB Output is correct
18 Correct 24 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3063 ms 57296 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 518 ms 8384 KB Output is correct
2 Correct 509 ms 9180 KB Output is correct
3 Correct 495 ms 7012 KB Output is correct
4 Correct 500 ms 7020 KB Output is correct
5 Correct 495 ms 7004 KB Output is correct
6 Correct 478 ms 7012 KB Output is correct
7 Correct 478 ms 6884 KB Output is correct
8 Correct 475 ms 7168 KB Output is correct
9 Correct 411 ms 5468 KB Output is correct
10 Correct 472 ms 7420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 17 ms 760 KB Output is correct
12 Correct 18 ms 888 KB Output is correct
13 Correct 21 ms 1016 KB Output is correct
14 Correct 30 ms 1100 KB Output is correct
15 Correct 30 ms 1012 KB Output is correct
16 Correct 26 ms 888 KB Output is correct
17 Correct 25 ms 888 KB Output is correct
18 Correct 24 ms 888 KB Output is correct
19 Correct 1210 ms 19536 KB Output is correct
20 Correct 1203 ms 18872 KB Output is correct
21 Correct 1176 ms 20612 KB Output is correct
22 Correct 1177 ms 20216 KB Output is correct
23 Correct 1177 ms 20560 KB Output is correct
24 Correct 1141 ms 16220 KB Output is correct
25 Correct 1135 ms 16160 KB Output is correct
26 Correct 1156 ms 16456 KB Output is correct
27 Correct 1160 ms 16208 KB Output is correct
28 Correct 1253 ms 16436 KB Output is correct
29 Correct 1156 ms 17488 KB Output is correct
30 Correct 1208 ms 18464 KB Output is correct
31 Correct 1169 ms 18476 KB Output is correct
32 Correct 1186 ms 18520 KB Output is correct
33 Correct 1182 ms 18772 KB Output is correct
34 Correct 1115 ms 18236 KB Output is correct
35 Correct 1121 ms 18372 KB Output is correct
36 Correct 1117 ms 18212 KB Output is correct
37 Correct 1112 ms 18000 KB Output is correct
38 Correct 1120 ms 18064 KB Output is correct
39 Correct 1073 ms 18564 KB Output is correct
40 Correct 984 ms 15364 KB Output is correct
41 Correct 1030 ms 16816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 17 ms 760 KB Output is correct
12 Correct 18 ms 888 KB Output is correct
13 Correct 21 ms 1016 KB Output is correct
14 Correct 30 ms 1100 KB Output is correct
15 Correct 30 ms 1012 KB Output is correct
16 Correct 26 ms 888 KB Output is correct
17 Correct 25 ms 888 KB Output is correct
18 Correct 24 ms 888 KB Output is correct
19 Execution timed out 3063 ms 57296 KB Time limit exceeded
20 Halted 0 ms 0 KB -