답안 #396802

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
396802 2021-04-30T18:48:33 Z SavicS Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
2534 ms 104924 KB
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1000005;
const int inf = 1e9 + 5;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k)  print the k-th smallest number in os(0-based)

int n, q;
int niz[maxn];

vector<array<int,3>> upit[maxn];

int res[maxn];

ll bor[4 * maxn];
ll lenj[4 * maxn];
void propagate(int v, int tl, int tr) {
    if(lenj[v]) {
        bor[v] += lenj[v];
        if(tl != tr) {
            lenj[v * 2] += lenj[v];
            lenj[v * 2 + 1] += lenj[v];
        }
        lenj[v] = 0;
    }
}

void lazyupd(int v, int tl, int tr, int l, int r, ll val) {
    propagate(v, tl, tr);
    if(tl > tr || l > tr || tl > r)return;
    if(tl >= l && tr <= r) {
        bor[v] += val;
        if(tl != tr) {
            lenj[v * 2] += val;
            lenj[v * 2 + 1] += val;
        }
        return;
    }
    int mid = (tl + tr) / 2;
    lazyupd(v * 2, tl, mid, l, r, val);
    lazyupd(v * 2 + 1, mid + 1, tr, l, r, val);
    bor[v] = max(bor[v * 2], bor[v * 2 + 1]);
}

ll kveri(int v, int tl, int tr, int l, int r) {
    propagate(v, tl, tr);
    if(tl > r || l > tr)return 0;
    if(tl >= l && tr <= r)return bor[v];
    int mid = (tl + tr) / 2;
    return max(kveri(v * 2, tl, mid, l, r), kveri(v * 2 + 1, mid + 1, tr, l, r));
}

int main() 
{
    ios::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);
    cin >> n >> q;
    ff(i,1,n)cin >> niz[i];
    ff(i,1,q) {
        int L, R, K;
        cin >> L >> R >> K;
        upit[L].pb({R, K, i});
    }

    stack<int> stek;
    fb(i,n,1) {

        while(!stek.empty() && niz[stek.top()] < niz[i]) {
            int vrh = stek.top();
            stek.pop();

            lazyupd(1,1,n,vrh + 1, (sz(stek) == 0 ? n : stek.top() - 1), niz[i] - niz[vrh]);
            lazyupd(1,1,n,vrh,vrh,niz[i] + niz[vrh]);

        }
        stek.push(i);

        for(auto c : upit[i]) {
            int R = c[0];
            int K = c[1];
            int id = c[2];
            res[id] = (kveri(1,1,n,i,R) <= K);
        }


    }

    ff(i,1,q)cout << res[i] << '\n';

    return 0;
}
/**

5 2
3 5 1 8 2
1 3 6
2 5 3

// probati bojenje sahovski ili slicno

**/


# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23756 KB Output is correct
2 Correct 15 ms 23756 KB Output is correct
3 Correct 15 ms 23756 KB Output is correct
4 Correct 15 ms 23756 KB Output is correct
5 Correct 16 ms 23804 KB Output is correct
6 Correct 16 ms 23864 KB Output is correct
7 Correct 16 ms 23756 KB Output is correct
8 Correct 15 ms 23824 KB Output is correct
9 Correct 16 ms 23756 KB Output is correct
10 Correct 15 ms 23756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23756 KB Output is correct
2 Correct 15 ms 23756 KB Output is correct
3 Correct 15 ms 23756 KB Output is correct
4 Correct 15 ms 23756 KB Output is correct
5 Correct 16 ms 23804 KB Output is correct
6 Correct 16 ms 23864 KB Output is correct
7 Correct 16 ms 23756 KB Output is correct
8 Correct 15 ms 23824 KB Output is correct
9 Correct 16 ms 23756 KB Output is correct
10 Correct 15 ms 23756 KB Output is correct
11 Correct 17 ms 23932 KB Output is correct
12 Correct 19 ms 24240 KB Output is correct
13 Correct 20 ms 24268 KB Output is correct
14 Correct 22 ms 24332 KB Output is correct
15 Correct 22 ms 24380 KB Output is correct
16 Correct 20 ms 24140 KB Output is correct
17 Correct 19 ms 24120 KB Output is correct
18 Correct 20 ms 24140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2459 ms 99012 KB Output is correct
2 Correct 2534 ms 103644 KB Output is correct
3 Correct 2483 ms 103692 KB Output is correct
4 Correct 2475 ms 103844 KB Output is correct
5 Correct 1498 ms 75080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 186 ms 33120 KB Output is correct
2 Correct 170 ms 32996 KB Output is correct
3 Correct 118 ms 29264 KB Output is correct
4 Correct 117 ms 29324 KB Output is correct
5 Correct 123 ms 29448 KB Output is correct
6 Correct 101 ms 28872 KB Output is correct
7 Correct 99 ms 28752 KB Output is correct
8 Correct 135 ms 30584 KB Output is correct
9 Correct 59 ms 27136 KB Output is correct
10 Correct 125 ms 29836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23756 KB Output is correct
2 Correct 15 ms 23756 KB Output is correct
3 Correct 15 ms 23756 KB Output is correct
4 Correct 15 ms 23756 KB Output is correct
5 Correct 16 ms 23804 KB Output is correct
6 Correct 16 ms 23864 KB Output is correct
7 Correct 16 ms 23756 KB Output is correct
8 Correct 15 ms 23824 KB Output is correct
9 Correct 16 ms 23756 KB Output is correct
10 Correct 15 ms 23756 KB Output is correct
11 Correct 17 ms 23932 KB Output is correct
12 Correct 19 ms 24240 KB Output is correct
13 Correct 20 ms 24268 KB Output is correct
14 Correct 22 ms 24332 KB Output is correct
15 Correct 22 ms 24380 KB Output is correct
16 Correct 20 ms 24140 KB Output is correct
17 Correct 19 ms 24120 KB Output is correct
18 Correct 20 ms 24140 KB Output is correct
19 Correct 417 ms 45072 KB Output is correct
20 Correct 412 ms 45120 KB Output is correct
21 Correct 353 ms 44392 KB Output is correct
22 Correct 346 ms 44388 KB Output is correct
23 Correct 346 ms 44392 KB Output is correct
24 Correct 220 ms 36804 KB Output is correct
25 Correct 217 ms 36892 KB Output is correct
26 Correct 251 ms 37312 KB Output is correct
27 Correct 245 ms 37240 KB Output is correct
28 Correct 253 ms 37148 KB Output is correct
29 Correct 273 ms 37576 KB Output is correct
30 Correct 265 ms 37660 KB Output is correct
31 Correct 266 ms 37532 KB Output is correct
32 Correct 281 ms 37572 KB Output is correct
33 Correct 262 ms 37568 KB Output is correct
34 Correct 203 ms 35996 KB Output is correct
35 Correct 204 ms 35952 KB Output is correct
36 Correct 204 ms 35768 KB Output is correct
37 Correct 197 ms 35652 KB Output is correct
38 Correct 202 ms 35908 KB Output is correct
39 Correct 263 ms 38108 KB Output is correct
40 Correct 186 ms 34296 KB Output is correct
41 Correct 271 ms 37768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23756 KB Output is correct
2 Correct 15 ms 23756 KB Output is correct
3 Correct 15 ms 23756 KB Output is correct
4 Correct 15 ms 23756 KB Output is correct
5 Correct 16 ms 23804 KB Output is correct
6 Correct 16 ms 23864 KB Output is correct
7 Correct 16 ms 23756 KB Output is correct
8 Correct 15 ms 23824 KB Output is correct
9 Correct 16 ms 23756 KB Output is correct
10 Correct 15 ms 23756 KB Output is correct
11 Correct 17 ms 23932 KB Output is correct
12 Correct 19 ms 24240 KB Output is correct
13 Correct 20 ms 24268 KB Output is correct
14 Correct 22 ms 24332 KB Output is correct
15 Correct 22 ms 24380 KB Output is correct
16 Correct 20 ms 24140 KB Output is correct
17 Correct 19 ms 24120 KB Output is correct
18 Correct 20 ms 24140 KB Output is correct
19 Correct 2459 ms 99012 KB Output is correct
20 Correct 2534 ms 103644 KB Output is correct
21 Correct 2483 ms 103692 KB Output is correct
22 Correct 2475 ms 103844 KB Output is correct
23 Correct 1498 ms 75080 KB Output is correct
24 Correct 186 ms 33120 KB Output is correct
25 Correct 170 ms 32996 KB Output is correct
26 Correct 118 ms 29264 KB Output is correct
27 Correct 117 ms 29324 KB Output is correct
28 Correct 123 ms 29448 KB Output is correct
29 Correct 101 ms 28872 KB Output is correct
30 Correct 99 ms 28752 KB Output is correct
31 Correct 135 ms 30584 KB Output is correct
32 Correct 59 ms 27136 KB Output is correct
33 Correct 125 ms 29836 KB Output is correct
34 Correct 417 ms 45072 KB Output is correct
35 Correct 412 ms 45120 KB Output is correct
36 Correct 353 ms 44392 KB Output is correct
37 Correct 346 ms 44388 KB Output is correct
38 Correct 346 ms 44392 KB Output is correct
39 Correct 220 ms 36804 KB Output is correct
40 Correct 217 ms 36892 KB Output is correct
41 Correct 251 ms 37312 KB Output is correct
42 Correct 245 ms 37240 KB Output is correct
43 Correct 253 ms 37148 KB Output is correct
44 Correct 273 ms 37576 KB Output is correct
45 Correct 265 ms 37660 KB Output is correct
46 Correct 266 ms 37532 KB Output is correct
47 Correct 281 ms 37572 KB Output is correct
48 Correct 262 ms 37568 KB Output is correct
49 Correct 203 ms 35996 KB Output is correct
50 Correct 204 ms 35952 KB Output is correct
51 Correct 204 ms 35768 KB Output is correct
52 Correct 197 ms 35652 KB Output is correct
53 Correct 202 ms 35908 KB Output is correct
54 Correct 263 ms 38108 KB Output is correct
55 Correct 186 ms 34296 KB Output is correct
56 Correct 271 ms 37768 KB Output is correct
57 Correct 2464 ms 104912 KB Output is correct
58 Correct 2461 ms 104924 KB Output is correct
59 Correct 2327 ms 102920 KB Output is correct
60 Correct 2280 ms 103032 KB Output is correct
61 Correct 2282 ms 102884 KB Output is correct
62 Correct 2285 ms 102852 KB Output is correct
63 Correct 1108 ms 64388 KB Output is correct
64 Correct 1121 ms 64316 KB Output is correct
65 Correct 1442 ms 64324 KB Output is correct
66 Correct 1443 ms 59076 KB Output is correct
67 Correct 1438 ms 59220 KB Output is correct
68 Correct 1516 ms 61156 KB Output is correct
69 Correct 1490 ms 60820 KB Output is correct
70 Correct 1478 ms 60364 KB Output is correct
71 Correct 1487 ms 60284 KB Output is correct
72 Correct 1476 ms 60356 KB Output is correct
73 Correct 961 ms 62564 KB Output is correct
74 Correct 1006 ms 73108 KB Output is correct
75 Correct 965 ms 62240 KB Output is correct
76 Correct 961 ms 51824 KB Output is correct
77 Correct 971 ms 52020 KB Output is correct
78 Correct 1444 ms 79568 KB Output is correct
79 Correct 956 ms 52624 KB Output is correct
80 Correct 1641 ms 69856 KB Output is correct