답안 #573434

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
573434 2022-06-06T15:27:29 Z MohammadAghil Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1307 ms 73764 KB
      #include <bits/stdc++.h>
//   #pragma GCC optimize ("Ofast,unroll-loops")
#pragma GCC target ("avx2")
    using namespace std;
  typedef long long ll;
   typedef pair<int, int> pp;
    #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
      #define per(i,r,l) for(int i = (r); i >= (l); i--)
        #define rep(i,l,r) for(int i = (l); i < (r); i++)
           #define all(x) x.begin(), x.end()
              #define sz(x) (int)(x).size()
                  #define pb push_back
                      #define ss second
                           #define ff first
                                   void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 1e6 + 5, lg = 22, lng = 26, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}

int seg[maxn<<2], n;
int upd(int i, int k, int x = 1, int lx = 0, int rx = n){
     if(lx + 1 == rx) return seg[x] = max(seg[x], k);
     int mid = (lx + rx)>>1;
     if(i < mid) upd(i, k, x<<1, lx, mid);
     else upd(i, k, x<<1|1, mid, rx);
     return seg[x] = max(seg[x<<1], seg[x<<1|1]);
}
int get(int l, int r, int x = 1, int lx = 0, int rx = n){
     if(l <= lx && r >= rx) return seg[x];
     if(l >= rx || r <= lx) return -1;
     int mid = (lx + rx)>>1;
     return max(get(l, r, x<<1, lx, mid), get(l, r, x<<1|1, mid, rx));
}

int main(){
     cin.tie(0) -> sync_with_stdio(0);
     int q; cin >> n >> q;
     vector<int> w(n);
     rep(i,0,n){
          cin >> w[i];
     }
     struct tr{
          int r, id, k;
     };
     vector<vector<tr>> query(n);
     rep(i,0,q){
          int l, r, k; cin >> l >> r >> k; l--;
          query[l].pb({r, i, k});
     }
     fill(seg, seg+(n<<2), -1);
     vector<int> st;
     vector<bool> ans(q);
     per(i,n-1,0){
          while(sz(st) && w[st.back()] < w[i]){
               upd(st.back(), w[st.back()] + w[i]);
               st.pop_back();
          }
          st.pb(i);
          for(auto[r, id, k]: query[i]){
               ans[id] = get(i, r) <= k;
          }
     }
     for(auto c: ans) cout << c << '\n';
     return 0; 
}

/*
5 2
3 5 1 8 2
1 3 6
2 5 3
*/

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:59:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   59 |           for(auto[r, id, k]: query[i]){
      |                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 5 ms 812 KB Output is correct
15 Correct 6 ms 732 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 4 ms 724 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1307 ms 69712 KB Output is correct
2 Correct 1237 ms 69708 KB Output is correct
3 Correct 1249 ms 69500 KB Output is correct
4 Correct 1232 ms 69556 KB Output is correct
5 Correct 1106 ms 73764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 9036 KB Output is correct
2 Correct 80 ms 8784 KB Output is correct
3 Correct 81 ms 9516 KB Output is correct
4 Correct 79 ms 9680 KB Output is correct
5 Correct 78 ms 9588 KB Output is correct
6 Correct 64 ms 8804 KB Output is correct
7 Correct 64 ms 8780 KB Output is correct
8 Correct 69 ms 8660 KB Output is correct
9 Correct 35 ms 3364 KB Output is correct
10 Correct 72 ms 8724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 5 ms 812 KB Output is correct
15 Correct 6 ms 732 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 4 ms 724 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
19 Correct 206 ms 16320 KB Output is correct
20 Correct 214 ms 16280 KB Output is correct
21 Correct 179 ms 15740 KB Output is correct
22 Correct 191 ms 15728 KB Output is correct
23 Correct 187 ms 15784 KB Output is correct
24 Correct 155 ms 16596 KB Output is correct
25 Correct 154 ms 16580 KB Output is correct
26 Correct 165 ms 16544 KB Output is correct
27 Correct 171 ms 16504 KB Output is correct
28 Correct 180 ms 16332 KB Output is correct
29 Correct 186 ms 16752 KB Output is correct
30 Correct 182 ms 16816 KB Output is correct
31 Correct 182 ms 16584 KB Output is correct
32 Correct 183 ms 16432 KB Output is correct
33 Correct 186 ms 16444 KB Output is correct
34 Correct 147 ms 15428 KB Output is correct
35 Correct 144 ms 15332 KB Output is correct
36 Correct 140 ms 15172 KB Output is correct
37 Correct 136 ms 15148 KB Output is correct
38 Correct 148 ms 15200 KB Output is correct
39 Correct 165 ms 15680 KB Output is correct
40 Correct 121 ms 12016 KB Output is correct
41 Correct 161 ms 15232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 5 ms 812 KB Output is correct
15 Correct 6 ms 732 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 4 ms 724 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
19 Correct 1307 ms 69712 KB Output is correct
20 Correct 1237 ms 69708 KB Output is correct
21 Correct 1249 ms 69500 KB Output is correct
22 Correct 1232 ms 69556 KB Output is correct
23 Correct 1106 ms 73764 KB Output is correct
24 Correct 89 ms 9036 KB Output is correct
25 Correct 80 ms 8784 KB Output is correct
26 Correct 81 ms 9516 KB Output is correct
27 Correct 79 ms 9680 KB Output is correct
28 Correct 78 ms 9588 KB Output is correct
29 Correct 64 ms 8804 KB Output is correct
30 Correct 64 ms 8780 KB Output is correct
31 Correct 69 ms 8660 KB Output is correct
32 Correct 35 ms 3364 KB Output is correct
33 Correct 72 ms 8724 KB Output is correct
34 Correct 206 ms 16320 KB Output is correct
35 Correct 214 ms 16280 KB Output is correct
36 Correct 179 ms 15740 KB Output is correct
37 Correct 191 ms 15728 KB Output is correct
38 Correct 187 ms 15784 KB Output is correct
39 Correct 155 ms 16596 KB Output is correct
40 Correct 154 ms 16580 KB Output is correct
41 Correct 165 ms 16544 KB Output is correct
42 Correct 171 ms 16504 KB Output is correct
43 Correct 180 ms 16332 KB Output is correct
44 Correct 186 ms 16752 KB Output is correct
45 Correct 182 ms 16816 KB Output is correct
46 Correct 182 ms 16584 KB Output is correct
47 Correct 183 ms 16432 KB Output is correct
48 Correct 186 ms 16444 KB Output is correct
49 Correct 147 ms 15428 KB Output is correct
50 Correct 144 ms 15332 KB Output is correct
51 Correct 140 ms 15172 KB Output is correct
52 Correct 136 ms 15148 KB Output is correct
53 Correct 148 ms 15200 KB Output is correct
54 Correct 165 ms 15680 KB Output is correct
55 Correct 121 ms 12016 KB Output is correct
56 Correct 161 ms 15232 KB Output is correct
57 Correct 1259 ms 69076 KB Output is correct
58 Correct 1252 ms 68880 KB Output is correct
59 Correct 1172 ms 66892 KB Output is correct
60 Correct 1171 ms 66696 KB Output is correct
61 Correct 1170 ms 66716 KB Output is correct
62 Correct 1157 ms 66788 KB Output is correct
63 Correct 751 ms 66996 KB Output is correct
64 Correct 765 ms 66756 KB Output is correct
65 Correct 1033 ms 70344 KB Output is correct
66 Correct 1020 ms 70360 KB Output is correct
67 Correct 1052 ms 70532 KB Output is correct
68 Correct 1109 ms 72692 KB Output is correct
69 Correct 1114 ms 72384 KB Output is correct
70 Correct 1104 ms 71992 KB Output is correct
71 Correct 1119 ms 72008 KB Output is correct
72 Correct 1105 ms 71876 KB Output is correct
73 Correct 740 ms 65644 KB Output is correct
74 Correct 745 ms 65672 KB Output is correct
75 Correct 712 ms 65568 KB Output is correct
76 Correct 699 ms 65648 KB Output is correct
77 Correct 690 ms 65716 KB Output is correct
78 Correct 915 ms 69068 KB Output is correct
79 Correct 654 ms 45356 KB Output is correct
80 Correct 931 ms 67928 KB Output is correct