답안 #533117

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
533117 2022-03-04T21:34:55 Z iliccmarko Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
64 / 100
3000 ms 73924 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define INF 1000000000
#define LINF 10000000000000000LL
#define pb push_back
#define all(x) x.begin(), x.end()
#define len(s) (int)s.size()
#define test_case { int t; cin>>t; while(t--)solve(); }
#define single_case solve();
#define line cerr<<"----------"<<endl;
#define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);  }
#define mod 1000000007LL
const int N = 1e6 + 5;
int seg[4*N];
int a[N], n, m;
int k[N];
int l[N], r[N];
int ans[N];
vector<int> upit[N];
stack<pair<int, int> > s;
pair<int, int> veci[N];
 
void update(int node, int l, int r, int pos, int x)
{
    if(l==r)
    {
        seg[node] = max(seg[node], x);
        return;
    }
    int mid = (l+r)/2;
    if(pos>mid) update(node*2+2, mid+1, r, pos, x);
    else update(node*2+1, l, mid, pos, x);
    seg[node] = max(seg[node*2+1], seg[node*2+2]);
}
 
int get(int node, int l, int r, int i, int j)
{
    if(i>r||j<l) return 0;
    if(i>=l&&j<=r) return seg[node];
    int mid = (i+j)/2;
    return max(get(node*2+1, l, r, i, mid), get(node*2+2, l, r, mid+1, j));
}
 
 
int main()
{
    cin>>n>>m;
    for(int i = 1;i<=n;i++) cin>>a[i];
    for(int i = 1;i<=m;i++) cin>>l[i]>>r[i]>>k[i], upit[r[i]].pb(i);
    s.push(make_pair(INF+2, 0));
    for(int i = 1;i<=n;i++)
    {
        while(a[i]>=s.top().first)
        {
            s.pop();
        }
        veci[i] = s.top();
        s.push(make_pair(a[i], i));
    }
    for(int i = 1;i<=n;i++)
    {
        if(veci[i].first!=INF+2)
        {
            update(0, 1, n, veci[i].second, veci[i].first+a[i]);
        }
        for(int x : upit[i])
        {
            int le = l[x];
            int ri = r[x];
            int w = get(0, le, ri, 1, n);
            cerr<<x<<' '<<len(upit[i]);
            if(w<=k[x]) ans[x] = 1;
        }
    }
 
    for(int i = 1;i<=m;i++) cout<<ans[i]<<endl;
 
 
 
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 12 ms 23788 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 13 ms 23728 KB Output is correct
5 Correct 13 ms 23756 KB Output is correct
6 Correct 15 ms 23880 KB Output is correct
7 Correct 15 ms 23796 KB Output is correct
8 Correct 15 ms 23776 KB Output is correct
9 Correct 15 ms 23776 KB Output is correct
10 Correct 18 ms 23796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 12 ms 23788 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 13 ms 23728 KB Output is correct
5 Correct 13 ms 23756 KB Output is correct
6 Correct 15 ms 23880 KB Output is correct
7 Correct 15 ms 23796 KB Output is correct
8 Correct 15 ms 23776 KB Output is correct
9 Correct 15 ms 23776 KB Output is correct
10 Correct 18 ms 23796 KB Output is correct
11 Correct 27 ms 24024 KB Output is correct
12 Correct 26 ms 24148 KB Output is correct
13 Correct 30 ms 24176 KB Output is correct
14 Correct 37 ms 24280 KB Output is correct
15 Correct 51 ms 24228 KB Output is correct
16 Correct 49 ms 24184 KB Output is correct
17 Correct 39 ms 24108 KB Output is correct
18 Correct 34 ms 24140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3044 ms 73924 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 552 ms 31980 KB Output is correct
2 Correct 503 ms 31276 KB Output is correct
3 Correct 508 ms 30820 KB Output is correct
4 Correct 585 ms 31136 KB Output is correct
5 Correct 502 ms 30980 KB Output is correct
6 Correct 515 ms 29552 KB Output is correct
7 Correct 576 ms 29604 KB Output is correct
8 Correct 477 ms 30720 KB Output is correct
9 Correct 479 ms 28300 KB Output is correct
10 Correct 477 ms 30708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 12 ms 23788 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 13 ms 23728 KB Output is correct
5 Correct 13 ms 23756 KB Output is correct
6 Correct 15 ms 23880 KB Output is correct
7 Correct 15 ms 23796 KB Output is correct
8 Correct 15 ms 23776 KB Output is correct
9 Correct 15 ms 23776 KB Output is correct
10 Correct 18 ms 23796 KB Output is correct
11 Correct 27 ms 24024 KB Output is correct
12 Correct 26 ms 24148 KB Output is correct
13 Correct 30 ms 24176 KB Output is correct
14 Correct 37 ms 24280 KB Output is correct
15 Correct 51 ms 24228 KB Output is correct
16 Correct 49 ms 24184 KB Output is correct
17 Correct 39 ms 24108 KB Output is correct
18 Correct 34 ms 24140 KB Output is correct
19 Correct 1172 ms 42984 KB Output is correct
20 Correct 1115 ms 43028 KB Output is correct
21 Correct 1131 ms 41284 KB Output is correct
22 Correct 1109 ms 41424 KB Output is correct
23 Correct 1110 ms 41360 KB Output is correct
24 Correct 1059 ms 39024 KB Output is correct
25 Correct 1066 ms 39068 KB Output is correct
26 Correct 1086 ms 39828 KB Output is correct
27 Correct 1074 ms 39944 KB Output is correct
28 Correct 1156 ms 40208 KB Output is correct
29 Correct 1129 ms 40984 KB Output is correct
30 Correct 1181 ms 40976 KB Output is correct
31 Correct 1084 ms 40924 KB Output is correct
32 Correct 1135 ms 41008 KB Output is correct
33 Correct 1213 ms 40900 KB Output is correct
34 Correct 1073 ms 38984 KB Output is correct
35 Correct 1085 ms 38904 KB Output is correct
36 Correct 1101 ms 38760 KB Output is correct
37 Correct 1058 ms 38788 KB Output is correct
38 Correct 1086 ms 38892 KB Output is correct
39 Correct 1101 ms 40132 KB Output is correct
40 Correct 994 ms 37940 KB Output is correct
41 Correct 1073 ms 39300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 12 ms 23788 KB Output is correct
3 Correct 13 ms 23756 KB Output is correct
4 Correct 13 ms 23728 KB Output is correct
5 Correct 13 ms 23756 KB Output is correct
6 Correct 15 ms 23880 KB Output is correct
7 Correct 15 ms 23796 KB Output is correct
8 Correct 15 ms 23776 KB Output is correct
9 Correct 15 ms 23776 KB Output is correct
10 Correct 18 ms 23796 KB Output is correct
11 Correct 27 ms 24024 KB Output is correct
12 Correct 26 ms 24148 KB Output is correct
13 Correct 30 ms 24176 KB Output is correct
14 Correct 37 ms 24280 KB Output is correct
15 Correct 51 ms 24228 KB Output is correct
16 Correct 49 ms 24184 KB Output is correct
17 Correct 39 ms 24108 KB Output is correct
18 Correct 34 ms 24140 KB Output is correct
19 Execution timed out 3044 ms 73924 KB Time limit exceeded
20 Halted 0 ms 0 KB -