Submission #511548

# Submission time Handle Problem Language Result Execution time Memory
511548 2022-01-16T01:54:14 Z Zhora_004 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
47 / 100
2051 ms 131444 KB
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#include <numeric>
#include <functional>
#include <chrono>
#include <cassert>
#include <bitset>
//#include <bit>
//#include <ranges>
//#include <numbers>
#define itn int
#define sacnf scanf
#define sz(a) ((int)((a).size()))
// printf("%.10f\n", ans);
using ll = long long;
using namespace std;
const ll mod = 1e9 + 7;
const int N = 1e6 + 5;

int fm(int& L, int& R, vector<int>& l, vector<vector<int>>& st)
{
    int j = l[R - L + 1];
    return min(st[L][j], st[R - (1 << j) + 1][j]);
}

int fmx(int& L, int& R, vector<int>& l, vector<vector<int>>& st)
{
    int j = l[R - L + 1];
    return max(st[L][j], st[R - (1 << j) + 1][j]);
}

int main()
{
    /*ios_base::sync_with_stdio(false);
    cin.tie(NULL);*/
    int n, m;
    scanf("%d%d", &n, &m);
    vector<int> v(n);
    bool flag = 1;
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &v[i]);
        if (v[i] > 1000) flag = 0;
    }
    if (n <= 5000 && m <= 5000)
    {
        for (int i = 0; i < m; i++)
        {
            int l, r, k;
            scanf("%d%d%d", &l, &r, &k);
            l--, r--;
            int mx_num = 0, mx = 0;
            for (int j = l; j <= r; j++)
            {
                if (mx_num > v[j]) mx = max(mx, v[j] + mx_num);
                mx_num = max(mx_num, v[j]);
            }
            if (mx <= k) printf("1\n");
            else printf("0\n");
        }
    }
    else if (flag)
    {
        // subtask 4
        vector<vector<int>> id(1001);
        for (int i = 0; i < n; i++) id[v[i]].push_back(i);
        vector<vector<int>> st(n + 2, vector<int>(22));
        for (int i = 0; i < n; i++) st[i][0] = v[i];
        for (int j = 1; j <= 21; j++)
            for (int i = 0; i + (1 << j) < n + 2; i++)
                st[i][j] = max(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
        vector<int> g(n + 2);
        g[1] = 0;
        for (int i = 2; i < n + 2; i++)
            g[i] = g[i / 2] + 1;
        while (m--)
        {
            int l, r, k;
            scanf("%d%d%d", &l, &r, &k);
            if (k >= 2000) printf("1\n");
            else
            {
                l--, r--;
                flag = 1;
                for (int num = 0; num <= 1000; num++)
                {
                    auto it = upper_bound(id[num].begin(), id[num].end(), r);
                    if (id[num].empty() || it == id[num].begin()) continue;
                    it--;
                    int index = *it;
                    index--;
                    if (index < l) continue;
                    int shan_txa = fmx(l, index, g, st);
                    if (shan_txa + num > k && shan_txa > num)
                    {
                        flag = 0;
                        break;
                    }
                }
                if (flag) printf("1\n");
                else printf("0\n");
            }
        }
    }
    else
    {
        // subtask 3
        stack<int> s;
        vector<int> ans(n);
        for (int i = 0; i < n; i++)
        {
            int next = v[i];
            if (s.empty()) 
            {
                s.push(i);
                continue;
            }
            while (!s.empty() && v[s.top()] > next) 
            {
                ans[s.top()] = i;
                s.pop();
            }
            s.push(i);
        }
        while (!s.empty()) 
        {
            ans[s.top()] = 2e9;
            s.pop();
        }
        vector<vector<int>> st(n + 2, vector<int>(22));
        for (int i = 0; i < n; i++) st[i][0] = ans[i];
        for (int j = 1; j <= 21; j++)
            for (int i = 0; i + (1 << j) < n + 2; i++)
                st[i][j] = min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
        vector<int> g(n + 2);
        g[1] = 0;
        for (int i = 2; i < n + 2; i++)
            g[i] = g[i / 2] + 1;
        while (m--)
        {
            int l, r, k;
            scanf("%d%d%d", &l, &r, &k);
            l--, r--;
            if (fm(l, r, g, st) <= r) printf("0\n");
            else printf("1\n");
        }
    }
    return 0;
}


// https://codeforces.com/problemset/problem/1136/D?locale=ru

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         scanf("%d", &v[i]);
      |         ~~~~~^~~~~~~~~~~~~
sortbooks.cpp:68:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |             scanf("%d%d%d", &l, &r, &k);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:97:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |             scanf("%d%d%d", &l, &r, &k);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:160:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  160 |             scanf("%d%d%d", &l, &r, &k);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 3 ms 204 KB Output is correct
12 Correct 6 ms 204 KB Output is correct
13 Correct 6 ms 204 KB Output is correct
14 Correct 13 ms 316 KB Output is correct
15 Correct 11 ms 308 KB Output is correct
16 Correct 18 ms 204 KB Output is correct
17 Correct 14 ms 316 KB Output is correct
18 Correct 18 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 998 ms 131332 KB Output is correct
2 Correct 1059 ms 131348 KB Output is correct
3 Correct 995 ms 131444 KB Output is correct
4 Correct 1008 ms 131428 KB Output is correct
5 Correct 991 ms 131424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1160 ms 13672 KB Output is correct
2 Correct 714 ms 13588 KB Output is correct
3 Correct 2051 ms 13752 KB Output is correct
4 Correct 1543 ms 13728 KB Output is correct
5 Correct 1587 ms 13624 KB Output is correct
6 Correct 1072 ms 13572 KB Output is correct
7 Correct 1180 ms 13608 KB Output is correct
8 Correct 111 ms 13692 KB Output is correct
9 Correct 69 ms 540 KB Output is correct
10 Correct 92 ms 13404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 3 ms 204 KB Output is correct
12 Correct 6 ms 204 KB Output is correct
13 Correct 6 ms 204 KB Output is correct
14 Correct 13 ms 316 KB Output is correct
15 Correct 11 ms 308 KB Output is correct
16 Correct 18 ms 204 KB Output is correct
17 Correct 14 ms 316 KB Output is correct
18 Correct 18 ms 312 KB Output is correct
19 Incorrect 180 ms 26496 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 3 ms 204 KB Output is correct
12 Correct 6 ms 204 KB Output is correct
13 Correct 6 ms 204 KB Output is correct
14 Correct 13 ms 316 KB Output is correct
15 Correct 11 ms 308 KB Output is correct
16 Correct 18 ms 204 KB Output is correct
17 Correct 14 ms 316 KB Output is correct
18 Correct 18 ms 312 KB Output is correct
19 Correct 998 ms 131332 KB Output is correct
20 Correct 1059 ms 131348 KB Output is correct
21 Correct 995 ms 131444 KB Output is correct
22 Correct 1008 ms 131428 KB Output is correct
23 Correct 991 ms 131424 KB Output is correct
24 Correct 1160 ms 13672 KB Output is correct
25 Correct 714 ms 13588 KB Output is correct
26 Correct 2051 ms 13752 KB Output is correct
27 Correct 1543 ms 13728 KB Output is correct
28 Correct 1587 ms 13624 KB Output is correct
29 Correct 1072 ms 13572 KB Output is correct
30 Correct 1180 ms 13608 KB Output is correct
31 Correct 111 ms 13692 KB Output is correct
32 Correct 69 ms 540 KB Output is correct
33 Correct 92 ms 13404 KB Output is correct
34 Incorrect 180 ms 26496 KB Output isn't correct
35 Halted 0 ms 0 KB -