Submission #1040310

#TimeUsernameProblemLanguageResultExecution timeMemory
1040310vjudge1Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
8 / 100
3044 ms22988 KiB
#include <bits/stdc++.h>
using namespace std;

int a[1000005];

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> a[i];

    for (int i = 1; i <= m; i++) {
        bool res = true;
        int l, r, w;
        cin >> l >> r >> w;

        vector<int> b(r - l + 1);
        for (int j = 0; j < r - l + 1; j++) {
            b[j] = a[l + j];
        }

        vector<int> c = b;
        sort(c.begin(), c.end());

        int temp = r - l + 1;
        for (int j = 0; j < temp & res; j++) {
            if (b[j] == c[j])
                continue;
            else {
                bool tempp = false;
                for (int k = j + 1; k < temp && res; k++) {
                    if (b[k] == c[j]) {
                        tempp = true;
                        for (int p = k; p > j; p--) {
                            if (b[p] + b[p - 1] <= w)
                                swap(b[p], b[p - 1]);
                            else {
                                res = false;
                                break;
                            }
                        }
                        break;
                    }
                }
                if (!tempp) {
                    res = false;
                    break;
                }
            }
        }

        if (res) cout << 1 << '\n';
        else cout << 0 << '\n';
    }
    return 0;
}

Compilation message (stderr)

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:26:27: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   26 |         for (int j = 0; j < temp & res; j++) {
      |                         ~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...