Submission #779699

# Submission time Handle Problem Language Result Execution time Memory
779699 2023-07-11T16:58:41 Z chanhchuong123 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
1509 ms 107236 KB
#include <bits/stdc++.h>
using namespace std;
#define task ""
#define fi first
#define se second
#define MASK(i) (1LL << (i))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define BIT(mask, i) ((mask) >> (i) & 1)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (b), _a = (a); i >= _a; --i)

template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
	if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
	if (a < b) {a = b; return true;} return false;
}

const int dx[] = {-1, 0, 0, +1};
const int dy[] = {0, -1, +1, 0};

const int MAX = 1000100;
int n, m;
int w[MAX];
bool ans[MAX];
vector<int> tmp;
#define value(x) (tmp[w[x] - 1])

struct query { int l, k, id; };
vector<query> queries[MAX];

int bit[MAX];
void update(int id, int delta) {
    for (; id > 0; id -= id & -id)
        bit[id] = max(bit[id], delta);
}
int get(int id) {
    int res = 0;
    for (; id <= n; id += id & -id)
        res = max(res, bit[id]);
    return res;
}

int st[MAX << 2];
void update(int id, int l, int r, int pos, int delta) {
    if (l == r) st[id] = max(st[id], delta);
    else {
        int mid = l + r >> 1;
        if (pos <= mid) update(id << 1, l, mid, pos, delta);
        else update(id << 1 | 1, mid + 1, r, pos, delta);
        st[id] = max(st[id << 1], st[id << 1 | 1]);
    }
}
int get(int id, int l, int r, int u, int v) {
    if (l > v || r < u) return 0;
    if (l >= u && r <= v) return st[id];
    int mid = l + r >> 1; return max(get(id << 1, l, mid, u, v), get(id << 1 | 1, mid + 1, r, u, v));
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr);

	if (fopen(task".inp", "r")) {
		freopen(task".inp", "r", stdin);
		freopen(task".out", "w", stdout);
	}

    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        cin >> w[i];
        tmp.push_back(w[i]);
    }
    sort(all(tmp)); tmp.resize(unique(all(tmp)) - tmp.begin());
    for (int i = 1; i <= n; ++i) {
        w[i] = upper_bound(all(tmp), w[i]) - tmp.begin();
        cout << w[i] << ' ';
    }
    cout << '\n';
    for (int i = 1; i <= m; ++i) {
        int l, r, k; cin >> l >> r >> k;
        queries[r].push_back({l, k, i});
    }
    for (int i = 1; i <= n; ++i) {
        int id = get(w[i] + 1);
        if (id) update(1, 1, n, id, value(i) + value(id));
        for (query &x: queries[i]) {
            int l = x.l, k = x.k, id = x.id;
            int cc = get(1, 1, n, l, i);
            ans[id] = k >= cc;
        }
        update(w[i], i);
    }
    for (int i = 1; i <= m; ++i) {
        cout << ans[i] << '\n';
    }
	return 0;
}

Compilation message

sortbooks.cpp: In function 'void update(int, int, int, int, int)':
sortbooks.cpp:49:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |         int mid = l + r >> 1;
      |                   ~~^~~
sortbooks.cpp: In function 'int get(int, int, int, int, int)':
sortbooks.cpp:58:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   58 |     int mid = l + r >> 1; return max(get(id << 1, l, mid, u, v), get(id << 1 | 1, mid + 1, r, u, v));
      |               ~~^~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:65:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:66:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 23824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 23824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1509 ms 107236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 97 ms 30356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 23824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 23824 KB Output isn't correct
2 Halted 0 ms 0 KB -