답안 #547647

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
547647 2022-04-11T07:05:44 Z Soul234 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
865 ms 92384 KB
#include<bits/stdc++.h>
using namespace std;

void DBG() { cerr << "]\n"; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << h; if(sizeof...(t)) cerr << ", ";
    DBG(t...);
}
#ifdef LOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif // LOCAL

#define FOR(i,a,b) for(int i = (a) ; i<(b) ; i++)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for(int i = (b)-1 ; i>=(a) ; i--)
#define R0F(i,a) ROF(i,0,a)
#define each(e,a) for(auto &e : (a))
#define sz(v) (int)(v).size()
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb push_back
#define tcT template<class T
#define nl "\n"

using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
using str = string;
tcT> using V = vector<T>;
tcT> using pqg = priority_queue<T,vector<T>,greater<T>>;

void setIO(string NAME = "") {
    cin.tie(0)->sync_with_stdio(0);
    if(sz(NAME)) {
        freopen((NAME + ".inp").c_str(),"r",stdin);
        freopen((NAME + ".out").c_str(),"w",stdout);
    }
}

tcT> bool ckmax(T&a, const T&b) {
    return b > a ? a = b, 1 : 0;
}

tcT, int SZ> using AR = array<T, SZ>;
const int MX = 1e6+5;
int N, M, A[MX], ft[MX], ans[MX];
V<AR<int,3>> q[MX];

void upd(int p, int val) {
    for(;p; p-=p&-p) ckmax(ft[p], val);
}

int query(int p) {
    int res = 0;
    for(;p<=N;p+=p&-p) ckmax(res, ft[p]);
    return res;
}

void solve() {
    cin>>N>>M;
    A[0] = INT_MAX;
    FOR(i,1,N+1) cin>>A[i];
    F0R(i,M) {
        int l, r, k; cin>>l>>r>>k;
        q[r].pb({l,k,i});
    }
    stack<int> st; st.push(0);
    FOR(i,1,N+1) {
        while(A[st.top()] <= A[i]) st.pop();
        if(st.top()) upd(st.top(), A[i] + A[st.top()]);
        F0R(j,sz(q[i])) ans[q[i][j][2]] = query(q[i][j][0]) <= q[i][j][1];
        st.push(i);
    }
    F0R(i,M) cout << ans[i] << nl;
}

int main() {
    setIO();

    int t=1;
    //cin>>t;
    while(t-->0) {
        solve();
    }

    return 0;
}

Compilation message

sortbooks.cpp: In function 'void setIO(std::string)':
sortbooks.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen((NAME + ".inp").c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen((NAME + ".out").c_str(),"w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23764 KB Output is correct
2 Correct 12 ms 23700 KB Output is correct
3 Correct 12 ms 23820 KB Output is correct
4 Correct 12 ms 23784 KB Output is correct
5 Correct 12 ms 23796 KB Output is correct
6 Correct 12 ms 23764 KB Output is correct
7 Correct 13 ms 23764 KB Output is correct
8 Correct 13 ms 23816 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 12 ms 23816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23764 KB Output is correct
2 Correct 12 ms 23700 KB Output is correct
3 Correct 12 ms 23820 KB Output is correct
4 Correct 12 ms 23784 KB Output is correct
5 Correct 12 ms 23796 KB Output is correct
6 Correct 12 ms 23764 KB Output is correct
7 Correct 13 ms 23764 KB Output is correct
8 Correct 13 ms 23816 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 12 ms 23816 KB Output is correct
11 Correct 13 ms 23888 KB Output is correct
12 Correct 15 ms 24052 KB Output is correct
13 Correct 15 ms 23948 KB Output is correct
14 Correct 15 ms 24060 KB Output is correct
15 Correct 16 ms 24080 KB Output is correct
16 Correct 15 ms 24020 KB Output is correct
17 Correct 16 ms 24084 KB Output is correct
18 Correct 14 ms 23952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 854 ms 91192 KB Output is correct
2 Correct 842 ms 92152 KB Output is correct
3 Correct 818 ms 92076 KB Output is correct
4 Correct 844 ms 92180 KB Output is correct
5 Correct 817 ms 88280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 29240 KB Output is correct
2 Correct 68 ms 29000 KB Output is correct
3 Correct 62 ms 28808 KB Output is correct
4 Correct 66 ms 28748 KB Output is correct
5 Correct 64 ms 28896 KB Output is correct
6 Correct 54 ms 28276 KB Output is correct
7 Correct 53 ms 28268 KB Output is correct
8 Correct 58 ms 28372 KB Output is correct
9 Correct 44 ms 27276 KB Output is correct
10 Correct 74 ms 28372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23764 KB Output is correct
2 Correct 12 ms 23700 KB Output is correct
3 Correct 12 ms 23820 KB Output is correct
4 Correct 12 ms 23784 KB Output is correct
5 Correct 12 ms 23796 KB Output is correct
6 Correct 12 ms 23764 KB Output is correct
7 Correct 13 ms 23764 KB Output is correct
8 Correct 13 ms 23816 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 12 ms 23816 KB Output is correct
11 Correct 13 ms 23888 KB Output is correct
12 Correct 15 ms 24052 KB Output is correct
13 Correct 15 ms 23948 KB Output is correct
14 Correct 15 ms 24060 KB Output is correct
15 Correct 16 ms 24080 KB Output is correct
16 Correct 15 ms 24020 KB Output is correct
17 Correct 16 ms 24084 KB Output is correct
18 Correct 14 ms 23952 KB Output is correct
19 Correct 145 ms 37340 KB Output is correct
20 Correct 160 ms 37380 KB Output is correct
21 Correct 141 ms 36712 KB Output is correct
22 Correct 125 ms 36744 KB Output is correct
23 Correct 132 ms 36720 KB Output is correct
24 Correct 124 ms 35788 KB Output is correct
25 Correct 120 ms 35924 KB Output is correct
26 Correct 139 ms 36152 KB Output is correct
27 Correct 139 ms 36148 KB Output is correct
28 Correct 137 ms 36232 KB Output is correct
29 Correct 146 ms 36616 KB Output is correct
30 Correct 142 ms 36556 KB Output is correct
31 Correct 134 ms 36512 KB Output is correct
32 Correct 137 ms 36560 KB Output is correct
33 Correct 140 ms 36572 KB Output is correct
34 Correct 117 ms 35340 KB Output is correct
35 Correct 120 ms 35276 KB Output is correct
36 Correct 114 ms 35148 KB Output is correct
37 Correct 113 ms 35084 KB Output is correct
38 Correct 117 ms 35364 KB Output is correct
39 Correct 129 ms 35004 KB Output is correct
40 Correct 115 ms 33448 KB Output is correct
41 Correct 127 ms 34412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23764 KB Output is correct
2 Correct 12 ms 23700 KB Output is correct
3 Correct 12 ms 23820 KB Output is correct
4 Correct 12 ms 23784 KB Output is correct
5 Correct 12 ms 23796 KB Output is correct
6 Correct 12 ms 23764 KB Output is correct
7 Correct 13 ms 23764 KB Output is correct
8 Correct 13 ms 23816 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 12 ms 23816 KB Output is correct
11 Correct 13 ms 23888 KB Output is correct
12 Correct 15 ms 24052 KB Output is correct
13 Correct 15 ms 23948 KB Output is correct
14 Correct 15 ms 24060 KB Output is correct
15 Correct 16 ms 24080 KB Output is correct
16 Correct 15 ms 24020 KB Output is correct
17 Correct 16 ms 24084 KB Output is correct
18 Correct 14 ms 23952 KB Output is correct
19 Correct 854 ms 91192 KB Output is correct
20 Correct 842 ms 92152 KB Output is correct
21 Correct 818 ms 92076 KB Output is correct
22 Correct 844 ms 92180 KB Output is correct
23 Correct 817 ms 88280 KB Output is correct
24 Correct 76 ms 29240 KB Output is correct
25 Correct 68 ms 29000 KB Output is correct
26 Correct 62 ms 28808 KB Output is correct
27 Correct 66 ms 28748 KB Output is correct
28 Correct 64 ms 28896 KB Output is correct
29 Correct 54 ms 28276 KB Output is correct
30 Correct 53 ms 28268 KB Output is correct
31 Correct 58 ms 28372 KB Output is correct
32 Correct 44 ms 27276 KB Output is correct
33 Correct 74 ms 28372 KB Output is correct
34 Correct 145 ms 37340 KB Output is correct
35 Correct 160 ms 37380 KB Output is correct
36 Correct 141 ms 36712 KB Output is correct
37 Correct 125 ms 36744 KB Output is correct
38 Correct 132 ms 36720 KB Output is correct
39 Correct 124 ms 35788 KB Output is correct
40 Correct 120 ms 35924 KB Output is correct
41 Correct 139 ms 36152 KB Output is correct
42 Correct 139 ms 36148 KB Output is correct
43 Correct 137 ms 36232 KB Output is correct
44 Correct 146 ms 36616 KB Output is correct
45 Correct 142 ms 36556 KB Output is correct
46 Correct 134 ms 36512 KB Output is correct
47 Correct 137 ms 36560 KB Output is correct
48 Correct 140 ms 36572 KB Output is correct
49 Correct 117 ms 35340 KB Output is correct
50 Correct 120 ms 35276 KB Output is correct
51 Correct 114 ms 35148 KB Output is correct
52 Correct 113 ms 35084 KB Output is correct
53 Correct 117 ms 35364 KB Output is correct
54 Correct 129 ms 35004 KB Output is correct
55 Correct 115 ms 33448 KB Output is correct
56 Correct 127 ms 34412 KB Output is correct
57 Correct 865 ms 92384 KB Output is correct
58 Correct 836 ms 92224 KB Output is correct
59 Correct 789 ms 90776 KB Output is correct
60 Correct 817 ms 90900 KB Output is correct
61 Correct 807 ms 90680 KB Output is correct
62 Correct 809 ms 90740 KB Output is correct
63 Correct 576 ms 83444 KB Output is correct
64 Correct 544 ms 83272 KB Output is correct
65 Correct 747 ms 86776 KB Output is correct
66 Correct 742 ms 86456 KB Output is correct
67 Correct 774 ms 86592 KB Output is correct
68 Correct 811 ms 88336 KB Output is correct
69 Correct 801 ms 88252 KB Output is correct
70 Correct 800 ms 87904 KB Output is correct
71 Correct 803 ms 87920 KB Output is correct
72 Correct 831 ms 87852 KB Output is correct
73 Correct 567 ms 79356 KB Output is correct
74 Correct 526 ms 80240 KB Output is correct
75 Correct 541 ms 79556 KB Output is correct
76 Correct 520 ms 79684 KB Output is correct
77 Correct 500 ms 79256 KB Output is correct
78 Correct 717 ms 81372 KB Output is correct
79 Correct 563 ms 71600 KB Output is correct
80 Correct 688 ms 77712 KB Output is correct