답안 #154109

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
154109 2019-09-18T11:19:18 Z beso123 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
64 / 100
3000 ms 84076 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+9;
int w[N], l[N], n, m,ans[N], L[N], R[N], F[N];
set<int > s;
void ad(int l, int r){
    auto it = s.lower_bound(l);
    if(it != s.end() && F[*it] <= r) return;
    while(it != s.begin() && F[*(--it)] >= r){
        s.erase(it);
        it = s.lower_bound(l);
    }
    F[l] =r;
    s.insert(l);

}
main(){
    int n;
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        scanf("%d",&w[i]);
    }

    stack<int> S;
    for(int i = 1; i <= n; i++){
        while(S.size() && w[S.top()] <= w[i]) S.pop();
        if(!S.size()) l[i] = 0;
        else l[i] = S.top();
        S.push(i);
    }
    vector<pair<int, pair<int,int> > > v;
    for(int i = 1; i <= n; i++){
        if(l[i]) v.push_back({-w[l[i]] - w[i], {l[i], i}});
    }
    sort(v.begin(), v.end());
    vector<pair<int,int> > Q;
    for(int i = 1; i <= m; i++){
        int k;
        scanf("%d%d%d", &L[i],&R[i], &k);
        Q.push_back({-k, i});
    }
    sort(Q.begin(), Q.end());
    int j = 0;
    for(int i = 0; i < Q.size(); i++){
        while(j < v.size() && v[j].first < Q[i].first){
            ad(v[j].second.first, v[j].second.second);
            j++;
        }

        int I = Q[i].second;
        int l =  L[I], r =R[I];
       auto it = s.lower_bound(l);
        if(it == s.end() || F[*it] > r) ans[I] = 1;


    }
    for(int  i = 1; i <= m; i++)
        printf("%d\n",ans[i]);

}

Compilation message

sortbooks.cpp:17:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:44:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < Q.size(); i++){
                    ~~^~~~~~~~~~
sortbooks.cpp:45:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(j < v.size() && v[j].first < Q[i].first){
               ~~^~~~~~~~~~
sortbooks.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&w[i]);
         ~~~~~^~~~~~~~~~~~
sortbooks.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &L[i],&R[i], &k);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 420 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 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 2 ms 376 KB Output is correct
4 Correct 2 ms 420 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 5 ms 608 KB Output is correct
12 Correct 7 ms 760 KB Output is correct
13 Correct 7 ms 760 KB Output is correct
14 Correct 8 ms 888 KB Output is correct
15 Correct 8 ms 888 KB Output is correct
16 Correct 6 ms 760 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 6 ms 680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3020 ms 84076 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 9356 KB Output is correct
2 Correct 146 ms 9196 KB Output is correct
3 Correct 70 ms 5456 KB Output is correct
4 Correct 71 ms 5360 KB Output is correct
5 Correct 70 ms 5356 KB Output is correct
6 Correct 63 ms 5008 KB Output is correct
7 Correct 62 ms 5032 KB Output is correct
8 Correct 74 ms 6888 KB Output is correct
9 Correct 50 ms 3956 KB Output is correct
10 Correct 74 ms 6224 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 2 ms 376 KB Output is correct
4 Correct 2 ms 420 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 5 ms 608 KB Output is correct
12 Correct 7 ms 760 KB Output is correct
13 Correct 7 ms 760 KB Output is correct
14 Correct 8 ms 888 KB Output is correct
15 Correct 8 ms 888 KB Output is correct
16 Correct 6 ms 760 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 6 ms 680 KB Output is correct
19 Correct 368 ms 20640 KB Output is correct
20 Correct 357 ms 20764 KB Output is correct
21 Correct 349 ms 19612 KB Output is correct
22 Correct 343 ms 19724 KB Output is correct
23 Correct 341 ms 19556 KB Output is correct
24 Correct 156 ms 11752 KB Output is correct
25 Correct 154 ms 11904 KB Output is correct
26 Correct 158 ms 11632 KB Output is correct
27 Correct 156 ms 11588 KB Output is correct
28 Correct 156 ms 11496 KB Output is correct
29 Correct 162 ms 11384 KB Output is correct
30 Correct 169 ms 11236 KB Output is correct
31 Correct 167 ms 11156 KB Output is correct
32 Correct 165 ms 10980 KB Output is correct
33 Correct 162 ms 11096 KB Output is correct
34 Correct 146 ms 10868 KB Output is correct
35 Correct 147 ms 10916 KB Output is correct
36 Correct 148 ms 10788 KB Output is correct
37 Correct 144 ms 10692 KB Output is correct
38 Correct 145 ms 10536 KB Output is correct
39 Correct 189 ms 13312 KB Output is correct
40 Correct 128 ms 10624 KB Output is correct
41 Correct 161 ms 12932 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 2 ms 376 KB Output is correct
4 Correct 2 ms 420 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 5 ms 608 KB Output is correct
12 Correct 7 ms 760 KB Output is correct
13 Correct 7 ms 760 KB Output is correct
14 Correct 8 ms 888 KB Output is correct
15 Correct 8 ms 888 KB Output is correct
16 Correct 6 ms 760 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 6 ms 680 KB Output is correct
19 Execution timed out 3020 ms 84076 KB Time limit exceeded
20 Halted 0 ms 0 KB -